Skip to main content

Crate tabnas_hoover

Crate tabnas_hoover 

Source
Expand description

Block-delimited string hoovering for the tabnas parser engine.

Hoovering vacuums up a run of source text, internal spaces and newlines included, between a start and an end delimiter, with optional escape handling and rule-context gating. The two canonical shapes are triple-quoted strings ('''hello world''') and end-of-line values (an unquoted run of text up to a newline, #, ; or the end of the input).

This crate is not a grammar: it is a lexer-matcher plugin that extends the host grammar’s val rule, so it is applied to a Tabnas instance that already carries a grammar defining val. It installs one custom lex matcher (lex.match.hoover, at order 4.5e6, ahead of the string and number matchers) that emits a #HV token, and prepends a val alternate accepting that token.

use tabnas::Tabnas;
use tabnas_hoover::{hoover, Block, HooverOptions};

let mut parser = Tabnas::new();
// ... install a host grammar that defines the `val` rule ...
hoover(
    &mut parser,
    HooverOptions::new(vec![Block::delimited("triplequote", "'''", "'''")]),
)?;
let value = parser.parse("'''hello world'''")?; // "hello world"

TypeScript is canonical: ts/src/hoover.ts defines behaviour, option names and defaults, and go/hoover.go is the sibling port. The shared fixtures in test/spec/*.tsv are the parity contract across all three.

Structs§

Block
One block definition. Blocks are tried in the order they are listed in HooverOptions::block, so that order is significant.
EndSpec
How a block ends: the delimiters it scans for, and whether a matched one is consumed. The empty string "" names the end of the input.
HooverError
A registration failure: the host grammar defines no val rule, the host’s alt filter removed the block alternate, the options could not be read, or the engine refused the grammar.
HooverOptions
The plugin options: the ordered block list, the matcher order and the optional alternate action.
HooverRuleFilter
Include and exclude lists for one side of a rule-context filter.
HooverRuleSpec
The rule context a block start is gated on: filters on the current rule and its parent, plus the rule state.
StartSpec
How a block starts: optional fixed delimiters, whether a matched one is consumed, and the rule context the start is gated on.

Enums§

Consume
Whether a matched delimiter is consumed (removed from the value and the stream) or left in place. Mirrors the TypeScript consume?: null | boolean | string[] field.

Constants§

DEFAULT_LEX_ORDER
The default matcher order: before the string (5e6) and number (7e6) matchers. Mirrors Hoover.defaults.lex.order in TypeScript and Defaults["lex"]["order"] in Go.
DEFAULT_TOKEN
The default token name a block emits.
INVALID_ESCAPE
The error code a rejected escape (allow_unknown_escape: false and an escape not in the escape map) is rejected with.
INVALID_TEXT
The error code a committed block that never reaches an end delimiter is rejected with.
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/hoover.ts and const VERSION in go/hoover.go.

Functions§

hoover
Register hoover on parser, the Rust spelling of the TypeScript tn.use(Hoover, options) call.
js_trim
JavaScript’s String.prototype.trim, exactly: strip leading and trailing code points in the ECMA-262 trim set.
plugin
Build the hoover plugin for options.

Type Aliases§

ActionFn
The alternate action run when a block token is matched by the val rule, the Rust spelling of the TypeScript action?: AltAction option. It sees the rule whose open token is the block token (its use bag carries {block: <name>}) and the parse context.