From 17184f2aa843895e8c873d19628eed94740331c3 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Mon, 20 Jun 2011 08:28:25 -0700 Subject: [PATCH] unary minus must not have any whitespace after it avoids precedence ambiguity between minus with fncall --- moonscript/parse.lua | 12 ++---------- tests/inputs/syntax.moon | 9 +++++++++ tests/outputs/syntax.lua | 7 ++++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/moonscript/parse.lua b/moonscript/parse.lua index 1a515ac..b6f7d7c 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -35,6 +35,7 @@ local Indent = C(S"\t "^0) / count_indent local Comment = P"--" * (1 - S"\n")^0 * #Stop local Space = _Space * Comment^-1 +local SomeSpace = S" \t"^1 * Comment^-1 local _Name = C(R("az", "AZ", "__") * R("az", "AZ", "09", "__")^0) local Name = Space * _Name @@ -279,7 +280,7 @@ local build_grammar = wrap(function() Value = If + - sym"-" * Exp / mark"minus" + + sym"-" * -SomeSpace * Exp / mark"minus" + sym"#" * Exp / mark"length" + sym"not" * Exp / mark"not" + TableLit + @@ -407,12 +408,3 @@ function string(str) return g:match(str) end -local program3 = [[ --- hello -class Hello - @something: 2323 - - hello: () -> - print 200 -]] - diff --git a/tests/inputs/syntax.moon b/tests/inputs/syntax.moon index 90f9e34..d99cfc0 100644 --- a/tests/inputs/syntax.moon +++ b/tests/inputs/syntax.moon @@ -159,3 +159,12 @@ hello = good: 230203 +5 + what wack +what whack + 5 + +5 - what wack +what whack - 5 + +x = hello - world - something + + diff --git a/tests/outputs/syntax.lua b/tests/outputs/syntax.lua index a92df46..23e472d 100644 --- a/tests/outputs/syntax.lua +++ b/tests/outputs/syntax.lua @@ -118,4 +118,9 @@ local hello = { ["else"] = 3434, ["function"] = "okay", good = 230203 -} \ No newline at end of file +} +_ = 5 + what(wack) +what(whack + 5) +_ = 5 - what(wack) +what(whack - 5) +x = hello - world - something \ No newline at end of file