MCPcopy Create free account
hub / github.com/astral-sh/ruff / parse_list

Method parse_list

crates/ruff_python_parser/src/parser/mod.rs:733–771  ·  view source on GitHub ↗

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>),
    )

Source from the content-addressed store, hash-verified

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.

Callers 4

parse_blockMethod · 0.80

Calls 11

assert_progressingMethod · 0.80
is_list_elementMethod · 0.80
create_errorMethod · 0.80
current_token_rangeMethod · 0.80
bump_anyMethod · 0.80
defaultFunction · 0.50
unionMethod · 0.45
re_lex_logical_tokenMethod · 0.45
add_errorMethod · 0.45

Tested by

no test coverage detected