Skip to content

Conversation

@h3n4l
Copy link
Member

@h3n4l h3n4l commented Jan 13, 2026

Summary

  • Add ANTLR grammar for parsing MongoDB shell (mongosh) syntax
  • Generate Go code for lexer, parser, listener, and visitor
  • Support MVP read operations as specified in the design document

Supported Features

Shell Commands:

  • show dbs, show databases, show collections

Database Statements:

  • db.collection.method(...) with method chains
  • Collection access: db.users, db["users"], db.getCollection("users")

Read Methods:

  • find(filter), findOne(filter)

Cursor Modifiers:

  • .sort(doc), .limit(n), .skip(n), .projection(doc), .project(doc)

Helper Functions (distinct AST nodes):

  • ObjectId(), ISODate(), Date(), UUID()
  • Long(), NumberLong(), Int32(), NumberInt()
  • Double(), Decimal128(), NumberDecimal()
  • Timestamp(), RegExp()

Document Syntax:

  • Unquoted and quoted keys
  • Nested documents and arrays
  • Trailing commas allowed
  • Single and double quoted strings

Other:

  • Regex literals: /pattern/flags
  • Comments: // line, /* block */
  • Numbers: integers, floats, scientific notation
  • Booleans and null

Design Decision

The new keyword is intentionally not supported for helper functions. When users write new ObjectId(), the parser generates a helpful error message using ANTLR's NotifyErrorListeners mechanism:

'new' keyword is not supported. Use ObjectId() directly

Test plan

  • All example files in mongodb/examples/ parse without errors
  • Unit tests cover shell commands, find operations, cursor modifiers, collection access, helper functions, regex, document syntax, literals, and comments
  • Error position reporting verified
  • Custom error message for new keyword usage verified

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings January 13, 2026 08:24
Add ANTLR grammar for parsing MongoDB shell syntax with Go code generation.

Supported features:
- Shell commands: show dbs, show databases, show collections
- Database statements: db.collection.method(...) with method chains
- Collection access: dot notation, bracket notation, getCollection()
- Read methods: find(), findOne()
- Cursor modifiers: sort(), limit(), skip(), projection(), project()
- Helper functions as distinct AST nodes: ObjectId(), ISODate(), Date(),
  UUID(), Long(), NumberLong(), Int32(), NumberInt(), Double(),
  Decimal128(), NumberDecimal(), Timestamp(), RegExp()
- Document syntax: unquoted/quoted keys, nested documents, arrays,
  trailing commas
- Regex literals: /pattern/flags
- Literals: strings (single/double quoted), numbers, booleans, null
- Comments: line (//) and block (/* */)

The 'new' keyword is intentionally not supported for helper functions.
When users write 'new ObjectId()', the parser generates a helpful error
message using ANTLR's NotifyErrorListeners mechanism.

Also adds mongodb to the CI workflow parser list.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@h3n4l h3n4l force-pushed the vk/0a3b-mongodb-mongosh branch from 3ea62a8 to 362fcdf Compare January 13, 2026 08:26
@h3n4l h3n4l merged commit 8ac2a65 into main Jan 13, 2026
5 checks passed
@h3n4l h3n4l deleted the vk/0a3b-mongodb-mongosh branch January 13, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants