Skip to content

Commit d8830b1

Browse files
committed
allow whitespace around function arguments when in parens, fixes #274
1 parent e0da63c commit d8830b1

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

moonscript/parse.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ local build_grammar = wrap_env(debug_grammar, function(root)
164164
LuaStringClose = "]" * P("=") ^ 0 * "]",
165165
Callable = pos(Name / mark("ref")) + SelfName + VarArg + Parens / mark("parens"),
166166
Parens = sym("(") * SpaceBreak ^ 0 * Exp * SpaceBreak ^ 0 * sym(")"),
167-
FnArgs = symx("(") * SpaceBreak ^ 0 * Ct(ExpList ^ -1) * SpaceBreak ^ 0 * sym(")") + sym("!") * -P("=") * Ct(""),
167+
FnArgs = symx("(") * SpaceBreak ^ 0 * Ct(FnArgsExpList ^ -1) * SpaceBreak ^ 0 * sym(")") + sym("!") * -P("=") * Ct(""),
168+
FnArgsExpList = Exp * (sym(",") * White * Exp) ^ 0,
168169
Chain = (Callable + String + -S(".\\")) * ChainItems / mark("chain") + Space * (DotChainItem * ChainItems ^ -1 + ColonChain) / mark("chain"),
169170
ChainItems = ChainItem ^ 1 * ColonChain ^ -1 + ColonChain,
170171
ChainItem = Invoke + DotChainItem + Slice + symx("[") * Exp / mark("index") * sym("]"),

moonscript/parse.moon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ build_grammar = wrap_env debug_grammar, (root) ->
227227
Callable: pos(Name / mark"ref") + SelfName + VarArg + Parens / mark"parens"
228228
Parens: sym"(" * SpaceBreak^0 * Exp * SpaceBreak^0 * sym")"
229229

230-
FnArgs: symx"(" * SpaceBreak^0 * Ct(ExpList^-1) * SpaceBreak^0 * sym")" + sym"!" * -P"=" * Ct""
230+
FnArgs: symx"(" * SpaceBreak^0 * Ct(FnArgsExpList^-1) * SpaceBreak^0 * sym")" + sym"!" * -P"=" * Ct""
231+
FnArgsExpList: Exp * (sym"," * White * Exp)^0
231232

232233
Chain: (Callable + String + -S".\\") * ChainItems / mark"chain" +
233234
Space * (DotChainItem * ChainItems^-1 + ColonChain) / mark"chain"

spec/inputs/whitespace.moon

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,22 @@ if hello 1,2,3,
8181
print "hello"
8282

8383

84+
--
85+
86+
a(
87+
one, two, three
88+
)
89+
90+
b(
91+
one,
92+
two,
93+
three
94+
)
95+
96+
97+
c(one, two,
98+
three, four)
99+
100+
--
101+
102+
nil

spec/outputs/whitespace.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,9 @@ if hello(1, 2, 3, world, world) then
7272
print("hello")
7373
end
7474
if hello(1, 2, 3, world, world) then
75-
return print("hello")
76-
end
75+
print("hello")
76+
end
77+
a(one, two, three)
78+
b(one, two, three)
79+
c(one, two, three, four)
80+
return nil

0 commit comments

Comments
 (0)