Parses a compound or a single simple statement. See: - -
(&mut self)
| 111 | /// - <https://docs.python.org/3/reference/compound_stmts.html> |
| 112 | /// - <https://docs.python.org/3/reference/simple_stmts.html> |
| 113 | pub(super) fn parse_statement(&mut self) -> Stmt { |
| 114 | let start = self.node_start(); |
| 115 | |
| 116 | match self.current_token_kind() { |
| 117 | TokenKind::If => Stmt::If(self.parse_if_statement()), |
| 118 | TokenKind::For => Stmt::For(self.parse_for_statement(start)), |
| 119 | TokenKind::While => Stmt::While(self.parse_while_statement()), |
| 120 | TokenKind::Def => { |
| 121 | Stmt::FunctionDef(self.parse_function_definition(DecoratorList::new(), start)) |
| 122 | } |
| 123 | TokenKind::Class => { |
| 124 | Stmt::ClassDef(self.parse_class_definition(DecoratorList::new(), start)) |
| 125 | } |
| 126 | TokenKind::Try => Stmt::Try(self.parse_try_statement()), |
| 127 | TokenKind::With => Stmt::With(self.parse_with_statement(start)), |
| 128 | TokenKind::At => self.parse_decorators(), |
| 129 | TokenKind::Async => self.parse_async_statement(), |
| 130 | token => { |
| 131 | if token == TokenKind::Match { |
| 132 | // Match is considered a soft keyword, so we will treat it as an identifier if |
| 133 | // it's followed by an unexpected token. |
| 134 | |
| 135 | match self.classify_match_token() { |
| 136 | MatchTokenKind::Keyword => { |
| 137 | return Stmt::Match(self.parse_match_statement()); |
| 138 | } |
| 139 | MatchTokenKind::KeywordOrIdentifier => { |
| 140 | if let Some(match_stmt) = self.try_parse_match_statement() { |
| 141 | return Stmt::Match(match_stmt); |
| 142 | } |
| 143 | } |
| 144 | MatchTokenKind::Identifier => {} |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | self.parse_single_simple_statement() |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /// Parses a single simple statement. |
| 154 | /// |
no test coverage detected