1
0
Fork 0
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:
Étienne Fildadut 2024-01-08 16:41:44 +01:00
parent 51ad18c5a4
commit 8562e8f18b
5 changed files with 42 additions and 8 deletions

View file

@ -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,14 +14,17 @@ 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 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
@ -30,6 +35,13 @@ return secondary {
elseif not Tuple:is(exp) or exp.explicit then -- single argument
exp = Tuple:new(exp)
end
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
for _, v in ipairs(exp.list) do
if Assignment:is(v) then

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"{\"l\":8, 4:3, true:6}" {}"" |
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,7 @@
--# run #--
--- text ---
| {}"" {}"[3, 6, 8]" {}"" |
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,4 @@
:f = $(l)
|{l}
f{4:3,true:6,"l":8}

View file

@ -0,0 +1,4 @@
:f = $(l)
|{l}
f[3,6,8]