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

Method parse_if_expression

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

Parses an `if` expression. # Panics If the parser isn't positioned at an `if` token. See:

(&mut self, body: Expr, start: TextSize)

Source from the content-addressed store, hash-verified

2933 ///
2934 /// See: <https://docs.python.org/3/reference/expressions.html#conditional-expressions>
2935 fn parse_if_expression(&mut self, body: Expr, start: TextSize) -> ast::ExprIf {
2936 self.bump(TokenKind::If);
2937
2938 let test = self.parse_simple_expression(ExpressionContext::default());
2939
2940 self.expect(TokenKind::Else);
2941
2942 // The binary-expression guard has already returned before parsing the `else` branch.
2943 let orelse = self.with_recursion(Self::parse_conditional_expression_or_higher);
2944
2945 ast::ExprIf {
2946 body: Box::new(body),
2947 test: Box::new(test.expr),
2948 orelse: Box::new(orelse.expr),
2949 range: self.node_range(start),
2950 node_index: AtomicNodeIndex::NONE,
2951 }
2952 }
2953
2954 /// Parses an IPython escape command at the expression level.
2955 ///

Calls 6

expectMethod · 0.80
with_recursionMethod · 0.80
node_rangeMethod · 0.80
defaultFunction · 0.50
bumpMethod · 0.45

Tested by

no test coverage detected