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

Method parse_list

crates/ruff_python_parser/src/parser/mod.rs:662–700  ·  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

660 /// Parses a list of elements where each element is parsed using the given
661 /// `parse_element` function.
662 fn parse_list(
663 &mut self,
664 recovery_context_kind: RecoveryContextKind,
665 mut parse_element: impl FnMut(&mut Parser<'src>),
666 ) {
667 let mut progress = ParserProgress::default();
668
669 let saved_context = self.recovery_context;
670 self.recovery_context = self
671 .recovery_context
672 .union(RecoveryContext::from_kind(recovery_context_kind));
673
674 loop {
675 progress.assert_progressing(self);
676
677 if recovery_context_kind.is_list_element(self) {
678 parse_element(self);
679 } else if recovery_context_kind.is_regular_list_terminator(self) {
680 break;
681 } else {
682 // Run the error recovery: If the token is recognised as an element or terminator
683 // of an enclosing list, then we try to re-lex in the context of a logical line and
684 // break out of list parsing.
685 if self.is_enclosing_list_element_or_terminator() {
686 self.tokens.re_lex_logical_token();
687 break;
688 }
689
690 self.add_error(
691 recovery_context_kind.create_error(self),
692 self.current_token_range(),
693 );
694
695 self.bump_any();
696 }
697 }
698
699 self.recovery_context = saved_context;
700 }
701
702 /// Parses a comma separated list of elements into a vector where each element
703 /// is parsed using the given `parse_element` function.

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