feat(mongodb): accept string arguments in Int32/NumberInt helpers#64
feat(mongodb): accept string arguments in Int32/NumberInt helpers#64
Conversation
Int32("123") and NumberInt("456") are valid in mongosh but the grammar
only accepted NUMBER tokens. Align with Long/NumberLong which already
supports both forms.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the MongoDB shell ANTLR grammar to accept string arguments for Int32(...) / NumberInt(...) helpers (e.g., Int32("123")), aligning behavior with existing Long(...) / NumberLong(...) parsing and improving mongosh compatibility.
Changes:
- Expanded the
int32Helpergrammar rule to accept(NUMBER | stringLiteral)instead of onlyNUMBER. - Regenerated the Go parser output to reflect the grammar update.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| mongodb/MongoShellParser.g4 | Updates int32Helper rule to accept string literals for Int32/NumberInt constructors. |
| mongodb/mongoshell_parser.go | Regenerated parser code to support the updated int32Helper alternative (NUMBER or string literal). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Int32(n), Int32("n"), NumberInt(n), NumberInt("n") | ||
| int32Helper | ||
| : (INT32 | NUMBER_INT) LPAREN NUMBER RPAREN | ||
| : (INT32 | NUMBER_INT) LPAREN (NUMBER | stringLiteral) RPAREN |
There was a problem hiding this comment.
The grammar now accepts Int32("n") / NumberInt("n"), but the parser test suite (driven by mongodb/examples/*.js) currently only exercises numeric Int32(100) / NumberInt(100). Please add examples for the quoted-string forms (e.g., in examples/helper_functions.js) so this new syntax is covered and regressions are caught.
Summary
Int32("123")andNumberInt("456")syntax in the MongoDB shell grammar, matching the existingLong/NumberLongbehaviorContext
Bytebase uses gomongo to translate mongosh queries to native Go driver calls. Telemetry showed
Int32("string")as the most frequent compatibility failure (BYT-9080). TheLong/NumberLonghelpers already accept string arguments — this change makesInt32/NumberIntconsistent.Changes
MongoShellParser.g4: Changedint32Helperrule fromNUMBERto(NUMBER | stringLiteral)Test plan
make build && make testinmongodb/directory passes🤖 Generated with Claude Code