MCPcopy Create free account
hub / github.com/astral-sh/ruff / parse_global_statement

Method parse_global_statement

crates/ruff_python_parser/src/parser/statement.rs:974–1004  ·  view source on GitHub ↗

Parses a global statement. # Panics If the parser isn't positioned at a `global` token. See:

(&mut self)

Source from the content-addressed store, hash-verified

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 ///

Callers 1

Calls 7

node_startMethod · 0.80
current_token_rangeMethod · 0.80
node_rangeMethod · 0.80
bumpMethod · 0.45
is_emptyMethod · 0.45
add_errorMethod · 0.45

Tested by

no test coverage detected