Skip to content

docs(grammar): generate docs/GRAMMAR.md from grammar.pest (#643 PR 4) - #653

Merged
adityamukho merged 2 commits into
v3from
feat/643-grammar-doc
Oct 20, 2026
Merged

adityamukho merged 2 commits into
v3from
feat/643-grammar-doc

Conversation

@adityamukho

@adityamukho adityamukho commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #643 (PR 4 of the plan, steps 14–18). No closing keyword: #643 closes by hand after PR 5.

What

  • tests/grammar_doc.rs (not wasm32) parses tests/grammar/grammar.pest with pest_meta and renders EBNF into docs/GRAMMAR.md. grammar_doc_is_current fails when the file is stale, printing the first differing line and UPDATE_GRAMMAR_DOC=1 cargo test --test grammar_doc.
  • Rendering (spec §7.1 plus plan step 14): ~ → juxtaposition; choices and sequences flattened and parenthesized only where needed; snake_case → kebab-case; SOI/EOI and rule modifiers dropped; ASCII_DIGIT/ASCII_ALPHA/ASCII_ALPHANUMERIC/ANY → digit/letter/(letter | digit)/any-char; !x/&x → (* not followed by x *)/(* followed by x *); e{n} as n copies (and {n,}, {,n}, {m,n}); atomic rules marked (* token *); WHITESPACE → a prose note generated from its literals; // ── X ── lines → section comments; edn_value_only skipped. Long top-level alternations break before | at 88 columns.
  • pest_meta = "2" dev-dependency: the same 2.9.4 that pest_derive already pulls in (cargo tree -d shows no duplicate).
  • 9 tests: the staleness check and 8 renderer tests on small grammars.

Deviations from the plan

  • Section titles are placed by scanning the raw text for rule definition lines, not by span: consume_rules returns ast::Rule without spans, and consume_rules_with_spans is private. Same result (text order).
  • A title followed by no rendered rule before the next title is dropped (WHITESPACE's header).
  • From Codex review: the page states that EBNF literals have no escapes ("\" is one backslash), and the verifier claim says "for every input up to a size bound".

Docs site

project-minigraf/minigraf-docs#47 adds the grammar snapshot page (Reference, since = "v3.0.0"). It needs this PR merged first: until then origin/v3 has no docs/GRAMMAR.md. Built locally against this branch: dist/v3.0.0/grammar/ renders, and v3.0.0's Datalog reference links to it.

Counts

1659 tests (1649 passing, 10 ignored), up 9. CLAUDE.md, README.md, docs/TEST_COVERAGE.md, CHANGELOG.md (v3.0.0 Documentation) updated.

🤖 Generated with Claude Code

https://claude.ai/code/session_019kY61Y11gcRD91Y6b7jbGT

tests/grammar_doc.rs renders tests/grammar/grammar.pest as EBNF with
pest_meta (dev-dependency, already built for pest_derive) and fails when
docs/GRAMMAR.md is stale; UPDATE_GRAMMAR_DOC=1 rewrites it. Lookaheads
become EBNF comments, atomic rules are marked (* token *), section titles
come from the grammar's // ── X ── lines, WHITESPACE becomes a note, and
the verifier's edn_value_only entry rule is left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019kY61Y11gcRD91Y6b7jbGT
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit d12164a into v3 Oct 20, 2026
25 checks passed
@adityamukho
adityamukho deleted the feat/643-grammar-doc branch October 20, 2026 12:43
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.

1 participant