Skip to main content

Crate bynk_grammar

Crate bynk_grammar 

Source
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§

GrammarError
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 name is 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 full ebnf block 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 in productions (the same <name> ::= <rhs> line render_production embeds, over embeddable_rules), and the full-grammar page reads appendix (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_json preserve_order).