diff --git a/crates/ruff_python_parser/src/lexer.rs b/crates/ruff_python_parser/src/lexer.rs index 2ce3d17c8e4498..3831bc28d0315f 100644 --- a/crates/ruff_python_parser/src/lexer.rs +++ b/crates/ruff_python_parser/src/lexer.rs @@ -2160,6 +2160,14 @@ f"{(lambda x:{x})}" assert_debug_snapshot!(lex_source(source)); } + #[test] + fn test_match_softkeyword_in_notebook() { + let source = r"match foo: + case bar: + pass"; + assert_debug_snapshot!(lex_jupyter_source(source)); + } + fn lex_fstring_error(source: &str) -> FStringErrorType { match lex(source, Mode::Module).find_map(std::result::Result::err) { Some(err) => match err.error { diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__match_softkeyword_in_notebook.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__match_softkeyword_in_notebook.snap new file mode 100644 index 00000000000000..0512714bd466a2 --- /dev/null +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__lexer__tests__match_softkeyword_in_notebook.snap @@ -0,0 +1,66 @@ +--- +source: crates/ruff_python_parser/src/lexer.rs +expression: lex_jupyter_source(source) +--- +[ + ( + Match, + 0..5, + ), + ( + Name { + name: "foo", + }, + 6..9, + ), + ( + Colon, + 9..10, + ), + ( + Newline, + 10..11, + ), + ( + Indent, + 11..15, + ), + ( + Case, + 15..19, + ), + ( + Name { + name: "bar", + }, + 20..23, + ), + ( + Colon, + 23..24, + ), + ( + Newline, + 24..25, + ), + ( + Indent, + 25..33, + ), + ( + Pass, + 33..37, + ), + ( + Newline, + 37..37, + ), + ( + Dedent, + 37..37, + ), + ( + Dedent, + 37..37, + ), +] diff --git a/crates/ruff_python_parser/src/soft_keywords.rs b/crates/ruff_python_parser/src/soft_keywords.rs index f7aab9c1137a6b..6d14dc7f37d72c 100644 --- a/crates/ruff_python_parser/src/soft_keywords.rs +++ b/crates/ruff_python_parser/src/soft_keywords.rs @@ -31,7 +31,7 @@ where pub fn new(lexer: I, mode: Mode) -> Self { Self { underlying: lexer.multipeek(), // spell-checker:ignore multipeek - start_of_line: matches!(mode, Mode::Module), + start_of_line: !matches!(mode, Mode::Expression), } } }