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 sealedBlock/TableOrFenceinterfaces become Rust enums (exhaustivematchreplacesinstanceof). Immutability is by construction (owned fields, no mutation) — Java’sList.copyOfdefensive copies have no Rust analog. - cell_
diff - Table row/cell comparison — port of
cell-diff.ts/CellDiff.java.Object+instanceof Map/Listduck-typing becomes matching onValue. - conformance
- Projects pipeline output into the plain
Valuewire artifacts the conformance goldens pin — port ofconformance.ts/Conformance.java. Covers all four projections (var-doc, registry, plan, trace). - diagnostics
- Diagnostics produced by the planner — port of the subset of
diagnostics.tsthatPlanneeds /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 committedvarar.lock.jsonbaseline 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, authorAssertionError).Result/panic-catch replace throw;instanceofdispatch becomesmatch. - 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 (theAssertionError/Throwableparity channel);Futurereturns are driven by a small stdblock_on. State is aValue, replaced wholesale by each stimulus. - expression
- Cucumber-expression matching — the owned layer over the
cucumber-expressionscrate’s grammar parser. Replacesio.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, andparameter_type_names. - failure
- Converts a caught step failure into the structured
ExampleFailurepayload — port offailure.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.StepReturncarries the sync-or-Futurechannel (the analog of “anObjectthat might be aCompletableFuture”). - hash
- FNV-1a (32-bit) change-detector over UTF-16 code units — port of
hash.ts/Hash.java. Byte-identical across every port sovarar.lock.jsonfingerprints match. Thefnv1a: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 incrate::result, and the lock-file writer. - json_
value - A tiny recursive-descent JSON reader over the dynamic
Valuemodel. - 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 atHitconstruction). - 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/charare UTF-16 natively); Ruststris UTF-8, so byte offsets fromstr::find/theregexcrate 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:
scanthenstructure— port ofparse.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```errorfence, 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 ownedcrate::expressionlayer. Persistent-value semantics:add_step/define_parameter_typereturn a newRegistry; the argument is unchanged. - result
- Immutable run-result records — port of
result.ts/Result.java. The persisted.varar/<oath>.jsonfile is a serializedOathResults. - scanner
- Turns raw Markdown into a flat list of
Blocknodes — port ofscanner.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 onchars 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’sStepKind/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 ofstructurer.ts/Structurer.java. - table_
cells - Parses a Markdown/Gherkin table row (
| a | b |) into trimmed cells + each cell’s source span — port oftable-cells.ts/TableCells.java. - value
- The dynamic value model — the Rust replacement for Java varar-core’s
Objectwithinstanceof Map/List/Stringduck-typing (seeCellDiff.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.