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 | context.in_generic_parameter_list = true | |
| 36 | arguments = type_list_parser.parse(context)! | |
| 37 | context.in_type_parameters = false | |
| 38 | context.in_generic_parameter_list = false | |
| 39 | arguments.check_no_reference_types(context.logger) | |
| 40 | ||
| 41 | is_poisoned = arguments.is_poisoned | |
| 42 | ||
| 43 | if | |
| 44 | !is_poisoned \/ | |
| 45 | context.current.token == Lexical.TOKEN.SQUARE_CLOSE | |
| 46 | then | |
| 47 | is_poisoned = !context.next_token(Lexical.TOKEN.SQUARE_CLOSE) \/ is_poisoned | |
| 48 | fi | |
| 49 | fi | |
| 50 | ||
| 51 | let modifiers = modifier_list_parser.parse(context)! | |
| 52 | ||
| 53 | let expect_body = !is_poisoned \/ context.current.token == Lexical.TOKEN.IS | |
| 54 | let have_body mut = false | |
| 55 | ||
| 56 | let body: Trees.Definitions.LIST mut | |
| 57 | ||
| 58 | if expect_body /\ context.next_token(Lexical.TOKEN.IS) then | |
| 59 | let use open = context.open_construct(Lexical.TOKEN.SI) | |
| 60 | ||
| 61 | body = definition_list_parser.parse(context)! | |
| 62 | have_body = true | |
| 63 | else | |
| 64 | body = Trees.Definitions.LIST(LOCATION.internal, Collections.LIST[Trees.Definitions.Definition](0)) | |
| 65 | is_poisoned = true | |
| 66 | fi | |
| 67 | ||
| 68 | let result = Trees.Definitions.PARTIAL( | |
| 69 | start::context.location, | |
| 70 | identifier, | |
| 71 | arguments, | |
| 72 | modifiers, | |
| 73 | body | |
| 74 | ) | |
| 75 | ||
| 76 | result.poison(is_poisoned) | |
| 77 | ||
| 78 | if have_body then | |
| 79 | context.expect_closer(Lexical.TOKEN.SI) | |
| 80 | fi | |
| 81 | ||
| 82 | return result | |
| 83 | finally | |
| 84 | context.in_classy = false | |
| 85 | yrt | |
| 86 | si | |
| 87 | si | |
| 88 | si |