mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 09:09:31 +00:00
Fix index with identifier conflicts with some syntaxes
This commit is contained in:
parent
b7761311fe
commit
d928ff5598
3 changed files with 26 additions and 10 deletions
|
|
@ -2,18 +2,8 @@ local infix = require("anselme.parser.expression.secondary.infix.infix")
|
||||||
|
|
||||||
local operator_priority = require("anselme.common").operator_priority
|
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 {
|
return infix {
|
||||||
operator = ".",
|
operator = ".",
|
||||||
identifier = "_._",
|
identifier = "_._",
|
||||||
priority = operator_priority["_._"],
|
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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -44,6 +44,7 @@ local secondaries = {
|
||||||
-- 12
|
-- 12
|
||||||
r("infix.call"),
|
r("infix.call"),
|
||||||
-- 14
|
-- 14
|
||||||
|
r("infix.index_identifier"),
|
||||||
r("infix.index"),
|
r("infix.index"),
|
||||||
-- 3
|
-- 3
|
||||||
r("infix.assignment"), -- deported after equal
|
r("infix.assignment"), -- deported after equal
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue