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

Method parse_generators

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

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

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