MCPcopy Create free account
hub / github.com/apache/fory / parse_union_field

Method parse_union_field

compiler/fory_compiler/frontend/fdl/parser.py:568–603  ·  view source on GitHub ↗

Parse a union case: Type name = 1;

(self)

Source from the content-addressed store, hash-verified

566 )
567
568 def parse_union_field(self) -> Field:
569 """Parse a union case: Type name = 1;"""
570 start = self.current()
571
572 if self.check(TokenType.OPTIONAL) or self.check(TokenType.REF):
573 raise self.error("Union cases do not support optional/ref modifiers")
574
575 repeated = False
576 if self.check(TokenType.REPEATED):
577 self.advance()
578 repeated = True
579
580 field_type = self.parse_type()
581 if repeated:
582 field_type = ListType(field_type, location=self.make_location(start))
583 name = self.consume(TokenType.IDENT, "Expected union case name").value
584 self.consume(TokenType.EQUALS, "Expected '=' after union case name")
585 number_token = self.consume(TokenType.INT, "Expected union case id")
586 number = int(number_token.value)
587
588 field_options = {}
589 if self.check(TokenType.LBRACKET):
590 field_options = self.parse_field_options(name)
591
592 self.consume(TokenType.SEMI, "Expected ';' after union case")
593
594 return Field(
595 name=name,
596 field_type=field_type,
597 number=number,
598 tag_id=number,
599 options=field_options,
600 line=start.line,
601 column=start.column,
602 location=self.make_location(start),
603 )
604
605 def parse_field(self) -> Field:
606 """Parse a field: optional ref repeated Type name = 1 [options];

Callers 1

parse_unionMethod · 0.95

Calls 10

currentMethod · 0.95
checkMethod · 0.95
errorMethod · 0.95
advanceMethod · 0.95
parse_typeMethod · 0.95
make_locationMethod · 0.95
consumeMethod · 0.95
parse_field_optionsMethod · 0.95
ListTypeClass · 0.90
FieldClass · 0.90

Tested by

no test coverage detected