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 <dev@buffet.sh>
This commit is contained in:
buffet 2022-10-26 14:46:13 +00:00
parent aeb61873c1
commit fbba44312f
3 changed files with 21 additions and 4 deletions

View file

@ -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| {

View file

@ -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);
}

View file

@ -0,0 +1,8 @@
---
source: crates/oyster_parser/tests/it/lexer.rs
expression: actual
---
Token {
kind: Whitespace,
len: 2,
}