Skip to content
← Back

src/syntax/parsers/modifiers/modifier.ghul

1
namespace Syntax.Parsers.Modifiers is
2
class MODIFIER(): Base[Trees.Modifiers.Modifier] is
3
super();
4
5
init(..) is
6
add_parsers();
7
si
8
9
add_parsers() is
10
add_parser(
11
context => Trees.Modifiers.PUBLIC(context.location_and_next()),
12
Lexical.TOKEN.PUBLIC
13
);
14
15
add_parser(
16
context => Trees.Modifiers.PRIVATE(context.location_and_next()),
17
Lexical.TOKEN.PRIVATE
18
);
19
20
add_parser(
21
context => Trees.Modifiers.PROTECTED(context.location_and_next()),
22
Lexical.TOKEN.PROTECTED
23
);
24
25
add_parser(
26
context => Trees.Modifiers.STATIC(context.location_and_next()),
27
Lexical.TOKEN.STATIC
28
);
29
30
add_parser(
31
context => Trees.Modifiers.FIELD(context.location_and_next()),
32
Lexical.TOKEN.FIELD
33
);
34
35
add_parser(
36
context => Trees.Modifiers.ABSTRACT(context.location_and_next()),
37
Lexical.TOKEN.ABSTRACT
38
);
39
si
40
41
// `init` and `open` remain contextual: promoting `init` would
42
// break every `init(...)` method declaration, and `open` is a
43
// common identifier in stream/file APIs. In modifier position
44
// the IDENTIFIER token with the right text produces the
45
// corresponding Modifier subtype; everything else falls
46
// through, ending the modifier list. Semantic validity (which
47
// modifiers can appear where) is enforced during later passes.
48
other_token(context: CONTEXT) -> Trees.Modifiers.Modifier? is
49
if context.current.token == Lexical.TOKEN.IDENTIFIER then
50
if context.current.value_string =~ "init" then
51
return Trees.Modifiers.INIT(context.location_and_next());
52
elif context.current.value_string =~ "open" then
53
return Trees.Modifiers.OPEN(context.location_and_next());
54
elif context.current.value_string =~ "pure" then
55
return Trees.Modifiers.PURE(context.location_and_next());
56
fi
57
fi
58
return null;
59
si
60
si
61
si