Debian Codegraph @

texmf-dist/tex/lualatex/luacas/core/luacas-compoundexpression.lua

raw
1 --- @class CompoundExpression
2 --- Interface for an expression consisting of one or more subexpressions.
3 CompoundExpression = {}
4 local __CompoundExpression = {}
5
6 ----------------------
7 -- Instance methods --
8 ----------------------
9
10 --- @param symbol SymbolExpression
11 --- @return boolean
12 function CompoundExpression:freeof(symbol)
13 for _, expression in ipairs(self:subexpressions()) do
14 if not expression:freeof(symbol) then
15 return false
16 end
17 end
18 return true
19 end
20
21 --- @param map table<Expression, Expression>
22 --- @return Expression
23 function CompoundExpression:substitute(map)
24 for expression, replacement in pairs(map) do
25 if self == expression then
26 return replacement
27 end
28 end
29
30 local results = {}
31 for index, expression in ipairs(self:subexpressions()) do
32 results[index] = expression:substitute(map)
33 end
34 return self:setsubexpressions(results)
35 end
36
37 --- @return boolean
38 function CompoundExpression:isatomic()
39 return false
40 end
41
42 --- @return boolean
43 function CompoundExpression:isconstant()
44 return false
45 end
46
47 -----------------
48 -- Inheritance --
49 -----------------
50
51 __CompoundExpression.__index = Expression
52 CompoundExpression = setmetatable(CompoundExpression, __CompoundExpression)