Skip to content
← Back

src/syntax/trees/expressions/tuple_element.ghul

1
namespace Syntax.Trees.Expressions is
2
3
use Source;
4
5
class TUPLE_ELEMENT: Expression is
6
name: Identifiers.Identifier;
7
initializer: Expression?;
8
type_expression: TypeExpressions.TypeExpression;
9
is_tuple_element: bool => true;
10
11
// Attribute pragmas carried over from the Expressions.VARIABLE
12
// this element was rewritten from — see Expressions.VARIABLE.
13
pragmas: Collections.LIST[Pragmas.PRAGMA]? public;
14
15
init(
16
location: LOCATION,
17
name: Identifiers.Identifier,
18
type_expression: TypeExpressions.TypeExpression,
19
initializer: Expression?
20
)
21
is
22
super.init(location);
23
24
self.name = name;
25
self.type_expression = type_expression;
26
self.initializer = initializer;
27
si
28
29
set_pragmas(pragmas: Collections.LIST[Pragmas.PRAGMA]) is
30
self.pragmas = pragmas;
31
si
32
33
// A `name: T` element keeps that shape when the enclosing
34
// group turns out to be a destructure pattern rather than a
35
// tuple literal, where it is a leaf with a per-element type
36
// ascription exactly as in a `let`.
37
try_copy_as_variable_left() -> Variables.VariableLeft? is
38
let result = Variables.SIMPLE_VARIABLE_LEFT(location, name.copy());
39
40
if !isa TypeExpressions.INFER(type_expression) then
41
result.set_type_expression(type_expression.copy());
42
fi
43
44
return result;
45
si
46
47
try_copy_as_variable() -> VARIABLE is
48
let result = VARIABLE(location, name, type_expression, initializer);
49
50
if let self_pragmas = pragmas then
51
result.set_pragmas(self_pragmas);
52
fi
53
54
return result;
55
si
56
57
rewrite_as_expression() -> Expression is
58
IoC.CONTAINER.instance.logger.error(name.location, "name not allowed here");
59
60
IoC.CONTAINER.instance.logger.error(type_expression.location, "type not allowed here");
61
62
if pragmas? then
63
for pragma in pragmas do
64
IoC.CONTAINER.instance.logger.error(pragma.location, "attribute is not allowed here");
65
od
66
fi
67
68
return initializer!
69
si
70
71
accept(visitor: Visitor) is
72
visitor.visit(self);
73
si
74
75
walk(visitor: Visitor) is
76
if !visitor.pre(self) then
77
if pragmas? then
78
for pragma in pragmas do
79
pragma.walk(visitor);
80
od
81
fi
82
83
name.walk(visitor);
84
type_expression.walk(visitor);
85
86
if initializer? then
87
initializer.walk(visitor);
88
fi
89
fi
90
91
accept(visitor);
92
si
93
si
94
si