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

Method parse_list

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

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.

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