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

Add identifier wrap for aliases

This commit is contained in:
Étienne Fildadut 2023-12-31 14:55:28 +01:00
parent 409a2e7095
commit 050c84921c
3 changed files with 31 additions and 8 deletions

View file

@ -1,5 +1,5 @@
local ast = require("anselme.ast") local ast = require("anselme.ast")
local Nil, Boolean, Definition, Call, Function, ParameterTuple, FunctionParameter, Identifier, Overload = ast.Nil, ast.Boolean, ast.Definition, ast.Call, ast.Function, ast.ParameterTuple, ast.FunctionParameter, ast.Identifier, ast.Overload local Nil, Boolean, Definition, Call, Function, ParameterTuple, FunctionParameter, Identifier, Overload, Assignment = ast.Nil, ast.Boolean, ast.Definition, ast.Call, ast.Function, ast.ParameterTuple, ast.FunctionParameter, ast.Identifier, ast.Overload, ast.Assignment
local assert0 = require("anselme.common").assert0 local assert0 = require("anselme.common").assert0
return { return {
@ -47,16 +47,21 @@ return {
local exp = q.expression local exp = q.expression
local get = Function:new(ParameterTuple:new(), exp):eval(state) local get = Function:new(ParameterTuple:new(), exp):eval(state)
local set_exp
if Call:is(exp) then if Call:is(exp) then
local set_param = ParameterTuple:new() set_exp = Call:new(exp.func, exp.arguments:with_assignment(Identifier:new("value")))
set_param:insert_assignment(FunctionParameter:new(Identifier:new("value"))) elseif Identifier:is(exp) then
local assign_expr = Call:new(exp.func, exp.arguments:with_assignment(Identifier:new("value"))) set_exp = Assignment:new(exp, Identifier:new("value"))
local set = Function:new(set_param, assign_expr):eval(state)
return Overload:new(get, set)
end end
return get if set_exp then
local set_param = ParameterTuple:new()
set_param:insert_assignment(FunctionParameter:new(Identifier:new("value")))
local set = Function:new(set_param, set_exp):eval(state)
return Overload:new(get, set)
else
return get
end
end end
} }
} }

View file

@ -0,0 +1,9 @@
--# run #--
--- text ---
| {}"" {}"4" {}" = " {}"4" {}" = 4" |
--- text ---
| {}"" {}"12" {}" = " {}"12" {}" = 12" |
--- return ---
()
--# saved #--
{}

View file

@ -0,0 +1,9 @@
:l = 4
:&c => l
| {c} = {l} = 4
c = 12
| {c} = {l} = 12