tabnas-debug 0.3.13

Tracing and introspection plugin for the tabnas parser engine.
Documentation

tabnas-debug (Rust)

Debug / introspection plugin for the tabnas parser engine, crate tabnas-debug (library tabnas_debug).

It makes a grammar visible: describe dumps an instance's installed grammar (tokens, rules, plugins) as labelled text, model returns the same information as structured, serialisable data, abnf re-expresses it as ABNF, and tracing logs a parse event by event. A dev/test aid, never a runtime dependency.

This is the Rust port of the canonical TypeScript implementation in ../ts; the TypeScript version is authoritative and this crate tracks it. The Rust engine exposes tracing and introspection through different idioms, so the surface differs in shape: free functions instead of instance methods, typed options instead of an option map, and a use_plugin wrapper for the print option. See the concepts doc and reference for the details, and ../docs/reference.md for the authoritative cross-runtime divergence register.

Install

The engine is on crates.io as tabnas-parser, whose library is named tabnas in code, and so is this crate, as tabnas-debug. The examples below name both, so add both:

cargo add tabnas-debug tabnas-parser

This repository's own Cargo.toml is not the published one: it takes the engine by path from a sibling checkout, so a build here needs https://github.com/tabnas/parser cloned beside it. The release workflow swaps that path for a crates.io version when it publishes the crate.

Use

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

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut parser = Tabnas::new();
    // ... install a grammar ...

    // Introspection needs no plugin at all: these are free functions.
    println!("{}", describe(&parser));
    println!("{}", abnf(&parser));
    println!("{}", model(&parser).config.start);

    // Tracing does need the plugin. Events go to the engine's debug
    // sink (stderr by default).
    apply(&mut parser, DebugOptions::default())?;
    parser.parse("a:1")?;
    Ok(())
}

describe, model and abnf read a live instance and have no side effects, so they work on any Tabnas whether or not the plugin is installed. Installing the plugin is what turns on tracing and the USE: dump.

To capture output instead of writing it to stderr, set the engine's sink:

# let mut parser = tabnas::Tabnas::new();
parser.options.debug.output = Some(std::sync::Arc::new(|line: &str| {
    // collect `line`
}));

Documentation

  • Tutorial. Zero to a working inspection, step by step.
  • How-to guide. Focused recipes.
  • Reference. The exact exports, options, and output.
  • Concepts. How it works and how it differs from the TypeScript version.

Build and test

The engine is a path dependency on the sibling checkout, so there is nothing to fetch and nothing to build first:

cargo build --all-targets
cargo test --all-targets
cargo clippy --all-targets --all-features -- -D warnings

Or, from the repository root, make test-rs runs the tests and Clippy. There is only one resolution here, always the sibling engine, unlike the Go module's pinned/workspace pair.

The suite runs the shared ../test/spec/*.tsv conformance fixtures (the same files the TypeScript and Go suites run) over the same named grammars. A row green in one runtime and red in another is a failure, not a discrepancy.

License

MIT.