mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 00:59:31 +00:00
Add variable reference and use them in alias(ref, id)
This commit is contained in:
parent
037654ebcf
commit
acb8945dec
11 changed files with 138 additions and 45 deletions
|
|
@ -6,16 +6,19 @@ local common
|
|||
|
||||
--- rewrite name to use defined aliases (under namespace only)
|
||||
-- namespace should not contain aliases
|
||||
-- returns the final fqm
|
||||
local replace_aliases = function(aliases, namespace, name)
|
||||
namespace = namespace == "" and "" or namespace.."."
|
||||
local name_list = common.split(name)
|
||||
for i=1, #name_list, 1 do
|
||||
local n = ("%s%s"):format(namespace, table.concat(name_list, ".", 1, i))
|
||||
local prefix = namespace
|
||||
for i=1, #name_list, 1 do -- search alias for each part of the fqm
|
||||
local n = ("%s%s%s"):format(prefix, prefix == "" and "" or ".", name_list[i])
|
||||
if aliases[n] then
|
||||
name_list[i] = aliases[n]:match("[^%.]+$")
|
||||
prefix = aliases[n]
|
||||
else
|
||||
prefix = n
|
||||
end
|
||||
end
|
||||
return table.concat(name_list, ".")
|
||||
return prefix
|
||||
end
|
||||
|
||||
local disallowed_set = ("~`^+-=<>/[]*{}|\\_!?,;:()\"@&$#%"):gsub("[^%w]", "%%%1")
|
||||
|
|
@ -93,7 +96,7 @@ common = {
|
|||
local ns = common.split(namespace)
|
||||
for i=#ns, 1, -1 do
|
||||
local current_namespace = table.concat(ns, ".", 1, i)
|
||||
local fqm = ("%s.%s"):format(current_namespace, replace_aliases(aliases, current_namespace, name))
|
||||
local fqm = replace_aliases(aliases, current_namespace, name)
|
||||
if list[fqm] then
|
||||
return list[fqm], fqm
|
||||
end
|
||||
|
|
@ -112,7 +115,7 @@ common = {
|
|||
local ns = common.split(namespace)
|
||||
for i=#ns, 1, -1 do
|
||||
local current_namespace = table.concat(ns, ".", 1, i)
|
||||
local fqm = ("%s.%s"):format(current_namespace, replace_aliases(aliases, current_namespace, name))
|
||||
local fqm = replace_aliases(aliases, current_namespace, name)
|
||||
if list[fqm] then
|
||||
table.insert(l, fqm)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -190,15 +190,27 @@ local function expression(s, state, namespace, current_priority, operating_on)
|
|||
local escaped = escape(op)
|
||||
if s:match("^"..escaped) then
|
||||
local sright = s:match("^"..escaped.."(.*)$")
|
||||
-- function reference
|
||||
-- function and variable reference
|
||||
if op == "&" and sright:match("^"..identifier_pattern) then
|
||||
local name, r = sright:match("^("..identifier_pattern..")(.-)$")
|
||||
name = format_identifier(name)
|
||||
-- get all functions this name can reference
|
||||
-- try prefixes until we find a valid function name
|
||||
-- try prefixes until we find a valid function or variable name
|
||||
local nl = split(name)
|
||||
for i=#nl, 1, -1 do
|
||||
local name_prefix = table.concat(nl, ".", 1, i)
|
||||
-- variable ref
|
||||
local var, vfqm = find(state.aliases, state.variables, namespace, name_prefix)
|
||||
if var then
|
||||
if i < #nl then
|
||||
r = "."..table.concat(nl, ".", i+1, #nl)..r
|
||||
end
|
||||
return expression(r, state, namespace, current_priority, {
|
||||
type = "variable reference",
|
||||
name = vfqm
|
||||
})
|
||||
end
|
||||
-- function ref
|
||||
local lfnqm = find_all(state.aliases, state.functions, namespace, name_prefix)
|
||||
if #lfnqm > 0 then
|
||||
if i < #nl then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue