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

Method parse_generators

crates/ruff_python_parser/src/parser/expression.rs:2539–2553  ·  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

2537 ///
2538 /// See: <https://docs.python.org/3/reference/expressions.html#grammar-token-python-grammar-comp_for>
2539 fn parse_generators(&mut self) -> Vec<ast::Comprehension> {
2540 const GENERATOR_SET: TokenSet = TokenSet::new([TokenKind::For, TokenKind::Async]);
2541
2542 let mut generators = Vec::with_capacity(1);
2543 let mut progress = ParserProgress::default();
2544
2545 while self.at_ts(GENERATOR_SET) {
2546 progress.assert_progressing(self);
2547 generators.push(self.parse_comprehension());
2548 }
2549
2550 generators.shrink_to_fit();
2551
2552 generators
2553 }
2554
2555 /// Parses a comprehension.
2556 ///

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