Skip to content
← Back

src/syntax/trees/pragmas/pragma.ghul

1
namespace Syntax.Trees.Pragmas is
2
use Source
3
4
// A `name = value` argument of an attribute pragma. Unlike a positional
5
// argument it is not a visitable AST node — only its value expression is
6
// walked (so it gets compiled); the name is resolved against the
7
// attribute type's members by ATTRIBUTE_RESOLVER, not as a scope use.
8
class NAMED_ARGUMENT(name: Identifiers.Identifier, value: Expressions.Expression) is
9
si
10
11
class PRAGMA(
12
location: LOCATION,
13
name: Identifiers.Identifier,
14
arguments: Expressions.LIST,
15
named_arguments: Collections.LIST[NAMED_ARGUMENT]?
16
): Trees.Node is
17
super(location)
18
19
// Set on the pragmas the compiler itself writes into the tree —
20
// the `IL.name` on a primary constructor's synthesized `deconstruct`
21
// — so a check that reports what the program wrote passes its own
22
// by.
23
is_synthesised: bool public
24
25
is_name_equal_to(other_name: string) -> bool => other_name =~ name.name
26
27
try_get_string_literal_at(index: int) -> string? =>
28
arguments.try_get_string_literal_at(index)
29
30
31
accept(visitor: Visitor) is
32
visitor.visit(self)
33
si
34
35
walk(visitor: Visitor) is
36
if !visitor.pre(self) then
37
name.walk(visitor)
38
39
arguments.walk(visitor)
40
41
if named_arguments? then
42
for named_argument in named_arguments do
43
named_argument.value.walk(visitor)
44
od
45
fi
46
fi
47
48
accept(visitor)
49
si
50
si
51
si