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

Fix _._ operator not working with arbitrary expressions

This commit is contained in:
Étienne Fildadut 2022-09-16 21:40:45 +09:00
parent f0ecfbb43b
commit c43266260d
3 changed files with 37 additions and 13 deletions

View file

@ -82,7 +82,7 @@ common = {
--- split a string separated by . --- split a string separated by .
split = function(str) split = function(str)
local address = {} local address = {}
for name in str:gmatch("[^%.]+") do for name in (str.."."):gmatch("(.-)%.") do
table.insert(address, name) table.insert(address, name)
end end
return address return address
@ -92,12 +92,14 @@ common = {
-- returns value, fqm in case of success -- returns value, fqm in case of success
-- returns nil, err in case of error -- returns nil, err in case of error
find = function(aliases, list, namespace, name) find = function(aliases, list, namespace, name)
local ns = common.split(namespace) if namespace ~= "" then
for i=#ns, 1, -1 do local ns = common.split(namespace:gsub("%.$", ""))
local current_namespace = table.concat(ns, ".", 1, i) for i=#ns, 1, -1 do
local fqm = replace_aliases(aliases, current_namespace, name) local current_namespace = table.concat(ns, ".", 1, i)
if list[fqm] then local fqm = replace_aliases(aliases, current_namespace, name)
return list[fqm], fqm if list[fqm] then
return list[fqm], fqm
end
end end
end end
-- root namespace -- root namespace
@ -111,12 +113,14 @@ common = {
-- returns a list of fqm -- returns a list of fqm
find_all = function(aliases, list, namespace, name) find_all = function(aliases, list, namespace, name)
local l = {} local l = {}
local ns = common.split(namespace) if namespace ~= "" then
for i=#ns, 1, -1 do local ns = common.split(namespace:gsub("%.$", ""))
local current_namespace = table.concat(ns, ".", 1, i) for i=#ns, 1, -1 do
local fqm = replace_aliases(aliases, current_namespace, name) local current_namespace = table.concat(ns, ".", 1, i)
if list[fqm] then local fqm = replace_aliases(aliases, current_namespace, name)
table.insert(l, fqm) if list[fqm] then
table.insert(l, fqm)
end
end end
end end
-- root namespace -- root namespace

View file

@ -0,0 +1,6 @@
:$ f
:x = 5
:a = &f
{a.("x")}

View file

@ -0,0 +1,14 @@
local _={}
_[5]={}
_[4]={text="5",tags=_[5]}
_[3]={_[4]}
_[2]={"return"}
_[1]={"text",_[3]}
return {_[1],_[2]}
--[[
{ "text", { {
tags = {},
text = "5"
} } }
{ "return" }
]]--