Appearance
| 1 | namespace Syntax.Parsers.Definitions is | |
| 2 | use System.Exception; | |
| 3 | use IO.Std; | |
| 4 | ||
| 5 | use Source; | |
| 6 | ||
| 7 | class MEMBER_LIST(definition_parser: Parser[Trees.Definitions.Definition]): Base[Trees.Definitions.LIST] is | |
| 8 | description: string => "definition list"; | |
| 9 | ||
| 10 | super(); | |
| 11 | ||
| 12 | parse(context: CONTEXT) -> Trees.Definitions.LIST is | |
| 13 | let start = context.location; | |
| 14 | let end mut = context.location; | |
| 15 | let definitions = Collections.LIST[Trees.Definitions.Definition](); | |
| 16 | ||
| 17 | while !context.is_end_of_file /\ context.current.token != Lexical.TOKEN.SI do | |
| 18 | try | |
| 19 | let definition = definition_parser.parse(context); | |
| 20 | ||
| 21 | if definition? then | |
| 22 | end = definition.location; | |
| 23 | ||
| 24 | definitions.add(definition); | |
| 25 | fi | |
| 26 | catch ue: UNWIND_TO_MEMBER_EXCEPTION | |
| 27 | // carry on from here | |
| 28 | ||
| 29 | catch ubp: UNWIND_BAD_PROPERTY_EXCEPTION | |
| 30 | break; | |
| 31 | ||
| 32 | catch e: Exception | |
| 33 | IoC.CONTAINER.instance.logger.exception(context.current.location, e, "parse exception: {e.message}"); | |
| 34 | ||
| 35 | // TODO: better recovery here - can we use indentation? | |
| 36 | while | |
| 37 | !context.is_end_of_file /\ | |
| 38 | context.current.token != Lexical.TOKEN.SI /\ | |
| 39 | context.current.token != Lexical.TOKEN.SEMICOLON | |
| 40 | do | |
| 41 | context.next_token(); | |
| 42 | od | |
| 43 | ||
| 44 | if context.is_end_of_file then | |
| 45 | break; | |
| 46 | fi | |
| 47 | yrt | |
| 48 | od | |
| 49 | ||
| 50 | return Trees.Definitions.LIST(start::end, definitions); | |
| 51 | si | |
| 52 | si | |
| 53 | si |