Parses an `if` expression. # Panics If the parser isn't positioned at an `if` token. See:
(&mut self, body: Expr, start: TextSize)
| 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 | /// |
no test coverage detected