Refactor: replace some dialect_of! checks with Dialect trait methods
#2171
+138
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces 6
dialect_of!macro invocations in the parser with dedicatedDialecttrait 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 already recommends using trait methods instead:This PR is a proof-of-concept to gauge community interest before doing more of these refactorings.
Changes
New trait methods added to
Dialect:supports_extract_comma_syntax()EXTRACT(YEAR, d)comma syntaxsupports_subquery_as_function_arg()FLATTEN(SELECT ...)without extra parenssupports_create_view_comment_syntax()CREATE VIEW ... COMMENT = '...'supports_array_typedef_without_element_type()ARRAYtype without element specificationsupports_parens_around_table_factor()FROM (mytable)extra parenssupports_values_as_table_factor()FROM VALUES (1,'a')without parensEach method includes documentation with examples and links to dialect documentation.
Test plan
cargo fmtandcargo clippypass🤖 Generated with Claude Code