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

Fix index with identifier conflicts with some syntaxes

This commit is contained in:
Étienne Fildadut 2023-12-30 23:44:59 +01:00
parent b7761311fe
commit d928ff5598
3 changed files with 26 additions and 10 deletions

View file

@ -2,18 +2,8 @@ local infix = require("anselme.parser.expression.secondary.infix.infix")
local operator_priority = require("anselme.common").operator_priority
local ast = require("anselme.ast")
local Call, Identifier, ArgumentTuple = ast.Call, ast.Identifier, ast.ArgumentTuple
return infix {
operator = ".",
identifier = "_._",
priority = operator_priority["_._"],
build_ast = function(self, left, right)
if Identifier:is(right) then
right = right:to_string()
end
return Call:new(Identifier:new(self.identifier), ArgumentTuple:new(left, right))
end
}

View file

@ -0,0 +1,25 @@
local escape = require("anselme.common").escape
local infix = require("anselme.parser.expression.secondary.infix.infix")
local identifier = require("anselme.parser.expression.primary.identifier")
local operator_priority = require("anselme.common").operator_priority
local ast = require("anselme.ast")
local Call, Identifier, ArgumentTuple = ast.Call, ast.Identifier, ast.ArgumentTuple
return infix {
operator = ".",
identifier = "_._",
priority = operator_priority["_._"],
match = function(self, str, current_priority, primary)
local escaped = escape(self.operator)
return self.priority > current_priority and str:match("^"..escaped) and identifier:match(str:match("^.(.-)$"))
end,
build_ast = function(self, left, right)
assert(Identifier:is(right))
return Call:new(Identifier:new(self.identifier), ArgumentTuple:new(left, right:to_string()))
end
}

View file

@ -44,6 +44,7 @@ local secondaries = {
-- 12
r("infix.call"),
-- 14
r("infix.index_identifier"),
r("infix.index"),
-- 3
r("infix.assignment"), -- deported after equal