refactor: replace ANTLR parser with omni recursive descent parser#26
Merged
h3n4l merged 5 commits intobytebase:mainfrom Apr 3, 2026
Merged
refactor: replace ANTLR parser with omni recursive descent parser#26h3n4l merged 5 commits intobytebase:mainfrom
h3n4l merged 5 commits intobytebase:mainfrom
Conversation
Replace the ANTLR-based parser (bytebase/parser/mongodb) with the hand-written recursive descent parser (bytebase/omni/mongo). This eliminates the ANTLR runtime dependency and simplifies the translator from ~3400 lines to ~1600 lines by replacing the visitor pattern with direct AST type switches. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors MongoDB shell parsing/translation by replacing the previous ANTLR-based parser/visitor implementation with the github.com/bytebase/omni/mongo recursive-descent parser and a new translation layer built on omni AST node type switches.
Changes:
- Replace ANTLR parse-tree visitor workflow with omni parsing (
mongo.Parse) and direct AST translation (translateNode). - Rework value/helper decoding to consume omni AST nodes for BSON conversion (documents, arrays, literals, helper calls).
- Update module dependencies to drop ANTLR/runtime and introduce
github.com/bytebase/omni.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/translator/visitor.go | Removes the ANTLR visitor-based operation extraction implementation. |
| internal/translator/translator.go | Switches parsing entrypoint to mongo.Parse and routes to omni AST translation. |
| internal/translator/translate.go | Adds omni AST → Operation translation via type switches and method dispatch. |
| internal/translator/helpers.go | Replaces parse-context value conversion with omni AST node conversion helpers. |
| internal/translator/database.go | Ports DB-level argument extraction to omni AST args. |
| internal/translator/collection.go | Ports collection/cursor method arg parsing and option extraction to omni AST args. |
| internal/translator/bson_helpers.go | Ports helper function decoding to omni AST helper calls. |
| go.mod | Removes ANTLR/parser deps; adds github.com/bytebase/omni and bumps/adjusts related deps. |
| go.sum | Updates checksums to reflect dependency graph changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The omni dependency requires Go 1.25.5, which is incompatible with golangci-lint v1.64.8 (built with Go 1.24). Upgrade both the Go version and linter in CI workflows. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Use errors.As for robust ParseError unwrapping in translator.go - Validate that Timestamp document contains both 't' and 'i' fields with integer values in bson_helpers.go - Copy bool value before taking address in extractRenameCollectionArgs to avoid retaining AST node Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
rebelice
approved these changes
Apr 3, 2026
d-bytebase
approved these changes
Apr 3, 2026
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
bytebase/parser/mongodb(ANTLR-based) withbytebase/omni/mongo(hand-written recursive descent parser)antlr4-go/antlr/v4runtime dependency and itsreplacedirectiveTest plan
go build ./...passesgolangci-lint runpasses with 0 issues🤖 Generated with Claude Code