Parses a global statement. # Panics If the parser isn't positioned at a `global` token. See:
(&mut self)
| 972 | /// |
| 973 | /// See: <https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-global_stmt> |
| 974 | fn parse_global_statement(&mut self) -> ast::StmtGlobal { |
| 975 | let start = self.node_start(); |
| 976 | self.bump(TokenKind::Global); |
| 977 | |
| 978 | // test_err global_stmt_trailing_comma |
| 979 | // global , |
| 980 | // global x, |
| 981 | // global x, y, |
| 982 | |
| 983 | // test_err global_stmt_expression |
| 984 | // global x + 1 |
| 985 | let names = self.parse_comma_separated_list_into_vec( |
| 986 | RecoveryContextKind::Identifiers, |
| 987 | Parser::parse_identifier, |
| 988 | ); |
| 989 | |
| 990 | if names.is_empty() { |
| 991 | // test_err global_stmt_empty |
| 992 | // global |
| 993 | self.add_error(ParseErrorType::EmptyGlobalNames, self.current_token_range()); |
| 994 | } |
| 995 | |
| 996 | // test_ok global_stmt |
| 997 | // global x |
| 998 | // global x, y, z |
| 999 | ast::StmtGlobal { |
| 1000 | range: self.node_range(start), |
| 1001 | names, |
| 1002 | node_index: AtomicNodeIndex::NONE, |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | /// Parses a nonlocal statement. |
| 1007 | /// |
no test coverage detected