@@ -61,8 +61,18 @@ pub static WHITESPACE_TOKENS: &[SyntaxKind] = &[
61
61
SyntaxKind :: SqlComment ,
62
62
] ;
63
63
64
- static PATTERN_LEXER : LazyLock < Regex > =
65
- LazyLock :: new ( || Regex :: new ( r"(?P<whitespace> +)|(?P<newline>\r?\n+)|(?P<tab>\t+)" ) . unwrap ( ) ) ;
64
+ static PATTERN_LEXER : LazyLock < Regex > = LazyLock :: new ( || {
65
+ #[ cfg( windows) ]
66
+ {
67
+ // On Windows, treat \r\n as a single newline token
68
+ Regex :: new ( r"(?P<whitespace> +)|(?P<newline>(\r\n|\n)+)|(?P<tab>\t+)" ) . unwrap ( )
69
+ }
70
+ #[ cfg( not( windows) ) ]
71
+ {
72
+ // On other platforms, just check for \n
73
+ Regex :: new ( r"(?P<whitespace> +)|(?P<newline>\n+)|(?P<tab>\t+)" ) . unwrap ( )
74
+ }
75
+ } ) ;
66
76
67
77
fn whitespace_tokens ( input : & str ) -> VecDeque < Token > {
68
78
let mut tokens = VecDeque :: new ( ) ;
@@ -202,6 +212,22 @@ mod tests {
202
212
assert_eq ! ( tokens[ 1 ] . kind, SyntaxKind :: Newline ) ;
203
213
}
204
214
215
+ #[ test]
216
+ fn test_consecutive_newlines ( ) {
217
+ // Test with multiple consecutive newlines
218
+ #[ cfg( windows) ]
219
+ let input = "select\r \n \r \n 1" ;
220
+ #[ cfg( not( windows) ) ]
221
+ let input = "select\n \n 1" ;
222
+
223
+ let tokens = lex ( input) . unwrap ( ) ;
224
+
225
+ // Check that we have exactly one newline token between "select" and "1"
226
+ assert_eq ! ( tokens[ 0 ] . kind, SyntaxKind :: Select ) ;
227
+ assert_eq ! ( tokens[ 1 ] . kind, SyntaxKind :: Newline ) ;
228
+ assert_eq ! ( tokens[ 2 ] . kind, SyntaxKind :: Iconst ) ;
229
+ }
230
+
205
231
#[ test]
206
232
fn test_whitespace_tokens ( ) {
207
233
let input = "select 1" ;
0 commit comments