Skip to content

Commit 23a43e6

Browse files
committed
fix(lexer): handle single
1 parent 51c301a commit 23a43e6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

crates/pgt_lexer/src/lib.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ static PATTERN_LEXER: LazyLock<Regex> = LazyLock::new(|| {
6666
#[cfg(windows)]
6767
{
6868
// On Windows, treat \r\n as a single newline token
69-
Regex::new(r"(?P<whitespace> +)|(?P<newline>(\r\n|\n)+)|(?P<tab>\t+)").unwrap()
69+
// and treat \r as a whitespace token
70+
Regex::new(r"(?P<whitespace> (+|\r))|(?P<newline>(\r\n|\n)+)|(?P<tab>\t+)").unwrap()
7071
}
7172
#[cfg(not(windows))]
7273
{
@@ -206,6 +207,15 @@ mod tests {
206207
assert_eq!(tokens[1].kind, SyntaxKind::Tab);
207208
}
208209

210+
#[test]
211+
#[cfg(windows)]
212+
fn test_carriage_return() {
213+
let input = "select\r\n\r1";
214+
let tokens = lex(input).unwrap();
215+
assert_eq!(tokens[1].kind, SyntaxKind::Newline);
216+
assert_eq!(tokens[2].kind, SyntaxKind::Whitespace);
217+
}
218+
209219
#[test]
210220
fn test_newline_tokens() {
211221
let input = "select\n1";
@@ -217,7 +227,7 @@ mod tests {
217227
fn test_consecutive_newlines() {
218228
// Test with multiple consecutive newlines
219229
#[cfg(windows)]
220-
let input = "select\r\n\r\n1";
230+
let input = "select\r\n\r\n\r1";
221231
#[cfg(not(windows))]
222232
let input = "select\n\n1";
223233

@@ -226,6 +236,7 @@ mod tests {
226236
// Check that we have exactly one newline token between "select" and "1"
227237
assert_eq!(tokens[0].kind, SyntaxKind::Select);
228238
assert_eq!(tokens[1].kind, SyntaxKind::Newline);
239+
assert_eq!(tokens[1].kind, SyntaxKind::Whitespace);
229240
assert_eq!(tokens[2].kind, SyntaxKind::Iconst);
230241
}
231242

0 commit comments

Comments
 (0)