andygrove opened a new pull request, #2171: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2171
## Summary This PR replaces 6 `dialect_of!` macro invocations in the parser with dedicated `Dialect` trait methods. This improves the separation between generic parsing logic and dialect-specific behavior, making it easier for custom dialects to override behavior without modifying the parser. ## Motivation The codebase currently has ~134 `dialect_of!` macro calls scattered throughout the parser. The [dialect module documentation](https://github.com/apache/datafusion-sqlparser-rs/blob/845e2130e908eb4e8e8ec7fab5c9f163cd2fff2c/src/dialect/mod.rs#L64-L71) already recommends using trait methods instead: > Note: when possible please the new style, adding a method to the `Dialect` trait rather than using this macro. > > The benefits of adding a method on `Dialect` over this macro are: > 1. user defined `Dialect`s can customize the parsing behavior > 2. The differences between dialects can be clearly documented in the trait This PR is a proof-of-concept to gauge community interest before doing more of these refactorings. ## Changes New trait methods added to `Dialect`: | Method | Dialects | Description | |--------|----------|-------------| | `supports_extract_comma_syntax()` | Snowflake, Generic | `EXTRACT(YEAR, d)` comma syntax | | `supports_subquery_as_function_arg()` | Snowflake | `FLATTEN(SELECT ...)` without extra parens | | `supports_create_view_comment_syntax()` | Snowflake, Generic | `CREATE VIEW ... COMMENT = '...'` | | `supports_array_typedef_without_element_type()` | Snowflake | `ARRAY` type without element specification | | `supports_parens_around_table_factor()` | Snowflake, Generic | `FROM (mytable)` extra parens | | `supports_values_as_table_factor()` | Snowflake, Databricks, Generic | `FROM VALUES (1,'a')` without parens | Each method includes documentation with examples and links to dialect documentation. ## Test plan - [x] All existing tests pass - [x] `cargo fmt` and `cargo clippy` pass - No new tests needed as this is a refactoring of existing behavior 🤖 Generated with [Claude Code](https://claude.ai/code) -- 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]
