1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-28 00:59:31 +00:00

Add maps; remove map emulation functionality from list; function and tags now internally use maps instead of lists

This commit is contained in:
Étienne Fildadut 2022-09-09 21:39:37 +09:00
parent bac5cdde01
commit 95462391e3
20 changed files with 699 additions and 139 deletions

View file

@ -287,7 +287,7 @@ common = {
implicit_call = implicit_call, -- was call implicitely (no ! or parentheses)?
variants = variants, -- list of potential variants
argument = { -- wrap everything in a list literal to simplify later things (otherwise may be nil, single value, list constructor)
type = "list_brackets",
type = "map_brackets",
expression = arg
}
}

View file

@ -132,6 +132,21 @@ local function expression(s, state, namespace, current_priority, operating_on)
type = "list_brackets",
expression = exp
})
-- map parenthesis
elseif s:match("^%b{}") then
local content, r = s:match("^(%b{})(.*)$")
content = content:gsub("^%{", ""):gsub("%}$", "")
local exp
if content:match("[^%s]") then
local r_paren
exp, r_paren = expression(content, state, namespace)
if not exp then return nil, "invalid expression inside map parentheses: "..r_paren end
if r_paren:match("[^%s]") then return nil, ("unexpected %q at end of map parenthesis expression"):format(r_paren) end
end
return expression(r, state, namespace, current_priority, {
type = "map_brackets",
expression = exp
})
-- identifier
elseif s:match("^"..identifier_pattern) then
local name, r = s:match("^("..identifier_pattern..")(.-)$")
@ -182,7 +197,7 @@ local function expression(s, state, namespace, current_priority, operating_on)
local err
args, err = expression(content, state, namespace)
if not args then return args, err end
if err:match("[^%s]") then return nil, ("unexpected %q at end of argument list"):format(err) end
if err:match("[^%s]") then return nil, ("unexpected %q at end of argument map"):format(err) end
end
else -- implicit call; will be changed if there happens to be a ! after in the suffix operator code
implicit_call = true
@ -267,7 +282,7 @@ local function expression(s, state, namespace, current_priority, operating_on)
local err
args, err = expression(content, state, namespace)
if not args then return args, err end
if err:match("[^%s]") then return nil, ("unexpected %q at end of argument list"):format(err) end
if err:match("[^%s]") then return nil, ("unexpected %q at end of argument map"):format(err) end
end
end
-- add first argument

View file

@ -332,11 +332,7 @@ local function parse_line(line, state, namespace, parent_function)
r.type = "tag"
r.child = true
local expr = l:match("^%#(.*)$")
if expr:match("[^%s]") then
r.expression = expr
else
r.expression = "()"
end
r.expression = ("{%s}"):format(expr)
-- return
elseif l:match("^%@") then
r.type = "return"