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)
| 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), |
no test coverage detected