mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
added support for colon open function calls
This commit is contained in:
parent
72eca8071c
commit
5e99633efc
@ -148,7 +148,15 @@ local build_grammar = wrap(function()
|
||||
|
||||
args = {"call", args}
|
||||
if ntype(callee) == "chain" then
|
||||
table.insert(callee, args)
|
||||
-- check for colon stub that needs arguments
|
||||
if ntype(callee[#callee]) == "colon_stub" then
|
||||
local stub = callee[#callee]
|
||||
stub[1] = "colon"
|
||||
table.insert(stub, args)
|
||||
else
|
||||
table.insert(callee, args)
|
||||
end
|
||||
|
||||
return callee
|
||||
end
|
||||
|
||||
@ -269,10 +277,11 @@ local build_grammar = wrap(function()
|
||||
sym"not" * Exp / mark"not" +
|
||||
TableLit +
|
||||
Comprehension +
|
||||
ColonChain +
|
||||
ColonChain * Ct(ExpList^0) / flatten_func + -- have precedence over open table
|
||||
Ct(KeyValueList) / mark"table" +
|
||||
Assign + FunLit + String +
|
||||
(Chain + Callable) * Ct(ExpList^0) / flatten_func + Num,
|
||||
((Chain + Callable) * Ct(ExpList^0)) / flatten_func +
|
||||
Num,
|
||||
|
||||
|
||||
String = Space * DoubleString + Space * SingleString + LuaString,
|
||||
@ -293,10 +302,10 @@ local build_grammar = wrap(function()
|
||||
|
||||
-- chain that starts with colon expression (for precedence over table literal)
|
||||
ColonChain =
|
||||
Callable * ColonCall * (ChainItem)^0 / mark"chain",
|
||||
Callable * (ColonCall * (ChainItem)^0 + ColonSuffix) / mark"chain",
|
||||
|
||||
-- a list of funcalls and indexs on a callable
|
||||
Chain = Callable * ChainItem^1 / mark"chain",
|
||||
Chain = Callable * (ChainItem^1 * ColonSuffix^-1 + ColonSuffix) / mark"chain",
|
||||
|
||||
ChainItem =
|
||||
Invoke +
|
||||
@ -308,6 +317,9 @@ local build_grammar = wrap(function()
|
||||
Slice = symx"[" * Num * sym":" * Num * (sym":" * Num)^-1 *sym"]" / mark"slice",
|
||||
|
||||
ColonCall = symx":" * (_Name * Invoke) / mark"colon",
|
||||
|
||||
ColonSuffix = symx":" * _Name / mark"colon_stub",
|
||||
|
||||
Invoke = FnArgs/mark"call" +
|
||||
SingleString / wrap_func_arg +
|
||||
DoubleString / wrap_func_arg,
|
||||
|
@ -134,5 +134,8 @@ x = #{#{},#{1},#{1,2}}
|
||||
|
||||
hello, world
|
||||
|
||||
|
||||
something:hello(what) a,b
|
||||
something:hello what
|
||||
something.hello:world a,b
|
||||
something.hello:world(1,2,3) a,b
|
||||
|
||||
|
@ -87,4 +87,8 @@ x = not true
|
||||
local y = not (5 + 5)
|
||||
y = #"hello"
|
||||
x = #{ #{ }, #{ 1 }, #{ 1, 2 } }
|
||||
_ = hello, world
|
||||
_ = hello, world
|
||||
something:hello(what)(a, b)
|
||||
something:hello(what)
|
||||
something.hello:world(a, b)
|
||||
something.hello:world(1, 2, 3)(a, b)
|
Loading…
Reference in New Issue
Block a user