Skip to content
Closed
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
2 changes: 1 addition & 1 deletion moonscript/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ local build_grammar = wrap_env(debug_grammar, function(root)
WithExp = Ct(ExpList) * Assign ^ -1 / format_assign,
With = key("with") * DisableDo * ensure(WithExp, PopDo) * key("do") ^ -1 * Body / mark("with"),
Switch = key("switch") * DisableDo * ensure(Exp, PopDo) * key("do") ^ -1 * Space ^ -1 * Break * SwitchBlock / mark("switch"),
SwitchBlock = EmptyLine ^ 0 * Advance * Ct(SwitchCase * (Break ^ 1 * SwitchCase) ^ 0 * (Break ^ 1 * SwitchElse) ^ -1) * PopIndent,
SwitchBlock = EmptyLine ^ 0 * Advance * Ct(SwitchCase * (SpaceBreak ^ 1 * SwitchCase) ^ 0 * (SpaceBreak ^ 1 * SwitchElse) ^ -1) * PopIndent,
SwitchCase = key("when") * Ct(ExpList) * key("then") ^ -1 * Body / mark("case"),
SwitchElse = key("else") * Body / mark("else"),
IfCond = Exp * Assign ^ -1 / format_single_assign,
Expand Down
2 changes: 1 addition & 1 deletion moonscript/parse.moon
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ build_grammar = wrap_env debug_grammar, (root) ->

Switch: key"switch" * DisableDo * ensure(Exp, PopDo) * key"do"^-1 * Space^-1 * Break * SwitchBlock / mark"switch"

SwitchBlock: EmptyLine^0 * Advance * Ct(SwitchCase * (Break^1 * SwitchCase)^0 * (Break^1 * SwitchElse)^-1) * PopIndent
SwitchBlock: EmptyLine^0 * Advance * Ct(SwitchCase * (SpaceBreak^1 * SwitchCase)^0 * (SpaceBreak ^1 * SwitchElse)^-1) * PopIndent
SwitchCase: key"when" * Ct(ExpList) * key"then"^-1 * Body / mark"case"
SwitchElse: key"else" * Body / mark"else"

Expand Down
3 changes: 2 additions & 1 deletion moonscript/parse/literals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ local plain_space = S(" \t") ^ 0
local Break = P("\r") ^ -1 * P("\n")
local Stop = Break + -1
local Comment = P("--") * (1 - S("\r\n")) ^ 0 * L(Stop)
local Space = plain_space * Comment ^ -1
local escape_newline = P("\\") * plain_space * Comment ^ -1 * Break
local Space = (S(" \t") + escape_newline) ^ 0 * Comment ^ -1
local SomeSpace = S(" \t") ^ 1 * Comment ^ -1
local SpaceBreak = Space * Break
local EmptyLine = SpaceBreak
Expand Down
4 changes: 3 additions & 1 deletion moonscript/parse/literals.moon
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Break = P"\r"^-1 * P"\n"
Stop = Break + -1

Comment = P"--" * (1 - S"\r\n")^0 * L(Stop)
Space = plain_space * Comment^-1
escape_newline = P"\\" * plain_space * Comment^-1 * Break
Space = (S" \t" + escape_newline)^0 * Comment^-1
SomeSpace = S" \t"^1 * Comment^-1

SpaceBreak = Space * Break
Expand All @@ -36,3 +37,4 @@ safe_module "moonscript.parse.literals", {
:White, :Break, :Stop, :Comment, :Space, :SomeSpace, :SpaceBreak, :EmptyLine,
:AlphaNum, :Name, :Num, :Shebang
}

2 changes: 1 addition & 1 deletion moonscript/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pos_to_line = function(str, pos)
end
local trim
trim = function(str)
return str:match("^%s*(.-)%s*$")
return str:match("^[%s\\]*(.-)%s*$")
end
local get_line
get_line = function(str, line_num)
Expand Down
2 changes: 1 addition & 1 deletion moonscript/util.moon
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pos_to_line = (str, pos) ->
line

trim = (str) ->
str\match "^%s*(.-)%s*$"
str\match "^[%s\\]*(.-)%s*$"

get_line = (str, line_num) ->
-- todo: this returns an extra blank line at the end
Expand Down
13 changes: 13 additions & 0 deletions spec/inputs/syntax.moon
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,16 @@ z = a- b


-- cooool

str = strA \ -- comment 1
.. strB \ -- comment 2
.. strC

->
a,b, \
c,d, \
e,f

with obj
print \
\func!
11 changes: 10 additions & 1 deletion spec/outputs/syntax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,13 @@ x = x and "hello"
z = a - b
z = a(-b)
z = a - b
z = a - b
z = a - b
local str = strA .. strB .. strC
_ = function()
return a, b, c, d, e, f
end
do
local _with_0 = obj
print(_with_0:func())
return _with_0
end