Skip to main content

Crate tabnas_directive

Crate tabnas_directive 

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

DirectiveConfig
The resolved token identities for a directive, handed to a CustomFn callback.
DirectiveError
A directive registration failure: an unusable name, a duplicate open token, or a grammar that the engine refused to install.
DirectiveOptions
Configuration for one directive.
RuleMod
How a directive integrates with one existing grammar rule.
RulesOption
Which grammar rules a directive modifies.

Enums§

DirectiveAction
How a directive transforms its parsed body.

Constants§

VERSION
VERSION is this crate’s version. It MUST equal ts/package.json “version” and the version field in rs/Cargo.toml: the release orchestrator rewrites all of them, and tests/version_test.rs fails the build if they drift. Mirrors VERSION in ts/src/directive.ts and const VERSION in go/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§

ActionFn
A directive action that transforms the parsed body.
ConditionFn
An alternate condition gating where a directive is recognised.
CustomFn
Extra customization of the parser once the directive rule exists.
TokenActionFn
A directive action that may hand a token back to the engine, mirroring the TypeScript bc hook’s Token | void return. A token carrying an error code halts the parse; any other token is forwarded and otherwise ignored.