allow whitespace/newlines after binary operator

This commit is contained in:
leaf corcoran 2015-02-28 13:26:29 -08:00
parent 72615aa6e2
commit 8ea934964a
3 changed files with 49 additions and 7 deletions

View File

@ -436,16 +436,12 @@ local build_grammar = wrap_env(function()
Assign = sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign", Assign = sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign",
Update = ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=") / trim) * Exp / mark"update", Update = ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=") / trim) * Exp / mark"update",
-- we can ignore precedence for now -- we don't need to parse precedence, lua will handle it for us
OtherOps = op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<" + op">", OtherOps = op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<" + op">",
BinaryOperator = (OtherOps + FactorOp + TermOp) * SpaceBreak^0,
Assignable = Cmt(DotChain + Chain, check_assignable) + Name + SelfName, Assignable = Cmt(DotChain + Chain, check_assignable) + Name + SelfName,
Exp = Ct(Value * (BinaryOperator * Value)^0) / flatten_or_mark"exp",
Exp = Ct(Value * ((OtherOps + FactorOp + TermOp) * Value)^0) / flatten_or_mark"exp",
-- Exp = Ct(Factor * (OtherOps * Factor)^0) / flatten_or_mark"exp",
-- Factor = Ct(Term * (FactorOp * Term)^0) / flatten_or_mark"exp",
-- Term = Ct(Value * (TermOp * Value)^0) / flatten_or_mark"exp",
SimpleValue = SimpleValue =
If + Unless + If + Unless +

View File

@ -0,0 +1,33 @@
--
x = 1 + 3
y = 1 +
3
z = 1 +
3 +
4
--
k = b and c and
g
h = thing and
->
print "hello world"
-- TODO: should fail, indent still set to previous line so it thinks body is
-- indented
i = thing or
->
print "hello world"
p = thing and
->
print "hello world"
s = thing or
-> and 234

View File

@ -0,0 +1,13 @@
local x = 1 + 3
local y = 1 + 3
local z = 1 + 3 + 4
local k = b and c and g
local h = thing and function()
return print("hello world")
end
local i = thing or function()
return print("hello world")
end
local p = thing and function() end
print("hello world")
local s = thing or function() end and 234