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>),
)
| 731 | /// Parses a list of elements where each element is parsed using the given |
| 732 | /// `parse_element` function. |
| 733 | fn parse_list( |
| 734 | &mut self, |
| 735 | recovery_context_kind: RecoveryContextKind, |
| 736 | mut parse_element: impl FnMut(&mut Parser<'src>), |
| 737 | ) { |
| 738 | let mut progress = ParserProgress::default(); |
| 739 | |
| 740 | let saved_context = self.recovery_context; |
| 741 | self.recovery_context = self |
| 742 | .recovery_context |
| 743 | .union(RecoveryContext::from_kind(recovery_context_kind)); |
| 744 | |
| 745 | loop { |
| 746 | progress.assert_progressing(self); |
| 747 | |
| 748 | if recovery_context_kind.is_list_element(self) { |
| 749 | parse_element(self); |
| 750 | } else if recovery_context_kind.is_regular_list_terminator(self) { |
| 751 | break; |
| 752 | } else { |
| 753 | // Run the error recovery: If the token is recognised as an element or terminator |
| 754 | // of an enclosing list, then we try to re-lex in the context of a logical line and |
| 755 | // break out of list parsing. |
| 756 | if self.is_enclosing_list_element_or_terminator() { |
| 757 | self.tokens.re_lex_logical_token(); |
| 758 | break; |
| 759 | } |
| 760 | |
| 761 | self.add_error( |
| 762 | recovery_context_kind.create_error(self), |
| 763 | self.current_token_range(), |
| 764 | ); |
| 765 | |
| 766 | self.bump_any(); |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | self.recovery_context = saved_context; |
| 771 | } |
| 772 | |
| 773 | /// Parses a comma separated list of elements into a vector where each element |
| 774 | /// is parsed using the given `parse_element` function. |
no test coverage detected