Appearance
| 1 | namespace Syntax.Parsers.Definitions is | |
| 2 | // Recovery for a type header that has no `is` where its body should | |
| 3 | // start: looks for the `is` further along the header's line, or at the | |
| 4 | // start of the next line, and consumes it if found, so the body that | |
| 5 | // follows is parsed as this type's rather than as definitions of its own. | |
| 6 | // | |
| 7 | // At the end of the file the tokenizer keeps returning the end-of-input | |
| 8 | // token at the same location, so the scan has to stop there explicitly | |
| 9 | // or it never leaves the header's line. | |
| 10 | class BODY_LOOKAHEAD is | |
| 11 | find_is(context: CONTEXT) -> bool static is | |
| 12 | let line = context.current.location.start_line | |
| 13 | ||
| 14 | let use diagnostics_snapshot = context.diagnostics_speculate_then_backtrack() | |
| 15 | ||
| 16 | while | |
| 17 | context.current.token != Lexical.TOKEN.END_OF_INPUT /\ | |
| 18 | context.current.location.start_line == line /\ | |
| 19 | context.current.location.start_column >= context.global_indent | |
| 20 | do | |
| 21 | if context.current.token == Lexical.TOKEN.IS then | |
| 22 | diagnostics_snapshot.commit() | |
| 23 | context.next_token() | |
| 24 | ||
| 25 | return true | |
| 26 | fi | |
| 27 | ||
| 28 | context.next_token() | |
| 29 | od | |
| 30 | ||
| 31 | if context.current_token == Lexical.TOKEN.IS /\ context.current.location.start_column >= context.global_indent then | |
| 32 | diagnostics_snapshot.commit() | |
| 33 | context.next_token() | |
| 34 | ||
| 35 | return true | |
| 36 | fi | |
| 37 | ||
| 38 | return false | |
| 39 | si | |
| 40 | si | |
| 41 | si |