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

Method parse_generators

crates/ruff_python_parser/src/parser/expression.rs:2610–2624  ·  view source on GitHub ↗

Parses a list of comprehension generators. These are the `for` and `async for` clauses in a comprehension, optionally followed by `if` clauses. See:

(&mut self)

Source from the content-addressed store, hash-verified

2608 ///
2609 /// See: <https://docs.python.org/3/reference/expressions.html#grammar-token-python-grammar-comp_for>
2610 fn parse_generators(&mut self) -> Vec<ast::Comprehension> {
2611 const GENERATOR_SET: TokenSet = TokenSet::new([TokenKind::For, TokenKind::Async]);
2612
2613 let mut generators = Vec::with_capacity(1);
2614 let mut progress = ParserProgress::default();
2615
2616 while self.at_ts(GENERATOR_SET) {
2617 progress.assert_progressing(self);
2618 generators.push(self.parse_comprehension());
2619 }
2620
2621 generators.shrink_to_fit();
2622
2623 generators
2624 }
2625
2626 /// Parses a comprehension.
2627 ///

Calls 6

at_tsMethod · 0.80
assert_progressingMethod · 0.80
parse_comprehensionMethod · 0.80
defaultFunction · 0.50
pushMethod · 0.45
shrink_to_fitMethod · 0.45

Tested by

no test coverage detected