Parses a `while` statement. # Panics If the parser isn't positioned at a `while` token. See:
(&mut self)
| 1940 | /// |
| 1941 | /// See: <https://docs.python.org/3/reference/compound_stmts.html#the-while-statement> |
| 1942 | fn parse_while_statement(&mut self) -> ast::StmtWhile { |
| 1943 | let start = self.node_start(); |
| 1944 | self.bump(TokenKind::While); |
| 1945 | |
| 1946 | // test_err while_stmt_missing_test |
| 1947 | // while : ... |
| 1948 | // while : |
| 1949 | // a = 1 |
| 1950 | |
| 1951 | // test_err while_stmt_invalid_test_expr |
| 1952 | // while *x: ... |
| 1953 | // while yield x: ... |
| 1954 | // while a, b: ... |
| 1955 | // while a := 1, b: ... |
| 1956 | let test = self.parse_named_expression_or_higher(ExpressionContext::default()); |
| 1957 | |
| 1958 | // test_err while_stmt_missing_colon |
| 1959 | // while ( |
| 1960 | // a < 30 # comment |
| 1961 | // ) |
| 1962 | // pass |
| 1963 | self.expect(TokenKind::Colon); |
| 1964 | |
| 1965 | let body = self.parse_body(Clause::While); |
| 1966 | |
| 1967 | let orelse = if self.eat(TokenKind::Else) { |
| 1968 | self.expect(TokenKind::Colon); |
| 1969 | self.parse_body(Clause::Else) |
| 1970 | } else { |
| 1971 | Suite::new() |
| 1972 | }; |
| 1973 | |
| 1974 | ast::StmtWhile { |
| 1975 | test: Box::new(test.expr), |
| 1976 | body, |
| 1977 | orelse, |
| 1978 | range: self.node_range(start), |
| 1979 | node_index: AtomicNodeIndex::NONE, |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | /// Parses a function definition. |
| 1984 | /// |
no test coverage detected