Skip to content

Commit 5d074c9

Browse files
committed
allow whitespace around function argument declaration, fixes #227
1 parent 2e7d515 commit 5d074c9

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

moonscript/parse.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ local build_grammar = wrap_env(debug_grammar, function(root)
187187
KeyValue = (sym(":") * -SomeSpace * Name * lpeg.Cp()) / self_assign + Ct((KeyName + sym("[") * Exp * sym("]") + Space * DoubleString + Space * SingleString) * symx(":") * (Exp + TableBlock + SpaceBreak ^ 1 * Exp)),
188188
KeyValueList = KeyValue * (sym(",") * KeyValue) ^ 0,
189189
KeyValueLine = CheckIndent * KeyValueList * sym(",") ^ -1,
190-
FnArgsDef = sym("(") * Ct(FnArgDefList ^ -1) * (key("using") * Ct(NameList + Space * "nil") + Ct("")) * sym(")") + Ct("") * Ct(""),
191-
FnArgDefList = FnArgDef * (sym(",") * FnArgDef) ^ 0 * (sym(",") * Ct(VarArg)) ^ 0 + Ct(VarArg),
190+
FnArgsDef = sym("(") * White * Ct(FnArgDefList ^ -1) * (key("using") * Ct(NameList + Space * "nil") + Ct("")) * White * sym(")") + Ct("") * Ct(""),
191+
FnArgDefList = FnArgDef * (sym(",") * White * FnArgDef) ^ 0 * (sym(",") * White * Ct(VarArg)) ^ 0 + Ct(VarArg),
192192
FnArgDef = Ct((Name + SelfName) * (sym("=") * Exp) ^ -1),
193193
FunLit = FnArgsDef * (sym("->") * Cc("slim") + sym("=>") * Cc("fat")) * (Body + Ct("")) / mark("fndef"),
194194
NameList = Name * (sym(",") * Name) ^ 0,

moonscript/parse.moon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ build_grammar = wrap_env debug_grammar, (root) ->
292292
KeyValueList: KeyValue * (sym"," * KeyValue)^0
293293
KeyValueLine: CheckIndent * KeyValueList * sym","^-1
294294

295-
FnArgsDef: sym"(" * Ct(FnArgDefList^-1) *
295+
FnArgsDef: sym"(" * White * Ct(FnArgDefList^-1) *
296296
(key"using" * Ct(NameList + Space * "nil") + Ct"") *
297-
sym")" + Ct"" * Ct""
297+
White * sym")" + Ct"" * Ct""
298298

299-
FnArgDefList: FnArgDef * (sym"," * FnArgDef)^0 * (sym"," * Ct(VarArg))^0 + Ct(VarArg)
299+
FnArgDefList: FnArgDef * (sym"," * White * FnArgDef)^0 * (sym"," * White * Ct(VarArg))^0 + Ct(VarArg)
300300
FnArgDef: Ct((Name + SelfName) * (sym"=" * Exp)^-1)
301301

302302
FunLit: FnArgsDef *

spec/inputs/funcs.moon

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,26 @@ f(
9595

9696
--
9797

98+
x = (a,
99+
b) ->
100+
print "what"
101+
102+
103+
y = (a="hi",
104+
b=23) ->
105+
print "what"
106+
107+
z = (
108+
a="hi",
109+
b=23) ->
110+
print "what"
111+
112+
113+
j = (f,g,m,
114+
a="hi",
115+
b=23
116+
) ->
117+
print "what"
118+
98119

99120
nil

spec/outputs/funcs.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,37 @@ end)(), 10, 20)
125125
f()()(what)(function()
126126
return print("srue")
127127
end, 123)
128+
x = function(a, b)
129+
return print("what")
130+
end
131+
local y
132+
y = function(a, b)
133+
if a == nil then
134+
a = "hi"
135+
end
136+
if b == nil then
137+
b = 23
138+
end
139+
return print("what")
140+
end
141+
local z
142+
z = function(a, b)
143+
if a == nil then
144+
a = "hi"
145+
end
146+
if b == nil then
147+
b = 23
148+
end
149+
return print("what")
150+
end
151+
local j
152+
j = function(f, g, m, a, b)
153+
if a == nil then
154+
a = "hi"
155+
end
156+
if b == nil then
157+
b = 23
158+
end
159+
return print("what")
160+
end
128161
return nil

0 commit comments

Comments
 (0)