allow whitespace around function argument declaration, fixes #227

This commit is contained in:
leaf corcoran 2016-09-25 17:45:50 -07:00
parent 2e7d5153f1
commit 5d074c9e62
4 changed files with 59 additions and 5 deletions

View File

@ -187,8 +187,8 @@ local build_grammar = wrap_env(debug_grammar, function(root)
KeyValue = (sym(":") * -SomeSpace * Name * lpeg.Cp()) / self_assign + Ct((KeyName + sym("[") * Exp * sym("]") + Space * DoubleString + Space * SingleString) * symx(":") * (Exp + TableBlock + SpaceBreak ^ 1 * Exp)), KeyValue = (sym(":") * -SomeSpace * Name * lpeg.Cp()) / self_assign + Ct((KeyName + sym("[") * Exp * sym("]") + Space * DoubleString + Space * SingleString) * symx(":") * (Exp + TableBlock + SpaceBreak ^ 1 * Exp)),
KeyValueList = KeyValue * (sym(",") * KeyValue) ^ 0, KeyValueList = KeyValue * (sym(",") * KeyValue) ^ 0,
KeyValueLine = CheckIndent * KeyValueList * sym(",") ^ -1, KeyValueLine = CheckIndent * KeyValueList * sym(",") ^ -1,
FnArgsDef = sym("(") * Ct(FnArgDefList ^ -1) * (key("using") * Ct(NameList + Space * "nil") + Ct("")) * sym(")") + Ct("") * Ct(""), FnArgsDef = sym("(") * White * Ct(FnArgDefList ^ -1) * (key("using") * Ct(NameList + Space * "nil") + Ct("")) * White * sym(")") + Ct("") * Ct(""),
FnArgDefList = FnArgDef * (sym(",") * FnArgDef) ^ 0 * (sym(",") * Ct(VarArg)) ^ 0 + Ct(VarArg), FnArgDefList = FnArgDef * (sym(",") * White * FnArgDef) ^ 0 * (sym(",") * White * Ct(VarArg)) ^ 0 + Ct(VarArg),
FnArgDef = Ct((Name + SelfName) * (sym("=") * Exp) ^ -1), FnArgDef = Ct((Name + SelfName) * (sym("=") * Exp) ^ -1),
FunLit = FnArgsDef * (sym("->") * Cc("slim") + sym("=>") * Cc("fat")) * (Body + Ct("")) / mark("fndef"), FunLit = FnArgsDef * (sym("->") * Cc("slim") + sym("=>") * Cc("fat")) * (Body + Ct("")) / mark("fndef"),
NameList = Name * (sym(",") * Name) ^ 0, NameList = Name * (sym(",") * Name) ^ 0,

View File

@ -292,11 +292,11 @@ build_grammar = wrap_env debug_grammar, (root) ->
KeyValueList: KeyValue * (sym"," * KeyValue)^0 KeyValueList: KeyValue * (sym"," * KeyValue)^0
KeyValueLine: CheckIndent * KeyValueList * sym","^-1 KeyValueLine: CheckIndent * KeyValueList * sym","^-1
FnArgsDef: sym"(" * Ct(FnArgDefList^-1) * FnArgsDef: sym"(" * White * Ct(FnArgDefList^-1) *
(key"using" * Ct(NameList + Space * "nil") + Ct"") * (key"using" * Ct(NameList + Space * "nil") + Ct"") *
sym")" + Ct"" * Ct"" White * sym")" + Ct"" * Ct""
FnArgDefList: FnArgDef * (sym"," * FnArgDef)^0 * (sym"," * Ct(VarArg))^0 + Ct(VarArg) FnArgDefList: FnArgDef * (sym"," * White * FnArgDef)^0 * (sym"," * White * Ct(VarArg))^0 + Ct(VarArg)
FnArgDef: Ct((Name + SelfName) * (sym"=" * Exp)^-1) FnArgDef: Ct((Name + SelfName) * (sym"=" * Exp)^-1)
FunLit: FnArgsDef * FunLit: FnArgsDef *

View File

@ -95,5 +95,26 @@ f(
-- --
x = (a,
b) ->
print "what"
y = (a="hi",
b=23) ->
print "what"
z = (
a="hi",
b=23) ->
print "what"
j = (f,g,m,
a="hi",
b=23
) ->
print "what"
nil nil

View File

@ -125,4 +125,37 @@ end)(), 10, 20)
f()()(what)(function() f()()(what)(function()
return print("srue") return print("srue")
end, 123) end, 123)
x = function(a, b)
return print("what")
end
local y
y = function(a, b)
if a == nil then
a = "hi"
end
if b == nil then
b = 23
end
return print("what")
end
local z
z = function(a, b)
if a == nil then
a = "hi"
end
if b == nil then
b = 23
end
return print("what")
end
local j
j = function(f, g, m, a, b)
if a == nil then
a = "hi"
end
if b == nil then
b = 23
end
return print("what")
end
return nil return nil