@@ -61,8 +61,18 @@ pub static WHITESPACE_TOKENS: &[SyntaxKind] = &[
6161 SyntaxKind :: SqlComment ,
6262] ;
6363
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+ } ) ;
6676
6777fn whitespace_tokens ( input : & str ) -> VecDeque < Token > {
6878 let mut tokens = VecDeque :: new ( ) ;
@@ -202,6 +212,22 @@ mod tests {
202212 assert_eq ! ( tokens[ 1 ] . kind, SyntaxKind :: Newline ) ;
203213 }
204214
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+
205231 #[ test]
206232 fn test_whitespace_tokens ( ) {
207233 let input = "select 1" ;
0 commit comments