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:969–999  ·  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

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

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