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:2209–2226  ·  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

2207 ///
2208 /// See: <https://docs.python.org/3/reference/compound_stmts.html#the-with-statement>
2209 fn parse_with_statement(&mut self, start: TextSize) -> ast::StmtWith {
2210 self.bump(TokenKind::With);
2211
2212 let mut items = self.parse_with_items();
2213 items.shrink_to_fit();
2214
2215 self.expect(TokenKind::Colon);
2216
2217 let body = self.parse_body(Clause::With);
2218
2219 ast::StmtWith {
2220 items,
2221 body,
2222 is_async: false,
2223 range: self.node_range(start),
2224 node_index: AtomicNodeIndex::NONE,
2225 }
2226 }
2227
2228 /// Parses a list of with items.
2229 ///

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