Draft
Add formal EBNF grammar specification for Maya date parser#29
Conversation
Co-authored-by: drewsonne <233054+drewsonne@users.noreply.github.com>
Co-authored-by: drewsonne <233054+drewsonne@users.noreply.github.com>
…nces Co-authored-by: drewsonne <233054+drewsonne@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Document Maya date parsing grammar in EBNF notation
Add formal EBNF grammar specification for Maya date parser
Jan 5, 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.
The parser has no formal grammar specification. Parsing logic is embedded across 4 layers of state machine code, making it difficult to understand the complete language, identify edge cases, or verify completeness.
Changes
Grammar Documentation (
docs/GRAMMAR.md)Lexical Tokens
NUMBER,WORD,WILDCARD,PERIOD,PLUS,MINUS,HASH,NEWLINE,SPACESyntactic Grammar
Semantic Constraints
Ambiguities Resolved
**) tokenize as two separateWILDCARDtokensExamples
6Manik' 5Mol(no space after number),8.7.6.5.4.17.2.1(8-part Long Count)Diagrams
Coverage
Grammar verified against 85 existing parser tests (100% coverage across layers 0-3).
Original prompt
This section details on the original issue you should resolve
<issue_title>Create Formal Grammar Specification</issue_title>
<issue_description>
Parent: Epic: Stabilize Parser & Upgrade to maya-dates >= 1.3.0
Priority: High
Complexity: Medium
Estimated Effort: 16 hours
Labels:
documentation,grammar,specificationDescription
Document the Maya date parsing grammar in EBNF notation. This serves as the specification for the new parser implementation and helps identify edge cases/ambiguities in the current informal parsing logic.
Problem Statement
The current parser has no formal grammar specification. Parsing logic is embedded across 4 layers of state machine code, making it:
Grammar Coverage
The grammar must document:
tzolkin haab(e.g.,4 Ajaw 8 Kumk'u)baktun.katun.tun.winal.kin(e.g.,9.16.19.17.19)calendarRound longCount*in any position (* Ajaw 8 Kumk'u,9.*.10.10.10)expr (+ | -) expr# text(inline or standalone)Deliverables
1.
docs/GRAMMAR.mdCreate comprehensive grammar document with:
Introduction
Lexical Tokens
Syntactic Grammar
Semantic Constraints
Document validation rules not expressible in grammar:
2. Examples for Each Production
For every grammar rule, provide 3+ examples:
3. Ambiguity Analysis
Document and resolve ambiguities:
Ambiguity 1: Partial Dates
Issue: Is
4 Ajawa valid partial calendar round (tzolkin only) or an error?Current Behavior (from tests):
Resolution: Document whether partial dates are:
Ambiguity 2: Whitespace Handling
Issue: How much whitespace is required/allowed between components?
Examples:
4 Ajaw 8 Kumk'u- Single space (valid)4 Ajaw 8 Kumk'u- Multiple spaces (valid?)4Ajaw 8Kumk'u- No space between number and word (valid?)Current Behavior (from tests):
Resolution: Specify exact whitespace rules.
Ambiguity 3: Comment Placement
Issue: Can comments appear anywhere?
Examples:
4 Ajaw 8 Kumk'u # comment- After full date (valid)# comment\n4 Ajaw 8 Kumk'u- Standa...✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.