Add ParseStmt, ParseExpr and FormatBeautify convenience API#278
Open
git-hulk wants to merge 1 commit into
Open
Add ParseStmt, ParseExpr and FormatBeautify convenience API#278git-hulk wants to merge 1 commit into
git-hulk wants to merge 1 commit into
Conversation
- ParseStmt(sql) parses exactly one statement, erroring on zero or multiple statements, so callers no longer need to go through NewParser(...).ParseStmts() and validate the slice length. - ParseExpr(sql) parses an expression fragment (column expression, function call, ...) and requires the whole input to be consumed. - FormatBeautify(expr) renders multi-line indented SQL, the one-call counterpart of Format; previously beautified output required wiring NewFormatter().WithBeautify().WriteExpr() by hand. The CLI -beautify path now uses it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Purely additive public API for the three most common call patterns that previously required boilerplate:
Previously a single statement needed
NewParser(sql).ParseStmts()plus slice-length handling, expression fragments could not be parsed at all without wrapping them in a dummy SELECT, and beautified output requiredNewFormatter().WithBeautify().WriteExpr()wiring.Changes
parser/api.gowithParseStmt,ParseExpr,FormatBeautify; errors flow through the existingwrapErrorpath so they carry positions and caret rendering.-beautifypath now usesFormatBeautify(behavior unchanged, verified by CLI smoke test).The
DDL.Type()→ typedKindenum item from the same backlog entry is intentionally left out: it is a breaking change and belongs with the v0.5/v1 interface-split batch.Testing
New
api_test.gocovering single/zero/multiple statements, fragment parsing, trailing-token rejection, andFormatBeautifyequivalence with the long-form formatter plus reparse round-trip. Full suite passes including-race -compatible.🤖 Generated with Claude Code