fmt: support the MySQL engine - #4595
Merged
Merged
Conversation
Implement ParseFile on the dolphin parser: marino now records the comments its lexer scans, so statements and comments come from one parser pass, with statement extents computed by sequential search so repeated statements resolve to their own occurrences. Parse becomes a filter over ParseFile, dropping the TODO statements the compiler skips while the formatter still sees them. Register MySQL in newQueryFormatter and teach the fmt comment helpers MySQL's # line-comment syntax. Carry marino's newly stamped positions through the converter (FROM tables, INSERT columns, binary and IS NULL expressions) so comments anchor to the right clause and the author's line breaks survive, matching the SQLite and PostgreSQL behavior. The fmt/mysql endtoend case now expects formatted output instead of the unsupported-engine notice. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C48orUYrL7xE989UGLTVqi
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C48orUYrL7xE989UGLTVqi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
sqlc fmtnow formats MySQL query files. Built on marino v0.3.1 (sqlc-dev/marino#46), whose lexer records the comments it scans and stamps positions on table references and INSERT column lists.dolphin: ParseFile
The dolphin parser gains
ParseFile, following meyer's and oliphant's shape: statements and the file's comments from one parser pass.Parsebecomes a filter over it — statements sqlc has no node for stay inParseFile's list (the formatter needs their extents to keep them as written) and are dropped for the compiler.Statement extents are now found by searching from the previous statement's end instead of
strings.Indexover the whole file, so two statements with identical text no longer resolve to the same location.fmt
MySQL joins
newQueryFormatter, and the comment-line helpers learn#, MySQL's line-comment syntax — safe globally, since text reaching those helpers sits outside statements the engine already parsed. The docs page now names the supported engines.Converter positions
The converted nodes carry the positions marino now stamps — FROM-clause tables, INSERT columns, binary and IS NULL expressions. The printer's comment anchoring and break preservation are position-driven (
Pos() == 0nodes are invisible to them), and these fixed two fidelity issues:FROMandWHEREdrifted aboveFROM;INSERT INTO t (...)\nVALUES (...)collapsed to one line.Both now match the SQLite and PostgreSQL behavior: comments stay anchored to their clause, and the author's line breaks survive.
All of fmt's safety nets apply unchanged: a statement is only reformatted when the output reparses to one statement with the same comments and prints as a fixed point, and no file result may change comment content or statement count.
Testing
The
fmt/mysqlendtoend case now expects real formatted output —-- name:headers,# hashcomments, inline/* */comments, trailing same-line comments,@user_namesession variables, andCAST(... AS UNSIGNED)all preserved. The full--tags=examplessuite passes against live PostgreSQL and MySQL.🤖 Generated with Claude Code
https://claude.ai/code/session_01C48orUYrL7xE989UGLTVqi
Generated by Claude Code