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

Method classify_match_token

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

Classify the `match` soft keyword token. # Panics If the parser isn't positioned at a `match` token.

(&mut self)

Source from the content-addressed store, hash-verified

3912 ///
3913 /// If the parser isn't positioned at a `match` token.
3914 fn classify_match_token(&mut self) -> MatchTokenKind {
3915 assert_eq!(self.current_token_kind(), TokenKind::Match);
3916
3917 let (first, second) = self.peek2();
3918
3919 match first {
3920 // test_ok match_classify_as_identifier_1
3921 // match not in case
3922 TokenKind::Not if second == TokenKind::In => MatchTokenKind::Identifier,
3923
3924 // test_ok match_classify_as_keyword_1
3925 // match foo:
3926 // case _: ...
3927 // match 1:
3928 // case _: ...
3929 // match 1.0:
3930 // case _: ...
3931 // match 1j:
3932 // case _: ...
3933 // match "foo":
3934 // case _: ...
3935 // match f"foo {x}":
3936 // case _: ...
3937 // match {1, 2}:
3938 // case _: ...
3939 // match ~foo:
3940 // case _: ...
3941 // match ...:
3942 // case _: ...
3943 // match not foo:
3944 // case _: ...
3945 // match await foo():
3946 // case _: ...
3947 // match lambda foo: foo:
3948 // case _: ...
3949
3950 // test_err match_classify_as_keyword
3951 // match yield foo:
3952 // case _: ...
3953 TokenKind::Identifier
3954 | TokenKind::Int
3955 | TokenKind::Float
3956 | TokenKind::Complex
3957 | TokenKind::String
3958 | TokenKind::FStringStart
3959 | TokenKind::TStringStart
3960 | TokenKind::Lbrace
3961 | TokenKind::Tilde
3962 | TokenKind::Ellipsis
3963 | TokenKind::Not
3964 | TokenKind::Await
3965 | TokenKind::Yield
3966 | TokenKind::Lambda => MatchTokenKind::Keyword,
3967
3968 // test_ok match_classify_as_keyword_or_identifier
3969 // match (1, 2) # Identifier
3970 // match (1, 2): # Keyword
3971 // case _: ...

Callers 1

parse_statementMethod · 0.80

Calls 3

is_soft_keywordMethod · 0.80
peek2Method · 0.45
is_singletonMethod · 0.45

Tested by

no test coverage detected