Parses an `elif` or `else` clause. # Panics If the parser isn't positioned at an `elif` or `else` token.
(&mut self, kind: ElifOrElse)
| 1485 | /// |
| 1486 | /// If the parser isn't positioned at an `elif` or `else` token. |
| 1487 | fn parse_elif_or_else_clause(&mut self, kind: ElifOrElse) -> ast::ElifElseClause { |
| 1488 | let start = self.node_start(); |
| 1489 | self.bump(kind.as_token_kind()); |
| 1490 | |
| 1491 | let test = if kind.is_elif() { |
| 1492 | // test_err if_stmt_invalid_elif_test_expr |
| 1493 | // if x: |
| 1494 | // pass |
| 1495 | // elif *x: |
| 1496 | // pass |
| 1497 | // elif yield x: |
| 1498 | // pass |
| 1499 | Some( |
| 1500 | self.parse_named_expression_or_higher(ExpressionContext::default()) |
| 1501 | .expr, |
| 1502 | ) |
| 1503 | } else { |
| 1504 | None |
| 1505 | }; |
| 1506 | |
| 1507 | // test_err if_stmt_elif_missing_colon |
| 1508 | // if x: |
| 1509 | // pass |
| 1510 | // elif y |
| 1511 | // pass |
| 1512 | // else: |
| 1513 | // pass |
| 1514 | self.expect(TokenKind::Colon); |
| 1515 | |
| 1516 | let body = self.parse_body(kind.as_clause()); |
| 1517 | |
| 1518 | ast::ElifElseClause { |
| 1519 | test, |
| 1520 | body, |
| 1521 | range: self.node_range(start), |
| 1522 | node_index: AtomicNodeIndex::NONE, |
| 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | /// Parses a `try` statement. |
| 1527 | /// |
no test coverage detected