Skip to main content

Crate varar_core

Crate varar_core 

Source
Expand description

varar-core — the pure functional core of var, ported from the Java module dev.varar.core: parse → match → plan → execute, diffs, drift/hash, canonical JSON, and the conformance projections. No filesystem, network, time, or test-framework dependencies.

The sealed Java interfaces (Block, TableOrFence, ResolvedSteps) become Rust enums; the exception hierarchy becomes error::StepError/Result; Object duck-typing becomes value::Value; reflective handler invocation becomes boxed closures (handler::Handler).

Modules§

ast
AST node types produced by the scanner/structurer — port of ast.ts / Ast.java. Pure data; the sealed Block/TableOrFence interfaces become Rust enums (exhaustive match replaces instanceof). Immutability is by construction (owned fields, no mutation) — Java’s List.copyOf defensive copies have no Rust analog.
cell_diff
Table row/cell comparison — port of cell-diff.ts / CellDiff.java. Object + instanceof Map/List duck-typing becomes matching on Value.
conformance
Projects pipeline output into the plain Value wire artifacts the conformance goldens pin — port of conformance.ts / Conformance.java. Covers all four projections (var-doc, registry, plan, trace).
diagnostics
Diagnostics produced by the planner — port of the subset of diagnostics.ts that Plan needs / Diagnostics.java.
doc_string_diff
Doc-string comparison — port of doc-string-diff.ts / DocStringDiff.java.
drift
Oath drift detection — port of drift.ts / Drift.java. A paragraph the committed varar.lock.json baseline recorded as an example that now matches no step. Byte-identical to the other ports (FNV-1a fingerprint, insertion-ordered lockfile serializer, Jaccard word-similarity re-identification).
error
The error model: the Rust replacement for Java varar-core’s typed exception hierarchy (CellMismatchException, ReturnShapeException, UnexpectedPassException, author AssertionError). Result/panic-catch replace throw; instanceof dispatch becomes match.
execute
The executor — port of execute.ts / Execute.java, on the full-replacement state model. Handlers are invoked via boxed closures (no reflection); panics are caught (the AssertionError/Throwable parity channel); Future returns are driven by a small std block_on. State is a Value, replaced wholesale by each stimulus.
expression
Cucumber-expression matching — the owned layer over the cucumber-expressions crate’s grammar parser. Replaces io.cucumber.cucumberexpressions. We take the crate’s AST parser (the escape-rule-dense part) and own the small, corpus-pinned rest: regex generation with one named group per parameter, built-in + custom parameter types, argument extraction, and parameter_type_names.
failure
Converts a caught step failure into the structured ExampleFailure payload — port of failure.ts / Failure.java. The Java stack-trace-scraping machinery becomes a structural [FailureLocation] lookup by exact path match.
handler
Step handlers — the Rust replacement for Java’s reflective arity-matched SAM invocation (Execute.invokeHandler/samMethod). A handler is a boxed closure over (state, args); arity is validated at the constructor. StepReturn carries the sync-or-Future channel (the analog of “an Object that might be a CompletableFuture”).
hash
FNV-1a (32-bit) change-detector over UTF-16 code units — port of hash.ts / Hash.java. Byte-identical across every port so varar.lock.json fingerprints match. The fnv1a: prefix namespaces the algorithm.
json_escape
JSON string escaping, reproducing JSON.stringify’s: control chars as \uXXXX, non-ASCII raw. Shared by the writers that produce real files — the run-result writer in crate::result, and the lock-file writer.
json_value
A tiny recursive-descent JSON reader over the dynamic Value model.
matcher
Matches a sentence against a registry’s compiled expressions — port of matcher.ts / Matcher.java. Unanchored substring scan per step, then greedy left-to-right non-overlap resolution. All returned offsets are UTF-16 (regex byte offsets converted at Hit construction).
offsets
UTF-16 offset helpers — the conversion layer the Python port needed and Java did not. All spans/offsets in the shared conformance goldens are UTF-16 code-unit offsets (Java String/char are UTF-16 natively); Rust str is UTF-8, so byte offsets from str::find/the regex crate must be converted to UTF-16 at every span-production site. Byte offsets exist only as transient locals; every stored offset is UTF-16.
param_diff
Parameter comparison — port of param-diff.ts / ParamDiff.java. Compares a sensor’s returned inline actuals against the values captured from the document.
parse
Top-level parse entry point: scan then structure — port of parse.ts / Parse.java.
plan
The planner — port of plan.ts / Plan.java. Plans each text-bearing block via the matcher, lifts block offsets to source spans, attaches trailing table/fence nodes, handles the ```error fence, expands header-bound tables into one example per row, and collects diagnostics.
reference
Reuse is a link (ADR 0016). A candidate block whose entire content is a single Markdown link to an oath section is a REFERENCE BLOCK: it splices that section’s steps in at its own position instead of being prose.
registry
Step registry — port of registry.ts / Registry.java. Wraps the owned crate::expression layer. Persistent-value semantics: add_step / define_parameter_type return a new Registry; the argument is unchanged.
result
Immutable run-result records — port of result.ts / Result.java. The persisted .varar/<oath>.json file is a serialized OathResults.
scanner
Turns raw Markdown into a flat list of Block nodes — port of scanner.ts / Scanner.java. Offsets in stored spans are UTF-16 code units; the line splitter keeps a running (byte, UTF-16) dual cursor and per-line regex offsets are converted from bytes to UTF-16.
sentences
Splits a block of text into sentence-level spans so the matcher can try each sentence independently — port of sentences.ts / Sentences.java. Operates on chars with a running UTF-16 offset table (the Python-port approach): the split decisions use BMP terminators, and emitted offsets are UTF-16.
span
Source positions/ranges anchored to UTF-16 code-unit offsets (1-based line/column). Port of varar-core/src/span.ts / Span.java.
step_kind
The role a step definition plays — port of step-role.ts’s StepKind / StepKind.java.
step_role
Guess a step’s role from its neighbours in document order — port of step-role.ts / StepRole.java. Purely structural (no keyword heuristics).
structurer
Groups the flat scanner output into Examples, tracking a heading scope stack — port of structurer.ts / Structurer.java.
table_cells
Parses a Markdown/Gherkin table row (| a | b |) into trimmed cells + each cell’s source span — port of table-cells.ts / TableCells.java.
value
The dynamic value model — the Rust replacement for Java varar-core’s Object with instanceof Map/List/String duck-typing (see CellDiff.java, DocStringDiff.java, ParamDiff.java). One closed enum carries handler arguments, handler returns, thread-through state, row objects, table rows, and the conformance wire values.