1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2026-02-04 02:08:40 +00:00

feat: add prefix attributes in variables declarations

This commit is contained in:
Étienne Fildadut 2025-11-24 18:56:35 +01:00
parent 1e118381f8
commit 19405a4d8e
3 changed files with 15 additions and 3 deletions

View file

@ -585,8 +585,9 @@ local G = { V"Lua",
ImplicitPushStat = tagC("Push", commaSep(V"Expr", "RetList")) / markImplicit;
NameList = tagC("NameList", commaSep(V"Id"));
DestructuringNameList = tagC("NameList", commaSep(V"DestructuringId")),
AttributeNameList = tagC("AttributeNameList", commaSep(V"AttributeId"));
DestructuringNameList = tagC("NameList", commaSep(V"DestructuringId"));
AttributeNameList = tagC("AttributeNameList", commaSep(V"AttributeId"))
+ tagC("PrefixedAttributeNameList", V"Attribute" * commaSep(V"AttributeId"));
VarList = tagC("VarList", commaSep(V"VarExpr"));
ExprList = tagC("ExpList", commaSep(V"Expr", "ExprList"));

View file

@ -8,6 +8,9 @@ tags.AttributeId = (t)
return t[1]
end
end
tags.PrefixedAttributeNameList = (t)
error("target "..targetName.." does not support variable attributes")
end
#placeholder("patch")

View file

@ -465,7 +465,7 @@ return function(code, ast, options, macros={functions={}, variables={}})
-- Local{ {attributeident+} {expr+}? }
Local = (t)
local destructured = {}
local r = "local "..push("destructuring", destructured)..lua(t[1], "_lhs")..pop("destructuring")
local r = "local "..push("destructuring", destructured)..lua(t[1])..pop("destructuring")
if t[2][1] then
r ..= " = "..lua(t[2], "_lhs")
end
@ -822,6 +822,14 @@ return function(code, ast, options, macros={functions={}, variables={}})
end
return r
end,
-- PrefixedAttributeNameList{ attribute {AttributeId+} }
PrefixedAttributeNameList = (t)
return "<" .. t[1] .. "> " .. lua(t, "_lhs", 2)
end,
-- AttributeNameList{ {AttributeId+} }
AttributeNameList = (t)
return lua(t, "_lhs")
end,
-- AttributeId{ <string> <string>? }
AttributeId = (t)
if t[2] then