iffyio commented on code in PR #2186:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2186#discussion_r2755023736
##########
src/dialect/mssql.rs:
##########
@@ -145,7 +145,22 @@ impl Dialect for MsSqlDialect {
}
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement,
ParserError>> {
- if parser.peek_keyword(Keyword::IF) {
+ if parser.parse_keyword(Keyword::BEGIN) {
+ if parser.peek_keyword(Keyword::TRANSACTION)
+ || parser.peek_keyword(Keyword::WORK)
+ || parser.peek_keyword(Keyword::TRY)
+ || parser.peek_keyword(Keyword::CATCH)
+ || parser.peek_keyword(Keyword::DEFERRED)
+ || parser.peek_keyword(Keyword::IMMEDIATE)
+ || parser.peek_keyword(Keyword::EXCLUSIVE)
+ || parser.peek_token_ref().token == Token::SemiColon
+ || parser.peek_token_ref().token == Token::EOF
+ {
+ parser.prev_token();
+ return None;
+ }
+ Some(parser.parse_begin_exception_end())
Review Comment:
Oh I see, that makes sense! Can we do something like this to clarify the
code?
we pull out the [linked fallback
logic](https://github.com/apache/datafusion-sqlparser-rs/blob/c8b7f7cf4281cdfff3e08e9827928662b8be8095/src/parser/mod.rs#L17930-L17944)
into a function `parse_transaction_modifier()`. So that it can be reused.
Then here we can do e.g.
```rust
if without_modifier = self.maybe_parse(|parser| {
if parser.parse_transaction_modifier()?.is_some() {
parser_error!()
} else {
Some(())
}
})?.is_some();
```
such that with that bool we know whether to defer to the main parser logic
or continue with the begin/exception logic
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]