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

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.
This commit is contained in:
Étienne Fildadut 2023-12-27 21:25:14 +01:00
parent 56ed6c912b
commit e71bff9562
13 changed files with 169 additions and 58 deletions

View file

@ -167,11 +167,11 @@ return primary {
local mod_const, mod_exported, rem = source:consume(str:match("^(%:(:?)([&@]?)%$)(.-)$"))
-- get modifiers
local constant, exported, persistent
local constant, exported, alias
if mod_const == ":" then constant = true end
if mod_exported == "@" then exported = true
elseif mod_exported == "&" then persistent = true end
local modifiers = { constant = constant, exported = exported, persistent = persistent }
elseif mod_exported == "&" then alias = true end
local modifiers = { constant = constant, exported = exported, alias = alias }
-- search for a valid signature
local symbol, parameters

View file

@ -16,11 +16,11 @@ return primary {
parse = function(self, source, str)
local mod_const, mod_export, rem = source:consume(str:match("^(%:(:?)([&@]?))(.-)$"))
local constant, persistent, type_check_exp, exported
local constant, alias, type_check_exp, exported
-- get modifier
if mod_const == ":" then constant = true end
if mod_export == "&" then persistent = true
if mod_export == "&" then alias = true
elseif mod_export == "@" then exported = true end
-- name
@ -35,6 +35,6 @@ return primary {
type_check_exp = exp.arguments.positional[2]
end
return ident:to_symbol{ constant = constant, persistent = persistent, exported = exported, type_check = type_check_exp }:set_source(source), rem
return ident:to_symbol{ constant = constant, alias = alias, exported = exported, type_check = type_check_exp }:set_source(source), rem
end
}

View file

@ -18,7 +18,7 @@ return infix {
end,
build_ast = function(self, left, right)
left.arguments:add_assignment(right)
return Call:new(left.func, left.arguments) -- recreate Call since we modified left.arguments
local args = left.arguments:with_assignment(right)
return Call:new(left.func, args)
end,
}