romanb commented on PR #1791:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1791#issuecomment-2783825394

   > This is a great improvement! However, I noticed a difficulty with my code. 
This SQL fails to parse:
   > 
   > ```
   > declare @x bit = 1
   > 
   > if @x = 1
   > begin
   >   select 1
   > end
   > ```
   > 
   > It works if you add a semi-colon for the declare statement, though. Either 
syntax executes as expected in SQL Server directly.
   > 
   > What would it take to make it parse okay even without the semi-colon?
   
   To parse multiple top-level statements for MSSQL with optional semicolons, 
you can use the `Parser` API as follows:
   ```rust
   let mut stmts = Vec::new();
   loop {
       if let Token::EOF = parser.peek_token_ref().token {
           break;
       }
       stmts.push(parser.parse_statement()?);
       while let Token::SemiColon = parser.peek_token_ref().token {
           parser.advance_token();
       }
   }
   ```
   I also did it similarly in this PR when parsing the statements within 
`BEGIN` and `END` of a conditional for MSSQL. In contrast, 
`Parser#parse_statements()` always expects semicolon-separated statements.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to