Skip to main content

Crate tabnas_abnf

Crate tabnas_abnf 

Source
Expand description

An ABNF (RFC 5234) grammar compiler for the tabnas parsing engine.

Where most tabnas grammar crates carry one fixed grammar, this one is a META compiler: the grammar it installs is whatever ABNF text it is handed at run time.

ABNF text ──parse_abnf──▶ Grammar ──emit_grammar_spec──▶ GrammarSpec

parse_abnf is the RFC 5234 front-end and is what this crate adds; everything downstream of the IR lives in tabnas_bnf and is shared with the GBNF and EBNF front-ends.

let mut parser = tabnas::Tabnas::new();
tabnas_abnf::abnf(&mut parser, "greet = \"hi\" / \"hello\"", None).unwrap();
let tree = parser.parse("hello").unwrap();
assert_eq!(tree.to_json()["rule"], "greet");

This is the Rust port of the canonical TypeScript implementation in ts/src; the TypeScript version is authoritative and this crate tracks it.

Structs§

AbnfActionError
A malformed or unresolvable user action ref.
AbnfCompileError
A grammar that cannot be reduced to pure data.
AbnfCompileOptions
Options for abnf_compile: what to convert, and how to serialize it.
AbnfConvertOptions
Compiler options. Mirrors the TypeScript ConvertOptions.
AbnfOptions
Options for abnf, the install path.
AbnfParseError
A failure to read ABNF source.
AltSpec
One emitted alternate: the engine’s alt fields in the order they were written, plus the compiler-internal mark m, which never reaches the wire.
Element
One element of a sequence: a terminal in one of its spellings, a rule reference, or EBNF sugar around further elements. The kind carries the variant; sp is where the element came from, when the front-end recorded it. Mirrors the TypeScript Element union.
EmitError
A compile failure that can say WHERE.
Grammar
A grammar: the productions a front-end lowered, plus the <remove> directives and the ambiguity report.
GrammarSpec
The emitted grammar.
JsonicOptions
How to_jsonic writes its text.
Production
One rule of the grammar. Mirrors the TypeScript Production.
RuleSpec
One emitted rule: its open alternates and, when it captures or replaces, its close alternates.
SrcSpan
Where an IR node came from in the front-end’s grammar text.
TranslationPart
One optional alchemy translation source and its explicit entry point.
TranslationParts
The package-local structural translation interface.
ValueAnnotation
What a production builds when it carries a value annotation.

Enums§

AbnfError
Anything that can go wrong turning ABNF source into a grammar.
Kind
The element variants. Serialized with the TypeScript field names, so an IR built in one runtime loads in the other.
NodeKind
How a production contributes to the output AST.
RefAction
What a @-ref in the spec’s ref map stands for. In closure mode the emitter registers one of these per tree-building or probe-control action instead of a $-builtin; GrammarSpec::bind turns them into engine closures by name. User actions land here too.
TransducePart
The transducer part of an emitted grammar, or why its documents are read whole.

Constants§

TAG
The group tag stamped on every emitted alt, and the prefix of every diagnostic this crate raises through the shared compiler.
VERSION
This crate’s version. It MUST equal ts/package.json “version”: the release orchestrator rewrites both, and tests/version_test.rs fails the build if they drift. Mirrors VERSION in ts/src/abnf.ts and const VERSION in go/abnf.go.

Functions§

