Parses a list of elements where each element is parsed using the given `parse_element` function.
(
&mut self,
recovery_context_kind: RecoveryContextKind,
mut parse_element: impl FnMut(&mut Parser<'src>),
)
| 686 | /// Parses a list of elements where each element is parsed using the given |
| 687 | /// `parse_element` function. |
| 688 | fn parse_list( |
| 689 | &mut self, |
| 690 | recovery_context_kind: RecoveryContextKind, |
| 691 | mut parse_element: impl FnMut(&mut Parser<'src>), |
| 692 | ) { |
| 693 | let mut progress = ParserProgress::default(); |
| 694 | |
| 695 | let saved_context = self.recovery_context; |
| 696 | self.recovery_context = self |
| 697 | .recovery_context |
| 698 | .union(RecoveryContext::from_kind(recovery_context_kind)); |
| 699 | |
| 700 | loop { |
| 701 | progress.assert_progressing(self); |
| 702 | |
| 703 | if recovery_context_kind.is_list_element(self) { |
| 704 | parse_element(self); |
| 705 | } else if recovery_context_kind.is_regular_list_terminator(self) { |
| 706 | break; |
| 707 | } else { |
| 708 | // Run the error recovery: If the token is recognised as an element or terminator |
| 709 | // of an enclosing list, then we try to re-lex in the context of a logical line and |
| 710 | // break out of list parsing. |
| 711 | if self.is_enclosing_list_element_or_terminator() { |
| 712 | self.tokens.re_lex_logical_token(); |
| 713 | break; |
| 714 | } |
| 715 | |
| 716 | self.add_error( |
| 717 | recovery_context_kind.create_error(self), |
| 718 | self.current_token_range(), |
| 719 | ); |
| 720 | |
| 721 | self.bump_any(); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | self.recovery_context = saved_context; |
| 726 | } |
| 727 | |
| 728 | /// Parses a comma separated list of elements into a vector where each element |
| 729 | /// is parsed using the given `parse_element` function. |
no test coverage detected