Skip to content

Commit e698e18

Browse files
committed
newlines can be used to separte function argument declarations
1 parent a5abd2f commit e698e18

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

moonscript/parse.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ local build_grammar = wrap_env(debug_grammar, function(root)
188188
KeyValueList = KeyValue * (sym(",") * KeyValue) ^ 0,
189189
KeyValueLine = CheckIndent * KeyValueList * sym(",") ^ -1,
190190
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),
191+
FnArgDefList = FnArgDef * ((sym(",") + Break) * White * FnArgDef) ^ 0 * ((sym(",") + Break) * 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ build_grammar = wrap_env debug_grammar, (root) ->
296296
(key"using" * Ct(NameList + Space * "nil") + Ct"") *
297297
White * sym")" + Ct"" * Ct""
298298

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

302302
FunLit: FnArgsDef *

spec/inputs/funcs.moon

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ y = (a="hi",
129129
) ->
130130
print "what"
131131

132+
--
133+
134+
args = (a
135+
b) ->
136+
print "what"
137+
138+
139+
args = (a="hi"
140+
b=23) ->
141+
print "what"
142+
143+
args = (
144+
a="hi"
145+
b=23) ->
146+
print "what"
147+
148+
149+
args = (f,g,m
150+
a="hi"
151+
b=23
152+
) ->
153+
print "what"
132154

133155

134156

spec/outputs/funcs.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,35 @@ y = function(a, b, ...)
176176
end
177177
return print("what")
178178
end
179+
local args
180+
args = function(a, b)
181+
return print("what")
182+
end
183+
args = function(a, b)
184+
if a == nil then
185+
a = "hi"
186+
end
187+
if b == nil then
188+
b = 23
189+
end
190+
return print("what")
191+
end
192+
args = function(a, b)
193+
if a == nil then
194+
a = "hi"
195+
end
196+
if b == nil then
197+
b = 23
198+
end
199+
return print("what")
200+
end
201+
args = function(f, g, m, a, b)
202+
if a == nil then
203+
a = "hi"
204+
end
205+
if b == nil then
206+
b = 23
207+
end
208+
return print("what")
209+
end
179210
return nil

0 commit comments

Comments
 (0)