diff --git a/moonscript/compile/line.lua b/moonscript/compile/line.lua index 77ecc1a..9759e7f 100644 --- a/moonscript/compile/line.lua +++ b/moonscript/compile/line.lua @@ -117,7 +117,7 @@ line_compile = { end, update = function(self, node) local _, name, op, exp = unpack(node) - local op_final = op:match("(.)=") + local op_final = op:match("^(.+)=$") if not op_final then error("Unknown op: " .. op) end diff --git a/moonscript/compile/line.moon b/moonscript/compile/line.moon index 6ab61e9..f2c819b 100644 --- a/moonscript/compile/line.moon +++ b/moonscript/compile/line.moon @@ -66,7 +66,7 @@ line_compile = update: (node) => _, name, op, exp = unpack node - op_final = op\match "(.)=" + op_final = op\match "^(.+)=$" error "Unknown op: "..op if not op_final @stm {"assign", {name}, {{"exp", name, op_final, exp}}} diff --git a/moonscript/parse.lua b/moonscript/parse.lua index 50c0246..8631715 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -305,7 +305,7 @@ local build_grammar = wrap(function() CompClause = CompFor + key"when" * Exp / mark"when", Assign = Ct(AssignableList) * sym"=" * (With + If + Ct(TableBlock + ExpListLow)) / mark"assign", - Update = Assignable * ((sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=")/trim) * Exp / mark"update", + Update = Assignable * ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=")/trim) * Exp / mark"update", -- we can ignore precedence for now OtherOps = op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<" + op">", diff --git a/tests/inputs/syntax.moon b/tests/inputs/syntax.moon index 2151702..af3359d 100644 --- a/tests/inputs/syntax.moon +++ b/tests/inputs/syntax.moon @@ -138,7 +138,7 @@ j -= "hello" y *= 2 y /= 100 m %= 2 - +hello ..= "world" x = 0 (if ntype(v) == "fndef" then x += 1) for v in *values diff --git a/tests/outputs/syntax.lua b/tests/outputs/syntax.lua index 9d49f37..e43519b 100644 --- a/tests/outputs/syntax.lua +++ b/tests/outputs/syntax.lua @@ -142,6 +142,7 @@ local j = j - "hello" y = y * 2 y = y / 100 local m = m % 2 +local hello = hello .. "world" x = 0 do local _item_0 = values @@ -155,7 +156,7 @@ do end)()) end end -local hello = { +hello = { something = world, ["if"] = "hello", ["else"] = 3434,