Skip to main content

Crate tabnas_debug

Crate tabnas_debug 

Source
Expand description

Tracing and introspection plugin for the tabnas parser engine.

This is the developer tool the rest of the tabnas fleet’s test suites consume. It provides four things:

  • describe() — a human-readable dump of a live Tabnas instance: its tag, tokens, token sets, rules, alternates, lexer matchers, config, plugins, and an ABNF rendering of the grammar.
  • model() — the structured counterpart: the same information as a typed, serialisable DebugModel, so tools and tests can consume the grammar programmatically.
  • abnf() — a re-compilable ABNF rendering of the instance’s live grammar.
  • parse tracing that logs events as the parser runs (see TraceKinds).

The plugin is a developer tool, not part of the parse path.

use tabnas::Tabnas;
use tabnas_debug::{apply, describe, DebugOptions};

let mut parser = Tabnas::new();
// ... install a grammar ...
apply(&mut parser, DebugOptions::quiet())?;
println!("{}", describe(&parser));

TypeScript is canonical: ts/src/debug.ts is the source of truth for behaviour, option names, defaults, output format and section ordering. The shared fixtures in test/spec/*.tsv are the parity contract. Intentional differences are recorded in docs/reference.md.

§Free functions, not instance methods

TypeScript attaches these as instance methods (tn.debug.describe()). Rust cannot add methods to a type it does not own, so — exactly as the Go port does — they are free functions taking the instance. They are also infallible here: the Go port returns (value, error) because its engine accessors can fail, while the Rust accessors cannot.

Re-exports§

pub use abnf::abnf;
pub use describe::describe;
pub use describe::SECTIONS;
pub use model::model;
pub use model::DebugAltInfo;
pub use model::DebugConfigInfo;
pub use model::DebugLexMatcher;
pub use model::DebugModel;
pub use model::DebugPluginInfo;
pub use model::DebugRuleEdges;
pub use model::DebugRuleInfo;
pub use model::DebugSeqItem;
pub use model::DebugTokenInfo;
pub use model::DebugTokenSet;
pub use trace::TraceKinds;
pub use trace::TRACE_BANNER;

Modules§

abnf
Emit an ABNF representation of an instance’s live grammar.
describe
describe() — a human-readable dump of a live instance: its tag, tokens, token sets, rules, alternates, lexer matchers, config, plugins, and an ABNF rendering of the grammar.
model
The structured counterpart to crate::describe(): an instance and its grammar as typed, JSON-serialisable data, so tools and tests can consume the grammar programmatically.
trace
Parse tracing: log events as the parser runs.

Structs§

DebugOptions
How the debug plugin behaves once installed.

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 them, and tests/version_test.rs fails the build if they drift. Mirrors VERSION in ts/src/debug.ts and const VERSION in go/debug.go.

Functions§

apply
Install the debug plugin on parser.
plugin
Build the debug plugin for options.
use_plugin
Install plugin on parser, dumping describe() afterwards when the debug plugin was installed with print on.