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

Method parse_clauses

crates/ruff_python_parser/src/parser/statement.rs:4050–4071  ·  view source on GitHub ↗

Parses a sequence of clauses. The parser only continues for as long as it sees the token indicating the start of the specific clause. Unlike [`Parser::parse_list`], this method does not perform error recovery when the next token is not a list terminator or the start of a list element. The special method is necessary because Python uses indentation over explicit delimiters to indicate the end of

(&mut self, clause: Clause, mut parse_clause: impl FnMut(&mut Parser<'src>))

Source from the content-addressed store, hash-verified

4048 /// `Else`) to the recovery context so that expression recovery stops when it encounters an
4049 /// `else` token.
4050 fn parse_clauses(&mut self, clause: Clause, mut parse_clause: impl FnMut(&mut Parser<'src>)) {
4051 let mut progress = ParserProgress::default();
4052
4053 let recovery_kind = match clause {
4054 Clause::ElIf => RecoveryContextKind::Elif,
4055 Clause::Except => RecoveryContextKind::Except,
4056 _ => unreachable!("Clause is not supported"),
4057 };
4058
4059 let saved_context = self.recovery_context;
4060 self.recovery_context = self
4061 .recovery_context
4062 .union(RecoveryContext::from_kind(recovery_kind));
4063
4064 while recovery_kind.is_list_element(self) {
4065 progress.assert_progressing(self);
4066
4067 parse_clause(self);
4068 }
4069
4070 self.recovery_context = saved_context;
4071 }
4072}
4073
4074#[derive(Copy, Clone)]

Callers 2

parse_if_statementMethod · 0.80
parse_try_statementMethod · 0.80

Calls 4

is_list_elementMethod · 0.80
assert_progressingMethod · 0.80
defaultFunction · 0.50
unionMethod · 0.45

Tested by

no test coverage detected