From 2e7d5153f193ca19e7de9941ae09a1ad7bf00962 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sun, 25 Sep 2016 17:34:59 -0700 Subject: [PATCH] expression can be used inside slide boundaries, fixes #233 --- moonscript/parse.lua | 2 +- moonscript/parse.moon | 2 +- spec/inputs/comprehension.moon | 6 ++++++ spec/outputs/comprehension.lua | 10 ++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/moonscript/parse.lua b/moonscript/parse.lua index 3b9b832..0ed7e4e 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -155,7 +155,7 @@ local build_grammar = wrap_env(debug_grammar, function(root) SimpleValue = If + Unless + Switch + With + ClassDecl + ForEach + For + While + Cmt(Do, check_do) + sym("-") * -SomeSpace * Exp / mark("minus") + sym("#") * Exp / mark("length") + sym("~") * Exp / mark("bitnot") + key("not") * Exp / mark("not") + TblComprehension + TableLit + Comprehension + FunLit + Num, ChainValue = (Chain + Callable) * Ct(InvokeArgs ^ -1) / join_chain, Value = pos(SimpleValue + Ct(KeyValueList) / mark("table") + ChainValue + String), - SliceValue = SimpleValue + ChainValue, + SliceValue = Exp, String = Space * DoubleString + Space * SingleString + LuaString, SingleString = simple_string("'"), DoubleString = simple_string('"', true), diff --git a/moonscript/parse.moon b/moonscript/parse.moon index 5ffc1f0..0403f33 100644 --- a/moonscript/parse.moon +++ b/moonscript/parse.moon @@ -211,7 +211,7 @@ build_grammar = wrap_env debug_grammar, (root) -> ChainValue + String) - SliceValue: SimpleValue + ChainValue + SliceValue: Exp String: Space * DoubleString + Space * SingleString + LuaString SingleString: simple_string("'") diff --git a/spec/inputs/comprehension.moon b/spec/inputs/comprehension.moon index 51b3985..1609d79 100644 --- a/spec/inputs/comprehension.moon +++ b/spec/inputs/comprehension.moon @@ -42,5 +42,11 @@ hi = {hello,world for {:hello, :world} in *things} ok(a,b,c) for {a,b,c} in things +-- + +[item for item in *items[1 + 2,3+4]] +[item for item in *items[hello! * 4, 2 - thing[4]]] + + nil diff --git a/spec/outputs/comprehension.lua b/spec/outputs/comprehension.lua index c53290e..15a9389 100644 --- a/spec/outputs/comprehension.lua +++ b/spec/outputs/comprehension.lua @@ -247,4 +247,14 @@ for _des_0 in things do a, b, c = _des_0[1], _des_0[2], _des_0[3] ok(a, b, c) end +local _max_0 = 3 + 4 +for _index_0 = 1 + 2, _max_0 < 0 and #items + _max_0 or _max_0 do + local item = items[_index_0] + _ = item +end +local _max_1 = 2 - thing[4] +for _index_0 = hello() * 4, _max_1 < 0 and #items + _max_1 or _max_1 do + local item = items[_index_0] + _ = item +end return nil \ No newline at end of file