mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Allow function call with tuple and struct without parentheses
This commit is contained in:
parent
51ad18c5a4
commit
8562e8f18b
5 changed files with 42 additions and 8 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
local secondary = require("anselme.parser.expression.secondary.secondary")
|
||||
local parenthesis = require("anselme.parser.expression.primary.parenthesis")
|
||||
local tuple = require("anselme.parser.expression.primary.tuple")
|
||||
local struct = require("anselme.parser.expression.primary.struct")
|
||||
|
||||
local operator_priority = require("anselme.common").operator_priority
|
||||
|
||||
|
|
@ -12,22 +14,32 @@ return secondary {
|
|||
priority = operator_priority["_()"],
|
||||
|
||||
match = function(self, str, current_priority, primary)
|
||||
return self.priority > current_priority and parenthesis:match(str)
|
||||
return self.priority > current_priority and (parenthesis:match(str) or tuple:match(str) or struct:match(str))
|
||||
end,
|
||||
|
||||
parse = function(self, source, str, limit_pattern, current_priority, primary)
|
||||
local start_source = source:clone()
|
||||
local args = ArgumentTuple:new()
|
||||
|
||||
local exp, rem = parenthesis:parse(source, str, limit_pattern)
|
||||
local exp, rem
|
||||
|
||||
if Nil:is(exp) then
|
||||
if str:match("^%(%s*%(%s*%)%s*%)") then -- special case: single nil argument
|
||||
exp = Tuple:new(Nil:new())
|
||||
else -- no arguments
|
||||
exp = Tuple:new()
|
||||
if parenthesis:match(str) then
|
||||
exp, rem = parenthesis:parse(source, str, limit_pattern)
|
||||
|
||||
if Nil:is(exp) then
|
||||
if str:match("^%(%s*%(%s*%)%s*%)") then -- special case: single nil argument
|
||||
exp = Tuple:new(Nil:new())
|
||||
else -- no arguments
|
||||
exp = Tuple:new()
|
||||
end
|
||||
elseif not Tuple:is(exp) or exp.explicit then -- single argument
|
||||
exp = Tuple:new(exp)
|
||||
end
|
||||
elseif not Tuple:is(exp) or exp.explicit then -- single argument
|
||||
elseif tuple:match(str) then
|
||||
exp, rem = tuple:parse(source, str, limit_pattern)
|
||||
exp = Tuple:new(exp)
|
||||
else
|
||||
exp, rem = struct:parse(source, str, limit_pattern)
|
||||
exp = Tuple:new(exp)
|
||||
end
|
||||
|
||||
|
|
|
|||
7
test/results/function call struct.ans
Normal file
7
test/results/function call struct.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"{\"l\":8, 4:3, true:6}" {}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
7
test/results/function call tuple.ans
Normal file
7
test/results/function call tuple.ans
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--# run #--
|
||||
--- text ---
|
||||
| {}"" {}"[3, 6, 8]" {}"" |
|
||||
--- return ---
|
||||
()
|
||||
--# saved #--
|
||||
{}
|
||||
4
test/tests/function call struct.ans
Normal file
4
test/tests/function call struct.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
:f = $(l)
|
||||
|{l}
|
||||
|
||||
f{4:3,true:6,"l":8}
|
||||
4
test/tests/function call tuple.ans
Normal file
4
test/tests/function call tuple.ans
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
:f = $(l)
|
||||
|{l}
|
||||
|
||||
f[3,6,8]
|
||||
Loading…
Add table
Add a link
Reference in a new issue