Expand description
Directive syntax plugin for the tabnas parser engine.
A directive is a token sequence — @name (open-only) or add<1,2>
(open + close) — that pushes into a dedicated rule and fires an action
to transform the parsed body. This crate is not a parser of its own:
it layers onto whatever host grammar supplies the standard val /
list / map / pair / elem rules, adds open/close tokens, modifies
those host rules, and installs one rule named after the directive.
use tabnas::{Tabnas, Value};
use tabnas_directive::{apply, DirectiveOptions};
let mut parser = Tabnas::new();
// ... install a host grammar supplying val/list/map/pair/elem ...
apply(
&mut parser,
DirectiveOptions::new("upper", "@").with_action(|rule, _ctx| {
let body = match &rule.child_node {
Value::String(text) => text.to_uppercase(),
other => other.to_string().to_uppercase(),
};
tabnas_directive::set_node(rule, Value::String(body));
Ok(())
}),
)?;TypeScript is canonical: ts/src/directive.ts defines behaviour,
option names, defaults and the order of alts. The shared fixtures in
test/spec/*.tsv are the parity contract across TypeScript, Go and
Rust. Intentional differences are tabulated in docs/reference.md.
Structs§
- Directive
Config - The resolved token identities for a directive, handed to a
CustomFncallback. - Directive
Error - A directive registration failure: an unusable name, a duplicate open token, or a grammar that the engine refused to install.
- Directive
Options - Configuration for one directive.
- RuleMod
- How a directive integrates with one existing grammar rule.
- Rules
Option - Which grammar rules a directive modifies.
Enums§
- Directive
Action - How a directive transforms its parsed body.
Constants§
- VERSION
- VERSION is this crate’s version. It MUST equal
ts/package.json“version” and theversionfield inrs/Cargo.toml: the release orchestrator rewrites all of them, andtests/version_test.rsfails the build if they drift. MirrorsVERSIONints/src/directive.tsandconst VERSIONingo/directive.go.
Functions§
- apply
- Register a directive on
parser. - plugin
- Build the directive plugin for
options. - set_
node - Set a rule’s node value.
Type Aliases§
- Action
Fn - A directive action that transforms the parsed body.
- Condition
Fn - An alternate condition gating where a directive is recognised.
- Custom
Fn - Extra customization of the parser once the directive rule exists.
- Token
Action Fn - A directive action that may hand a token back to the engine, mirroring
the TypeScript
bchook’sToken | voidreturn. A token carrying an error code halts the parse; any other token is forwarded and otherwise ignored.