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 secondary = require("anselme.parser.expression.secondary.secondary")
|
||||||
local parenthesis = require("anselme.parser.expression.primary.parenthesis")
|
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
|
local operator_priority = require("anselme.common").operator_priority
|
||||||
|
|
||||||
|
|
@ -12,22 +14,32 @@ return secondary {
|
||||||
priority = operator_priority["_()"],
|
priority = operator_priority["_()"],
|
||||||
|
|
||||||
match = function(self, str, current_priority, primary)
|
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,
|
end,
|
||||||
|
|
||||||
parse = function(self, source, str, limit_pattern, current_priority, primary)
|
parse = function(self, source, str, limit_pattern, current_priority, primary)
|
||||||
local start_source = source:clone()
|
local start_source = source:clone()
|
||||||
local args = ArgumentTuple:new()
|
local args = ArgumentTuple:new()
|
||||||
|
|
||||||
local exp, rem = parenthesis:parse(source, str, limit_pattern)
|
local exp, rem
|
||||||
|
|
||||||
if Nil:is(exp) then
|
if parenthesis:match(str) then
|
||||||
if str:match("^%(%s*%(%s*%)%s*%)") then -- special case: single nil argument
|
exp, rem = parenthesis:parse(source, str, limit_pattern)
|
||||||
exp = Tuple:new(Nil:new())
|
|
||||||
else -- no arguments
|
if Nil:is(exp) then
|
||||||
exp = Tuple:new()
|
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
|
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)
|
exp = Tuple:new(exp)
|
||||||
end
|
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