Skip to content
← Back

src/syntax/parsers/definitions/member.ghul

1
namespace Syntax.Parsers.Definitions is
2
use IO.Std;
3
4
use Source;
5
use Logging;
6
7
use Ghul.Pipes;
8
9
class MEMBER(
10
function_parser: Parser[Trees.Definitions.FUNCTION],
11
property_parser: Parser[Trees.Definitions.PROPERTY],
12
indexer_parser: Parser[Trees.Definitions.INDEXER],
13
pragma_parser: Parser[Trees.Definitions.PRAGMA],
14
super_call_parser: Parser[Trees.Definitions.SUPER_CALL]
15
): Base[Trees.Definitions.Definition] is
16
description: string => "member";
17
18
expected_tokens: Collections.Iterable[Lexical.TOKEN] => property_tokens;
19
20
property_tokens: Collections.List[Lexical.TOKEN];
21
22
super();
23
24
init(..) is
25
property_tokens = Collections.LIST([Lexical.TOKEN.COLON, Lexical.TOKEN.ASSIGN, Lexical.TOKEN.ARROW_FAT, Lexical.TOKEN.SEMICOLON]);
26
si
27
28
parse(context: CONTEXT) -> Trees.Definitions.Definition? is
29
if context.current.token == Lexical.TOKEN.SQUARE_OPEN then
30
return indexer_parser.parse(context);
31
elif context.current.token == Lexical.TOKEN.AT then
32
return pragma_parser.parse(context);
33
elif context.current.token == Lexical.TOKEN.SUPER then
34
return super_call_parser.parse(context);
35
fi
36
37
let use tokenizer_snapshot = context.tokenizer_speculate_then_commit();
38
39
context.next_token();
40
41
if property_tokens |> any(t => t == context.current.token) then
42
tokenizer_snapshot.backtrack();
43
44
return property_parser.parse(context);
45
elif
46
context.current.token == Lexical.TOKEN.SQUARE_OPEN \/
47
context.current.token == Lexical.TOKEN.PAREN_OPEN
48
then
49
tokenizer_snapshot.backtrack();
50
51
return function_parser.parse(context);
52
fi
53
54
tokenizer_snapshot.commit();
55
56
return other_token(context);
57
si
58
si
59
si