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