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. - Hoover
Error - A registration failure: the host grammar defines no
valrule, the host’s alt filter removed the block alternate, the options could not be read, or the engine refused the grammar. - Hoover
Options - The plugin options: the ordered block list, the matcher order and the optional alternate action.
- Hoover
Rule Filter - Include and exclude lists for one side of a rule-context filter.
- Hoover
Rule Spec - The rule context a block start is gated on: filters on the current rule and its parent, plus the rule state.
- Start
Spec - 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. MirrorsHoover.defaults.lex.orderin TypeScript andDefaults["lex"]["order"]in Go. - DEFAULT_
TOKEN - The default token name a block emits.
- INVALID_
ESCAPE - The error code a rejected escape (
allow_unknown_escape: falseand an escape not in theescapemap) 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 theversionfield inrs/Cargo.toml: the release orchestrator rewrites all of them, andtests/version_test.rsfails the build if they drift. MirrorsVERSIONints/src/hoover.tsandconst VERSIONingo/hoover.go.
Functions§
- hoover
- Register hoover on
parser, the Rust spelling of the TypeScripttn.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§
- Action
Fn - The alternate action run when a block token is matched by the
valrule, the Rust spelling of the TypeScriptaction?: AltActionoption. It sees the rule whose open token is the block token (itsusebag carries{block: <name>}) and the parse context.