1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00
anselme/parser/expression/secondary/infix/assignment_call.lua
Étienne Reuh Fildadut e71bff9562 Replace persistent variable system
Previous system linked the variable name with the saved value, meaning the variable could not be renamed or moved outside the global scope.

Instead we propose to store all persistent values in a global table, identifying each by a key. To still allow nice manipulation with identifiers, the alias syntax replace the persistent syntax for symbols - an aliases symbol will act as if a function call was used in place of the identifier when it appear.
2023-12-27 21:25:14 +01:00

24 lines
658 B
Lua

local infix = require("parser.expression.secondary.infix.infix")
local escape = require("common").escape
local operator_priority = require("common").operator_priority
local ast = require("ast")
local Call = ast.Call
return infix {
operator = "=",
identifier = "_=_",
priority = operator_priority["_=_"],
-- return bool
match = function(self, str, current_priority, primary)
local escaped = escape(self.operator)
return self.priority > current_priority and str:match("^"..escaped) and Call:is(primary)
end,
build_ast = function(self, left, right)
local args = left.arguments:with_assignment(right)
return Call:new(left.func, args)
end,
}