diff options
Diffstat (limited to 'macros/luatex/latex/luacas/tex/core/compoundexpression.lua')
-rw-r--r-- | macros/luatex/latex/luacas/tex/core/compoundexpression.lua | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/macros/luatex/latex/luacas/tex/core/compoundexpression.lua b/macros/luatex/latex/luacas/tex/core/compoundexpression.lua new file mode 100644 index 0000000000..792c36cfc2 --- /dev/null +++ b/macros/luatex/latex/luacas/tex/core/compoundexpression.lua @@ -0,0 +1,52 @@ +--- @class CompoundExpression +--- Interface for an expression consisting of one or more subexpressions. +CompoundExpression = {} +__CompoundExpression = {} + +---------------------- +-- Instance methods -- +---------------------- + +--- @param symbol SymbolExpression +--- @return boolean +function CompoundExpression:freeof(symbol) + for _, expression in ipairs(self:subexpressions()) do + if not expression:freeof(symbol) then + return false + end + end + return true + end + +--- @param map table<Expression, Expression> +--- @return Expression +function CompoundExpression:substitute(map) + for expression, replacement in pairs(map) do + if self == expression then + return replacement + end + end + + local results = {} + for index, expression in ipairs(self:subexpressions()) do + results[index] = expression:substitute(map) + end + return self:setsubexpressions(results) +end + +--- @return boolean +function CompoundExpression:isatomic() + return false +end + +--- @return boolean +function CompoundExpression:isconstant() + return false +end + +----------------- +-- Inheritance -- +----------------- + +__CompoundExpression.__index = Expression +CompoundExpression = setmetatable(CompoundExpression, __CompoundExpression)
\ No newline at end of file |