@@ -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 \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+
209219 #[ test]
210220 fn test_newline_tokens ( ) {
211221 let input = "select\n 1" ;
@@ -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 \n 1 " ;
230+ let input = "select\r \n \r \n \r 1 " ;
221231 #[ cfg( not( windows) ) ]
222232 let input = "select\n \n 1" ;
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