iffyio commented on code in PR #1734:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/1734#discussion_r1966451757
##########
src/parser/mod.rs:
##########
@@ -5061,20 +5066,19 @@ impl<'a> Parser<'a> {
}
pub fn parse_trigger_period(&mut self) -> Result<TriggerPeriod,
ParserError> {
- Ok(
- match self.expect_one_of_keywords(&[
- Keyword::BEFORE,
- Keyword::AFTER,
- Keyword::INSTEAD,
- ])? {
- Keyword::BEFORE => TriggerPeriod::Before,
- Keyword::AFTER => TriggerPeriod::After,
- Keyword::INSTEAD => self
- .expect_keyword_is(Keyword::OF)
- .map(|_| TriggerPeriod::InsteadOf)?,
- _ => unreachable!(),
- },
- )
+ let allowed_keywords = if dialect_of!(self is MySqlDialect) {
+ vec![Keyword::BEFORE, Keyword::AFTER]
+ } else {
+ vec![Keyword::BEFORE, Keyword::AFTER, Keyword::INSTEAD]
+ };
Review Comment:
I think cleanest would be to leave as the previous version which parses the
`INSTEAD` keyword unconditionally, the parser doesn't strive to be exact in
terms of dialect support in order to keep things tractable, rather downstream
crates may further validate the syntax tree if necessary
##########
src/parser/mod.rs:
##########
@@ -4970,14 +4970,19 @@ impl<'a> Parser<'a> {
/// DROP TRIGGER [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ]
/// ```
pub fn parse_drop_trigger(&mut self) -> Result<Statement, ParserError> {
- if !dialect_of!(self is PostgreSqlDialect | GenericDialect) {
+ if !dialect_of!(self is PostgreSqlDialect | GenericDialect |
MySqlDialect) {
self.prev_token();
return self.expected("an object type after DROP",
self.peek_token());
}
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let trigger_name = self.parse_object_name(false)?;
- self.expect_keyword_is(Keyword::ON)?;
- let table_name = self.parse_object_name(false)?;
+ let table_name = match dialect_of!(self is PostgreSqlDialect |
GenericDialect) {
+ true => {
+ self.expect_keyword_is(Keyword::ON)?;
+ Some(self.parse_object_name(false)?)
+ }
+ false => None,
+ };
Review Comment:
Ah yeah, I think what I meant was that since the table name is now optional
that we can look to parse the `ON` suffix if it appears in the text, decoupled
from the dialect. i.e.
```rust
let table_name = if self.parse_keyword(Keyword::ON) {
Some(self.parse_object_name(false)?)
} else {
None
}
```
--
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]