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:
parent
409a2e7095
commit
050c84921c
3 changed files with 31 additions and 8 deletions
|
|
@ -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
|
||||||
|
set_exp = Call:new(exp.func, exp.arguments:with_assignment(Identifier:new("value")))
|
||||||
|
elseif Identifier:is(exp) then
|
||||||
|
set_exp = Assignment:new(exp, Identifier:new("value"))
|
||||||
|
end
|
||||||
|
|
||||||
|
if set_exp then
|
||||||
local set_param = ParameterTuple:new()
|
local set_param = ParameterTuple:new()
|
||||||
set_param:insert_assignment(FunctionParameter:new(Identifier:new("value")))
|
set_param:insert_assignment(FunctionParameter:new(Identifier:new("value")))
|
||||||
local assign_expr = Call:new(exp.func, exp.arguments:with_assignment(Identifier:new("value")))
|
local set = Function:new(set_param, set_exp):eval(state)
|
||||||
local set = Function:new(set_param, assign_expr):eval(state)
|
|
||||||
|
|
||||||
return Overload:new(get, set)
|
return Overload:new(get, set)
|
||||||
end
|
else
|
||||||
|
|
||||||
return get
|
return get
|
||||||
end
|
end
|
||||||
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
test/results/alias identifier.ans
Normal file
9
test/results/alias identifier.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
--# run #--
|
||||||
|
--- text ---
|
||||||
|
| {}"" {}"4" {}" = " {}"4" {}" = 4" |
|
||||||
|
--- text ---
|
||||||
|
| {}"" {}"12" {}" = " {}"12" {}" = 12" |
|
||||||
|
--- return ---
|
||||||
|
()
|
||||||
|
--# saved #--
|
||||||
|
{}
|
||||||
9
test/tests/alias identifier.ans
Normal file
9
test/tests/alias identifier.ans
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
:l = 4
|
||||||
|
|
||||||
|
:&c => l
|
||||||
|
|
||||||
|
| {c} = {l} = 4
|
||||||
|
|
||||||
|
c = 12
|
||||||
|
|
||||||
|
| {c} = {l} = 12
|
||||||
Loading…
Add table
Add a link
Reference in a new issue