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

Method parse_field

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

Parse a field: optional ref repeated Type name = 1 [options]; Supports: - Keyword modifiers: optional ref repeated (repeated is an alias for list) - list type syntax for list fields - Bracket options: [deprecated=true, ref=true]

(self)

Source from the content-addressed store, hash-verified

603 )
604
605 def parse_field(self) -> Field:
606 """Parse a field: optional ref repeated Type name = 1 [options];
607
608 Supports:
609 - Keyword modifiers: optional ref repeated (repeated is an alias for list)
610 - list<T> type syntax for list fields
611 - Bracket options: [deprecated=true, ref=true]
612 """
613 start = self.current()
614
615 # Parse modifiers (optional/ref before repeated apply to the collection/field,
616 # optional/ref after repeated apply to elements).
617 optional = False
618 ref = False
619 ref_options = {}
620 element_optional = False
621 element_ref = False
622 element_ref_options = {}
623 repeated = False
624 while True:
625 if self.match(TokenType.OPTIONAL):
626 if repeated:
627 element_optional = True
628 else:
629 optional = True
630 continue
631 if self.match(TokenType.REF):
632 options = self.parse_ref_options(name="ref")
633 if repeated:
634 element_ref = True
635 element_ref_options = options
636 else:
637 ref = True
638 ref_options = options
639 continue
640 if self.check(TokenType.REPEATED):
641 if repeated:
642 raise self.error("Repeated modifier specified more than once")
643 self.advance()
644 repeated = True
645 continue
646 break
647
648 # Parse type
649 field_type = self.parse_type()
650 if not repeated and isinstance(field_type, ListType):
651 element_optional = field_type.element_optional
652 element_ref = field_type.element_ref
653 element_ref_options = field_type.element_ref_options
654
655 # Wrap in ListType if repeated
656 if repeated:
657 field_type = ListType(
658 field_type,
659 element_optional=element_optional,
660 element_ref=element_ref,
661 element_ref_options=element_ref_options,
662 location=self.make_location(start),

Callers 1

parse_messageMethod · 0.95

Calls 14

currentMethod · 0.95
matchMethod · 0.95
parse_ref_optionsMethod · 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
merge_ref_optionsMethod · 0.95
ListTypeClass · 0.90

Tested by

no test coverage detected