Appearance
| 1 | namespace Syntax.Parsers.Definitions is | |
| 2 | use Source; | |
| 3 | ||
| 4 | // partial <Type>[<params>] is <members> si | |
| 5 | // A supplementary member block for an already-declared type. No `:` | |
| 6 | // ancestors clause - interfaces stay in the target's own header. | |
| 7 | class PARTIAL( | |
| 8 | identifier_qualified_parser: Parser[Trees.Identifiers.Identifier], | |
| 9 | type_list_parser: Parser[Trees.TypeExpressions.LIST], | |
| 10 | modifier_list_parser: Parser[Trees.Modifiers.LIST], | |
| 11 | definition_list_parser: Parser[Trees.Definitions.LIST] | |
| 12 | ): Base[Trees.Definitions.PARTIAL] is | |
| 13 | super(); | |
| 14 | ||
| 15 | parse(context: CONTEXT) -> Trees.Definitions.PARTIAL? is | |
| 16 | let start = context.location; | |
| 17 | context.in_classy = true; | |
| 18 | context.global_indent = start.start_column; | |
| 19 | ||
| 20 | try | |
| 21 | context.next_token(Lexical.TOKEN.PARTIAL); | |
| 22 | let identifier = identifier_qualified_parser.parse(context); | |
| 23 | ||
| 24 | if !identifier? then | |
| 25 | return null; | |
| 26 | fi | |
| 27 | ||
| 28 | let is_poisoned mut = false; | |
| 29 | let arguments: Trees.TypeExpressions.LIST? mut = null; | |
| 30 | ||
| 31 | if context.current.token == Lexical.TOKEN.SQUARE_OPEN then | |
| 32 | context.next_token(); | |
| 33 | ||
| 34 | context.in_type_parameters = true; | |
| 35 | arguments = type_list_parser.parse(context)!; | |
| 36 | context.in_type_parameters = false; | |
| 37 | arguments.check_no_reference_types(context.logger); | |
| 38 | ||
| 39 | is_poisoned = arguments.is_poisoned; | |
| 40 | ||
| 41 | if | |
| 42 | !is_poisoned \/ | |
| 43 | context.current.token == Lexical.TOKEN.SQUARE_CLOSE | |
| 44 | then | |
| 45 | is_poisoned = !context.next_token(Lexical.TOKEN.SQUARE_CLOSE) \/ is_poisoned; | |
| 46 | fi | |
| 47 | fi | |
| 48 | ||
| 49 | let modifiers = modifier_list_parser.parse(context)!; | |
| 50 | ||
| 51 | let expect_body = !is_poisoned \/ context.current.token == Lexical.TOKEN.IS; | |
| 52 | let have_body mut = false; | |
| 53 | ||
| 54 | let body: Trees.Definitions.LIST mut; | |
| 55 | ||
| 56 | if expect_body /\ context.next_token(Lexical.TOKEN.IS) then | |
| 57 | body = definition_list_parser.parse(context)!; | |
| 58 | have_body = true; | |
| 59 | else | |
| 60 | body = Trees.Definitions.LIST(LOCATION.internal, Collections.LIST[Trees.Definitions.Definition](0)); | |
| 61 | is_poisoned = true; | |
| 62 | fi | |
| 63 | ||
| 64 | let result = Trees.Definitions.PARTIAL( | |
| 65 | start::context.location, | |
| 66 | identifier, | |
| 67 | arguments, | |
| 68 | modifiers, | |
| 69 | body | |
| 70 | ); | |
| 71 | ||
| 72 | result.poison(is_poisoned); | |
| 73 | ||
| 74 | if have_body then | |
| 75 | context.next_token(Lexical.TOKEN.SI); | |
| 76 | fi | |
| 77 | ||
| 78 | return result; | |
| 79 | finally | |
| 80 | context.in_classy = false; | |
| 81 | yrt | |
| 82 | si | |
| 83 | si | |
| 84 | si |