Let a Dialect override tokenization
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Feature
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- rust
- Bereich
- backend-api-design
Rechercherichtung
Start by reading Tokenizer::next_token, the private State character-stream implementation, and the parser dialect hooks. The issue proposes a new tokenizer override and raises unresolved questions about lookahead, custom token variants, and performance; first assess those design choices, then validate the hook against existing dialect-specific lexing and measure with sqlparser_bench. Done means the design is settled and dialects can override tokenization without consuming input when they return None.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Follow-up to the discussion in #2610.
Problem
The parser lets a dialect take over at specific points (parse_prefix, parse_infix, parse_statement): it receives &mut Parser, and returning None falls back to the default. The tokenizer has no equivalent. A dialect can only answer yes/no questions the tokenizer asks (is_identifier_part, supports_triple_quoted_string, and about 20 others), so it can toggle existing lexemes but not add new ones.
Dialect-specific lexing therefore lives in Tokenizer::next_token behind dialect_of! checks:
b'...'byte strings (BigQuery, MySQL) and bit strings (Postgres)r'...'raw strings (BigQuery)//as a line comment (Snowflake) or integer division (DuckDB)#as a line comment (Snowflake, BigQuery, MySQL, Hive)\rending a line comment (Postgres)
A downstream dialect cannot add a branch like these. Its only option is tokenize_with_location_into_buf_with_mapper, which rewrites one finished token at a time and cannot see characters or merge tokens.
Example: in dbt models, a Jinja comment {# ... #} breaks under every dialect that treats # as a line comment, because the tokenizer consumes the rest of the line, including #}.
Proposal
- Expose the character stream that
next_tokenreads from (today the privateState:peek,next,location), or a narrow public wrapper around it. - Add a hook with the same contract as the parser hooks:
/// Dialect-specific tokenizer override, called before the default rules. /// /// If `None` is returned, falls back to the default behavior. fn next_token( &self, _chars: &mut State, _prev_token: Option<&Token>, ) -> Option<Result<Token, TokenizerError>> { None } - As a separate step, move the existing
dialect_of!branches into the hook implementations of their dialects. That would show the hook covers syntax already in the tree, and would removedialect_of!from the tokenizer.
Open questions
- Lookahead: a hook that returns
Nonemust not consume input.StatewrapsPeekable<Chars>and allows one character of lookahead. ShouldStatebeClone, or offerpeek_nth? Tokenis a closed enum, so a dialect-specific lexeme must map to an existing variant (Word,CustomBinaryOperator, ...). Is that enough, or should there be aToken::Customvariant?- Cost: one extra dynamic call per token. The tokenizer already calls several dialect methods per token, and
sqlparser_benchcan measure the difference.
- Vorherrschende Sprache
- Rust
- Sterne
- 3.5k
- Forks
- 805
- Ø Merge
- 2 T. 3 Std.
- Gemergte PRs (30 T.)
- 116
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus apache/datafusion-sqlparser-rs
-
Redshift
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
apache/datafusion-sqlparser-rs#2959 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Redshift
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
apache/datafusion-sqlparser-rs#2958 ·
Maintainer antworten meist innerhalb von 1 Tag
-
PostgreSQL
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
apache/datafusion-sqlparser-rs#2862 ·
Maintainer antworten meist innerhalb von 1 Tag
-
PostgreSQL
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
apache/datafusion-sqlparser-rs#2861 ·
Maintainer antworten meist innerhalb von 1 Tag
-
PostgreSQL
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
apache/datafusion-sqlparser-rs#2858 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in apache/datafusion-sqlparser-rs
Ähnliche Issues
-
P3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
HerringtonDarkholme/hd-lang#1770 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
jonathanong/no-mistakes#3332 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
swc-project/swc-next-issues#310 ·
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
swc-project/swc-ai-issues#653 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
lbjlaq/Antigravity-Manager#3937 ·
Maintainer antworten meist innerhalb von 1 Tag