From 8bfb18431af82bba7f659bac6d6f73e2bf3ab413 Mon Sep 17 00:00:00 2001 From: Yorwba Date: Sat, 1 Feb 2014 22:27:48 +0100 Subject: [PATCH 1/3] Fixed lua/moon line mapping --- moonscript/compile.lua | 3 +++ moonscript/compile.moon | 1 + 2 files changed, 4 insertions(+) diff --git a/moonscript/compile.lua b/moonscript/compile.lua index 368eead7..29a075e0 100644 --- a/moonscript/compile.lua +++ b/moonscript/compile.lua @@ -61,6 +61,9 @@ do local _exp_0 = mtype(l) if "string" == _exp_0 or DelayedLine == _exp_0 then line_no = line_no + 1 + for _ in l:gmatch("\n") do + line_no = line_no + 1 + end out[line_no] = posmap[i] elseif Lines == _exp_0 then local _ diff --git a/moonscript/compile.moon b/moonscript/compile.moon index 27ab017c..f386c334 100644 --- a/moonscript/compile.moon +++ b/moonscript/compile.moon @@ -44,6 +44,7 @@ class Lines switch mtype l when "string", DelayedLine line_no += 1 + line_no += 1 for _ in l\gmatch"\n" out[line_no] = posmap[i] when Lines _, line_no = l\flatten_posmap line_no, out From 26fafb76bdd591f25a27f9c70dcd3d022f23d462 Mon Sep 17 00:00:00 2001 From: Yorwba Date: Mon, 3 Feb 2014 15:29:33 +0100 Subject: [PATCH 2/3] allow multi line comments --- moonscript/parse.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/moonscript/parse.lua b/moonscript/parse.lua index eb4bffc4..ea268a88 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -39,7 +39,7 @@ local Break = P"\r"^-1 * P"\n" local Stop = Break + -1 local Indent = C(S"\t "^0) / count_indent -local Comment = P"--" * (1 - S"\r\n")^0 * #Stop +local Comment = V"Comment" local Space = _Space * Comment^-1 local SomeSpace = S" \t"^1 * Comment^-1 @@ -392,6 +392,8 @@ local build_grammar = wrap_env(function() CheckIndent = Cmt(Indent, check_indent), -- validates line is in correct indent Line = (CheckIndent * Statement + Space * #Stop), + Comment = P"--" * (V"NoSpaceLuaString" / 0 * Space^-1 + (1 - S"\r\n")^0 * #Stop), + Statement = pos( Import + While + With + For + ForEach + Switch + Return + Local + Export + BreakLoop + @@ -505,11 +507,12 @@ local build_grammar = wrap_env(function() SingleString = simple_string("'"), DoubleString = simple_string('"', true), - LuaString = Cg(LuaStringOpen, "string_open") * Cb"string_open" * Break^-1 * + LuaString = Space * NoSpaceLuaString, + NoSpaceLuaString = Cg(LuaStringOpen, "string_open") * Cb"string_open" * Break^-1 * C((1 - Cmt(C(LuaStringClose) * Cb"string_open", check_lua_string))^0) * LuaStringClose / mark"string", - LuaStringOpen = sym"[" * P"="^0 * "[" / trim, + LuaStringOpen = "[" * P"="^0 * "[" / trim, LuaStringClose = "]" * P"="^0 * "]", Callable = pos(Name / mark"ref") + SelfName + VarArg + Parens / mark"parens", From 76f3cec605595699d2f194a914aa0070268b1ffe Mon Sep 17 00:00:00 2001 From: Yorwba Date: Wed, 5 Feb 2014 18:04:14 +0100 Subject: [PATCH 3/3] changed the method used for dropping captures in multiline comments --- moonscript/parse.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moonscript/parse.lua b/moonscript/parse.lua index ea268a88..276de4f8 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -392,7 +392,7 @@ local build_grammar = wrap_env(function() CheckIndent = Cmt(Indent, check_indent), -- validates line is in correct indent Line = (CheckIndent * Statement + Space * #Stop), - Comment = P"--" * (V"NoSpaceLuaString" / 0 * Space^-1 + (1 - S"\r\n")^0 * #Stop), + Comment = P"--" * (Cmt(NoSpaceLuaString, function() return true end) * Space^-1 + (1 - S"\r\n")^0 * #Stop), Statement = pos( Import + While + With + For + ForEach + Switch + Return +