Expand description
Example synthesis from a grammar (item Q-1).
Walks a Grammar’s Peg — not the schema — and emits input
strings that the grammar accepts by construction: every choice
picks a concrete arm, every token contributes matching input text
(%int → 1, %str → "example", keywords verbatim). Because
synthesis reads the grammar itself, spellings supplied through
schema_gen::SyntaxOverrides fall out automatically — no separate
example registration.
Two synthesis modes drive the output of examples_from_grammar:
- Minimal (per-rule examples) — at every choice take the arm with the cheapest finite derivation, at every repeat emit the minimum count. Terminates by the shortest-derivation argument: each step either emits a token or strictly reduces the remaining derivation cost.
- Rich (the composite program) — while a depth budget lasts, choices take the most expensive finite arm and repeats emit up to two iterations, showing nesting and list syntax; the budget decrements per rule expansion and exhaustion falls back to Minimal.
The intended consumer is an AI writing the canonical text syntax: few-shot examples beat a formal grammar table for one-shot accuracy, and machine-derived examples cannot drift from the grammar the way hand-written documentation does.
Modules§
- codes
- Diagnostic codes emitted by example synthesis.
Structs§
- Grammar
Examples - Everything
examples_from_grammarsynthesizes for one grammar. - Rule
Example - One rule’s minimal example.
Constants§
- COMPOSITE_
DEPTH - Rich-mode depth budget used by
examples_from_grammarfor the composite program: rule expansions beyond this depth continue minimally.
Functions§
- examples_
from_ grammar - Synthesizes
GrammarExamplesforgrammar.