Skip to content
← Back

src/syntax/trees/expressions/identifier.ghul

1
namespace Syntax.Trees.Expressions is
2
3
use Source;
4
5
class IDENTIFIER(location: LOCATION, identifier: Identifiers.Identifier): Expression is
6
right_location: LOCATION => identifier.right_location;
7
8
could_be_formal_argument: bool => !identifier.is_qualified;
9
could_be_type_expression: bool => true;
10
is_identifier: bool => true;
11
is_unqualified_identifier: bool => !identifier.is_qualified;
12
13
// Pushed in by the parent context. The compile-expressions
14
// pass uses it to lower a bare unit-variant identifier to a
15
// singleton load — `let n: Option[int] = NONE` specialises
16
// the union from the declared type. Other identifier shapes
17
// ignore the field.
18
19
try_copy_as_type_expression() -> TypeExpressions.TypeExpression? =>
20
if could_be_type_expression then
21
return TypeExpressions.NAMED(location, identifier.copy());
22
else
23
return null;
24
fi;
25
26
try_copy_as_identifer() -> Identifiers.Identifier =>
27
identifier.copy();
28
29
try_copy_as_variable_left() -> Variables.VariableLeft? =>
30
if identifier.is_qualified then
31
null
32
else
33
Variables.SIMPLE_VARIABLE_LEFT(location, identifier.copy())
34
fi;
35
36
super(location);
37
38
set_expected_type(expected_type: Semantic.Types.Type?, error_message: string?) is
39
compile_expressions_state.set_expected_type(expected_type, error_message);
40
si
41
42
accept(visitor: Visitor) =>
43
visitor.visit(self);
44
45
walk(visitor: Visitor) is
46
if !visitor.pre(self) then
47
identifier.walk(visitor);
48
fi
49
50
accept(visitor);
51
si
52
si
53
si