Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-line comment support #128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions moonscript/compile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down
1 change: 1 addition & 0 deletions moonscript/compile.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions moonscript/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"--" * (Cmt(NoSpaceLuaString, function() return true end) * Space^-1 + (1 - S"\r\n")^0 * #Stop),

Statement = pos(
Import + While + With + For + ForEach + Switch + Return +
Local + Export + BreakLoop +
Expand Down Expand Up @@ -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",
Expand Down