Skip to content
← Back

src/syntax/trees/expressions/string_interpolation.ghul

1
namespace Syntax.Trees.Expressions is
2
use IO.Std
3
use Source
4
5
class STRING_INTERPOLATION: Expression is
6
_values: Collections.LIST[INTERPOLATION_FRAGMENT]
7
values: Collections.List[INTERPOLATION_FRAGMENT] => _values
8
literal_length: int
9
expression_count: int
10
11
init(
12
location: LOCATION,
13
values: Collections.LIST[INTERPOLATION_FRAGMENT],
14
literal_length: int,
15
expression_count: int
16
) is
17
super.init(location)
18
19
self._values = values
20
self.literal_length = literal_length
21
self.expression_count = expression_count
22
si
23
24
// Swaps the expression a fragment evaluates, keeping its
25
// alignment and format.
26
replace_expression(index: int, expression: Expression) is
27
let fragment = _values[index]
28
29
_values[index] = INTERPOLATION_FRAGMENT(fragment.is_expression, expression, fragment.alignment, fragment.format)
30
si
31
32
accept(visitor: Visitor) is
33
visitor.visit(self)
34
si
35
36
walk(visitor: Visitor) is
37
if !visitor.pre(self) then
38
for v in _values do
39
v.expression.walk(visitor)
40
41
if let v.alignment? then
42
alignment.walk(visitor)
43
fi
44
od
45
fi
46
47
accept(visitor)
48
si
49
si
50
51
struct INTERPOLATION_FRAGMENT is
52
is_expression: bool
53
expression: Expression
54
// Null when the interpolation has no `,alignment` clause.
55
alignment: Expression?
56
// Null when the interpolation has no `:format` clause.
57
format: string?
58
59
init(
60
is_expression: bool,
61
expression: Expression,
62
alignment: Expression?,
63
format: string?
64
) is
65
self.is_expression = is_expression
66
self.expression = expression
67
self.alignment = alignment
68
self.format = format
69
si
70
si
71
si