abnf
Convert ABNF source and install the resulting grammar on parser.
abnf_compile
Compile ABNF source into a pure-data tabnas grammar, as jsonic text.
abnf_convert
Convert ABNF source into a tabnas grammar spec, without installing it. The Rust spelling of tn.abnf.toSpec(src).
abnf_rules
The ABNF meta-grammar’s rule table, as data.
abnf_transduce
The transducer part of an ABNF grammar, <name>-transduce: the alchemy program that streams the JSON events of the value its ; @object and ; @array annotations build, from its rule passes, or why its documents are read whole (transduce_alc says when). Converts as abnf_convert does, with opts. The Rust spelling of abnfTransduce.
attach_action_slots
Declare user-action SLOTS on a (pure-data) spec without supplying functions: each @<rule>:o|c:<mark> ref name is injected into the matched alt’s array-a, to be resolved at load time from a user-supplied ref map. Fails on unknown targets and on rule-phase refs.
attach_actions
Attach user semantic actions to a spec, in place. Keys are @<rule>:<phase> (bo/ao/bc/ac) or @<rule>:o|c:<mark>; the functions run AFTER the compiler’s own action, in attachment order. Alt actions are injected as the engine’s array-a form. Fails for a ref matching no rule, hook or marked alt.
eliminate_left_recursion
Eliminate left recursion, both direct (P → P α) and indirect (P → Q α, Q → P β), via Paull’s algorithm. Order the productions, and for each A_i walk back over A_1..A_{i-1} inlining any leading reference into A_i’s alternatives; once the only remaining leading self-reference on A_i is direct, rewrite to the iterative form P → (β_1 | … | β_m) (α_1 | … | α_n)*.
emit_grammar_spec
Emit a spec from an already-parsed ABNF grammar.
make
A fresh parser that reads an ABNF document as the tree: the parser a host streams a document through with the part, whose rule passes the part reads, and whose value is the tree (Undefined for an empty source, which makes no pass).
manifest_text
The plugin’s manifest, tabnas.plugin.json, as the repository carries it. Its translate object is what a host that translates reads: the shape a document is read as and written from (tree), the schema of that tree (grammar-rules), the root the render needs (object), the files that hold the part and the render, the sentences that say what a written grammar does not keep, and spec, the grammar-spec route. The crate embeds its own copy, translate/manifest.json, since a packaged crate holds nothing outside rs/; tests/translate_test.rs holds the copy to the file.
mark_listing
Human-readable listing of the marks the compiler assigned, one line per marked alt: <rule> o|c:<mark> s:<tokens> | p:<rule> | (empty).
parse_abnf
Parse ABNF source into the grammar IR.
parse_abnf_tree
An ABNF document read whole as the tree. A source the meta-grammar refuses, or the tree cannot hold, fails with an AbnfParseError naming the line and column, its code the engine’s.
plugin
The plugin descriptor, for Tabnas::use_plugin.
render_spec_text
The grammar-spec route’s render, alchemy/render-spec.alc, the file the manifest’s translate.spec.render names: its entry point abnf-render-spec writes a grammar spec’s events as one ABNF document that compiles back to the same spec. The crate embeds its own copy, translate/render-spec.alc.
render_text
The render, alchemy/render.alc, the file the manifest’s translate.render names: a library of alchemy definitions, with no export, whose entry point abnf-render writes a grammar-rules tree’s events as one ABNF document that reads back as the same tree. A host links it with its own program. The crate embeds its own copy, translate/render.alc, held to the file as the manifest’s is.
to_jsonic
Serialise a (function-free) value as jsonic text. Regular expressions are already @/pattern/flags strings in the data.
to_pure_spec
Reduce a spec to a pure-data, function-free grammar that KEEPS the AST-building $-builtins. Requires a builtins: true conversion with no user actions attached: any remaining ref is refused.
to_recognition_spec
Strip a converted spec down to a function-free recognition grammar, dropping the tree and value builders. Fails for grammars whose control logic is still closures (a probe dispatcher converted without builtins).
transduce_alc
The transducer part of an emitted grammar, defining <name>-transduce, or why its documents are read whole (ts/src/transduce.ts says when).
transduce_text
The part, alchemy/transduce.alc, the file the manifest’s translate.transduce names: its entry point abnf-transduce makes the tree’s events from the rule passes of make. The crate embeds its own copy, translate/transduce.alc.
translate
Return the translation parts of ABNF documents: the manifest, the part that streams a document’s tree, its rules in source order (the schema grammar-rules, which EBNF and GBNF share), from the rule passes of make, the render that writes such a tree back as ABNF, and, as spec, the render of the grammar-spec route, which writes the GrammarSpec the compiler emits back as ABNF (the tree a host reads on that route is abnf_compile with recognition false and strict true). There is no lift and no embed.

Type Aliases§

ActionFn
A user semantic action: run after the compiler’s own action on the alt it is attached to, with the engine’s rule and context.
ActionsMap
Action refs to attach: @<rule>:<phase> (bo/ao/bc/ac) or @<rule>:o|c:<mark>, each with the functions to run in order.
Sequence
A sequence of elements: one alternative of a production.