pub grammar - a package offers its grammar’s entriesOpen and answer this issue on GitHub.
blocked · opened 2026-10-07 · updated 2026-10-07 · 1 comment
Split out of #485, which waits on it. There was no issue for it.
What is decided (ADR-296 D25). pub belongs to the grammar. pub grammar G offers every entry rule of G to other packages, the way a pub enum offers its variants. A rule is never pub on its own: pub rule is refused, and the message names both words. No entry is distinguished.
Today. The parser refuses pub grammar with decided and not built (parser/mod.rs, around line 2398). So no package can offer a grammar, and dsl pkg::Sql { … } eod (ADR-299 D20, #485) has nothing to resolve to.
To build
pub grammar, and refuse pub rule with both words named (if that is not done already).pub grammar’s entries are recorded as the package’s entries (G::rule, as a grammar call is keyed, ADR-296 D24), with their signatures. So a consumer resolves pkg::G::rule(…), and a dsl pkg::G { … }.dsl pkg::G resolves to the pub grammar. NK1228’s help lists the package’s pub grammars. A package with two grammars has each reachable by its own path.Tests: a path package declares pub grammar Num { entry rule n -> i64 = … }, and a consumer calls pkg::Num::n("42") and prints 42. A non-pub grammar is NK1110 (private). pub rule is refused.
Steps 1-3 built in 0.0.618 (67a67a4).
pub grammar parses. GrammarDef carries public (ast.nika). pub rule stays refused, with both words named, as before.public is the grammar’s. Before, it was always true.lib::Nums::number(input) becomes nikaia_std::grammar::parse(&*input, lib::Nums::parse_number())?, as an entry of its own file’s grammar is. The emitter recognises the entry by what the package’s ledger records for every entry rule: one input, input, and ParseError as its one failure.grammar_lowering.rs, a_pub_grammar_is_entered_from_another_package. Two packages: the consumer prints 42, and calling the package’s non-pub grammar is NK1110. The test that expected the not built refusal is replaced by it.Left:
par_fold entry across packages, which needs parse_…_pieces and the parallelism. The ledger does not say an entry is a fold, so such a call would be lowered as a sequential parse and refused by rustc. It needs a column, or the dependency’s units.dsl lib::G { … }: a dsl block over a grammar is not lowered at all yet, its own or a package’s. That is #518, so it waits there.Generated by Claude Code