Parses a statement that is valid after an `async` token. If the statement is not a valid `async` statement, an error will be reported and it will be parsed as a statement. See: - - - <https://docs.python.org/3/reference/compound_stmt
(&mut self)
| 2872 | /// - <https://docs.python.org/3/reference/compound_stmts.html#the-async-for-statement> |
| 2873 | /// - <https://docs.python.org/3/reference/compound_stmts.html#coroutine-function-definition> |
| 2874 | fn parse_async_statement(&mut self) -> Stmt { |
| 2875 | let async_start = self.node_start(); |
| 2876 | self.bump(TokenKind::Async); |
| 2877 | |
| 2878 | match self.current_token_kind() { |
| 2879 | // test_ok async_function_definition |
| 2880 | // async def foo(): ... |
| 2881 | TokenKind::Def => Stmt::FunctionDef(ast::StmtFunctionDef { |
| 2882 | is_async: true, |
| 2883 | ..self.parse_function_definition(DecoratorList::new(), async_start) |
| 2884 | }), |
| 2885 | |
| 2886 | // test_ok async_with_statement |
| 2887 | // async with item: ... |
| 2888 | TokenKind::With => Stmt::With(ast::StmtWith { |
| 2889 | is_async: true, |
| 2890 | ..self.parse_with_statement(async_start) |
| 2891 | }), |
| 2892 | |
| 2893 | // test_ok async_for_statement |
| 2894 | // async for target in iter: ... |
| 2895 | TokenKind::For => Stmt::For(ast::StmtFor { |
| 2896 | is_async: true, |
| 2897 | ..self.parse_for_statement(async_start) |
| 2898 | }), |
| 2899 | |
| 2900 | kind => { |
| 2901 | // test_err async_unexpected_token |
| 2902 | // async class Foo: ... |
| 2903 | // async while test: ... |
| 2904 | // async x = 1 |
| 2905 | // async async def foo(): ... |
| 2906 | // async match test: |
| 2907 | // case _: ... |
| 2908 | self.add_error( |
| 2909 | ParseErrorType::UnexpectedTokenAfterAsync(kind), |
| 2910 | self.current_token_range(), |
| 2911 | ); |
| 2912 | |
| 2913 | // Although this statement is not a valid `async` statement, |
| 2914 | // we still parse it. Guard the recursive recovery path so |
| 2915 | // `async async async ...` cannot overflow the parser stack. |
| 2916 | self.with_recursion(Self::parse_statement) |
| 2917 | } |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | /// Parses a decorator list followed by a class, function or async function definition. |
| 2922 | /// |
no test coverage detected