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