mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
allow whitespace/newlines after binary operator
This commit is contained in:
parent
72615aa6e2
commit
8ea934964a
@ -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 +
|
||||||
|
33
spec/inputs/operators.moon
Normal file
33
spec/inputs/operators.moon
Normal 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
|
13
spec/outputs/operators.lua
Normal file
13
spec/outputs/operators.lua
Normal 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
|
Loading…
Reference in New Issue
Block a user