Expand description
Render the tree-sitter-bynk grammar to EBNF.
This crate is the single source of the grammar reference. It takes the
compiled grammar JSON (tree-sitter-bynk/src/grammar.json) as input and is
otherwise location-agnostic, so the same renderer feeds both the full
appendix page (render_appendix) and the per-rule includes embedded in
the curated reference page (render_production / render_rule). Because
both come from one implementation, an embedded production cannot drift from
the appendix.
Display names. Grammar rule names are parser-internal (_type_ref,
_expression, …). For the reference we render readable names via
display_name: a trivial _x ::= y wrapper collapses to its target, an
optional override applies, otherwise a single leading underscore is stripped.
The transform is applied to both rule heads and the nonterminal references
inside productions, so the whole reference reads as language, not internals.
See bynkc/tests/grammar_reference.rs (the appendix generator) and
site/src/plugins/remark-bynk-directives.mjs (the {{#grammar <rule>}}
include directive the Book renders with).
Enums§
- Grammar
Error - An error rendering a grammar production.
Functions§
- display_
name - The readable display name for a top-level rule. Errors if the grammar is
unparseable or
nameis not a top-level rule. - embeddable_
rules - Every top-level rule that should have exactly one
{{#grammar}}entry in the annotated reference: all rules except the trivial wrappers the display layer collapses (so this can never disagree with what is rendered). Grammar rule order is preserved. Returns an empty vector if the JSON is unparseable. - render_
appendix - Render the complete grammar reference appendix
(
site/src/content/docs/book/reference/grammar-appendix.md): the generated-file header, the notation note, the fullebnfblock of every production (display names, trivial wrappers collapsed), and the Tokens & trivia section. - render_
production - Render a complete production line,
<display name> ::= <rhs>, as it appears in the appendix (no surrounding fence). This is what{{#grammar <rule>}}embeds. - render_
rule - Render a single production’s right-hand side (display names applied), exactly
as it appears after
<name> ::=in the appendix’s EBNF block. - render_
site_ json - Render the grammar as the JSON document the documentation site consumes. The
{{#grammar}}remark directive looks each rule up inproductions(the same<name> ::= <rhs>linerender_productionembeds, overembeddable_rules), and the full-grammar page readsappendix(render_appendix). Because both come from the same renderer as the mdBook preprocessor, the site cannot drift from the book. Object keys preserve grammar order (serde_jsonpreserve_order).