@@ -66,7 +66,8 @@ static PATTERN_LEXER: LazyLock<Regex> = LazyLock::new(|| {
66
66
#[ cfg( windows) ]
67
67
{
68
68
// 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 ( )
70
71
}
71
72
#[ cfg( not( windows) ) ]
72
73
{
@@ -206,6 +207,15 @@ mod tests {
206
207
assert_eq ! ( tokens[ 1 ] . kind, SyntaxKind :: Tab ) ;
207
208
}
208
209
210
+ #[ test]
211
+ #[ cfg( windows) ]
212
+ fn test_carriage_return ( ) {
213
+ let input = "select\r \n \r 1" ;
214
+ let tokens = lex ( input) . unwrap ( ) ;
215
+ assert_eq ! ( tokens[ 1 ] . kind, SyntaxKind :: Newline ) ;
216
+ assert_eq ! ( tokens[ 2 ] . kind, SyntaxKind :: Whitespace ) ;
217
+ }
218
+
209
219
#[ test]
210
220
fn test_newline_tokens ( ) {
211
221
let input = "select\n 1" ;
@@ -217,7 +227,7 @@ mod tests {
217
227
fn test_consecutive_newlines ( ) {
218
228
// Test with multiple consecutive newlines
219
229
#[ cfg( windows) ]
220
- let input = "select\r \n \r \n 1 " ;
230
+ let input = "select\r \n \r \n \r 1 " ;
221
231
#[ cfg( not( windows) ) ]
222
232
let input = "select\n \n 1" ;
223
233
@@ -226,6 +236,7 @@ mod tests {
226
236
// Check that we have exactly one newline token between "select" and "1"
227
237
assert_eq ! ( tokens[ 0 ] . kind, SyntaxKind :: Select ) ;
228
238
assert_eq ! ( tokens[ 1 ] . kind, SyntaxKind :: Newline ) ;
239
+ assert_eq ! ( tokens[ 1 ] . kind, SyntaxKind :: Whitespace ) ;
229
240
assert_eq ! ( tokens[ 2 ] . kind, SyntaxKind :: Iconst ) ;
230
241
}
231
242
0 commit comments