From fbba44312fa053832a4c9b77547bffdc6a9d9b26 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Wed, 26 Oct 2022 14:46:13 +0000 Subject: [PATCH] fix(lexer): fix inproper handling of `\\\n` Before it would escape the newline resulting in passing it as an argument. Signed-off-by: Charlotte Meyer --- crates/oyster_parser/src/lexer.rs | 8 ++++---- crates/oyster_parser/tests/it/lexer.rs | 9 +++++++++ .../tests/it/snapshots/it__lexer__escape_newline.snap | 8 ++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 crates/oyster_parser/tests/it/snapshots/it__lexer__escape_newline.snap diff --git a/crates/oyster_parser/src/lexer.rs b/crates/oyster_parser/src/lexer.rs index f73993e..36f8154 100644 --- a/crates/oyster_parser/src/lexer.rs +++ b/crates/oyster_parser/src/lexer.rs @@ -125,10 +125,10 @@ impl Lexer<'_> { TokenKind::Comment } - '\\' => { - self.next_char(); - TokenKind::EscapedChar - } + '\\' => match self.next_char() { + Some('\n') => TokenKind::Whitespace, + _ => TokenKind::EscapedChar, + }, _ => { self.eat_while(|c| { diff --git a/crates/oyster_parser/tests/it/lexer.rs b/crates/oyster_parser/tests/it/lexer.rs index 6c43425..92a2368 100644 --- a/crates/oyster_parser/tests/it/lexer.rs +++ b/crates/oyster_parser/tests/it/lexer.rs @@ -144,3 +144,12 @@ fn closing_parenthesis_string_mode() { assert_snapshot!(actual); } + +#[test] +fn escape_newline() { + let source = "\\\n"; + + let actual = Lexer::new(source).next_command_token(); + + assert_snapshot!(actual); +} diff --git a/crates/oyster_parser/tests/it/snapshots/it__lexer__escape_newline.snap b/crates/oyster_parser/tests/it/snapshots/it__lexer__escape_newline.snap new file mode 100644 index 0000000..1fb4ba0 --- /dev/null +++ b/crates/oyster_parser/tests/it/snapshots/it__lexer__escape_newline.snap @@ -0,0 +1,8 @@ +--- +source: crates/oyster_parser/tests/it/lexer.rs +expression: actual +--- +Token { + kind: Whitespace, + len: 2, +}