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

Method parse_with_statement

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

Parses a `with` statement The given `start` offset is the start of either the `with` token or the `async` token if it's an async with statement. # Panics If the parser isn't positioned at a `with` token. See:

(&mut self, start: TextSize)

Source from the content-addressed store, hash-verified

2196 ///
2197 /// See: <https://docs.python.org/3/reference/compound_stmts.html#the-with-statement>
2198 fn parse_with_statement(&mut self, start: TextSize) -> ast::StmtWith {
2199 self.bump(TokenKind::With);
2200
2201 let mut items = self.parse_with_items();
2202 items.shrink_to_fit();
2203
2204 self.expect(TokenKind::Colon);
2205
2206 let body = self.parse_body(Clause::With);
2207
2208 ast::StmtWith {
2209 items,
2210 body,
2211 is_async: false,
2212 range: self.node_range(start),
2213 node_index: AtomicNodeIndex::NONE,
2214 }
2215 }
2216
2217 /// Parses a list of with items.
2218 ///

Callers 2

parse_statementMethod · 0.80
parse_async_statementMethod · 0.80

Calls 6

parse_with_itemsMethod · 0.80
expectMethod · 0.80
parse_bodyMethod · 0.80
node_rangeMethod · 0.80
bumpMethod · 0.45
shrink_to_fitMethod · 0.45

Tested by

no test coverage detected