Skip to content

Commit

Permalink
fix: support escaped newlines within string literals (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
withered-magic authored Oct 18, 2024
1 parent e84dec9 commit 3e0f636
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/starpls_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,10 @@ impl Cursor<'_> {
return (true, triple_quoted);
}
}
'\\' if self.first() == '\\' || self.first() == closing_quote => {
'\\' if self.first() == '\\'
|| self.first() == closing_quote
|| self.first() == '\n' =>
{
// Bump again to skip the escaped character.
self.bump();
}
Expand Down
17 changes: 17 additions & 0 deletions crates/starpls_lexer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,3 +797,20 @@ foo(3 + \
"#]],
)
}

#[test]
fn test_escaped_newline_in_string() {
check_lexing(
r#"
greeting = "Hello, \
world!""#,
expect![[r#"
Token { kind: Newline, len: 1 }
Token { kind: Ident, len: 8 }
Token { kind: Whitespace, len: 1 }
Token { kind: Eq, len: 1 }
Token { kind: Whitespace, len: 1 }
Token { kind: Literal { kind: Str { terminated: true, triple_quoted: false } }, len: 17 }
"#]],
);
}

0 comments on commit 3e0f636

Please sign in to comment.