summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luacas/tex/core/luacas-compoundexpression.lua
blob: 792c36cfc278689160b939b7c9c40c79bd1715f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)