Expand description
§kip — engineering expression evaluator (US imperial)
kip is a pure, thread-safe evaluator for engineering expressions with exact rational arithmetic, partial (symbolic) evaluation, and a user-extensible unit registry anchored to inch, lbf, second, Rankine (plus angle and custom base dimensions).
§Force-based (gravitational) system
kip uses a force-based dimensional system common in structural engineering:
Force is a base dimension (anchor: lbf), and mass is derived
(slug = lbf·s²/ft). There is no hidden gc constant in user-visible
math. SI-trained users: do not expect mass to be fundamental here.
§Typical workflow
- Build or load a
Registry(RegistryBuilder::from_seed,RegistryBuilder::parse_defs,RegistryBuilder::load_packs). parsean expression against that registry (optionalResolverfor symbols).evalto aValue— fullyQuantityoreval::value::SymExprresidual.- Format with
Quantity::displayandFmtOptions, or bind further withValue::bind.
§Concurrency (P1)
ASTs (Expr), registries (Registry), and evaluation are immutable and
Send + Sync. Evaluation is a pure function — no globals, no locks.
With the parallel feature: eval_batch, eval_scenarios, and intra-expression
rayon splits above PARALLEL_THRESHOLD nodes.
§Code equations (P2)
Namespaced calls such as ACI.fr(fc: 4000 psi, lambda: 1.0) require named arguments.
Load pack TOML via RegistryBuilder::load_packs or load_packs; results carry
EquationProvenance on Quantity.
§Version 0.1.0
Full grammar conformance (lexer → packs → parallel/fmt). See CHANGELOG.md and
VERSIONING.md for release policy.
Macros§
- qty
- Macro helper for tests and registry builder (exact integer magnitudes).
Structs§
- Constraint
Set - Dimension constraints accumulated over free symbols.
- Custom
DimId - Identifier for a user-declared base dimension (e.g.
dimension Currency). - Diag
- Primary error type returned by parse/eval APIs.
- Diagnostic
- A single diagnostic message.
- Dimension
- A dimension as a sorted map of base dimension → rational exponent.
- Empty
Resolver - Resolver that never binds symbols.
- Equation
Provenance - Provenance for a quantity produced by a code equation.
- Equation
Record - One equation loaded from a pack (pre-parsed body, frozen contracts).
- Equation
Registry - Immutable index of equations for one registry generation.
- Eval
Outcome - Result of checked evaluation (value + non-fatal lints).
- Expr
- Frozen expression tree.
- Expr
Node - Single AST node with span.
- FmtOptions
- Formatting options for quantity display.
- LexOutcome
- Outcome of lexing with non-fatal lints.
- Lint
Sink - Collects evaluation lints with de-duplication policy for exactness loss.
- MapResolver
- Simple map-backed resolver for tests and examples.
- NodeId
- Stable node identifier within an expression arena.
- Parse
Outcome - Outcome of parse-with-lints API.
- Quantity
- A unit-preserving engineering quantity.
- Registry
- Immutable frozen registry (generation N).
- Registry
Builder - Mutable registry builder; freezes into immutable
Registry. - Span
- Byte offset range in source text (half-open
[start, end)). - Spanned
Token - A token with its source span.
- SymExpr
- Symbolic residual expression (M5).
- Symbol
- A free symbol name in a partial evaluation residual.
Enums§
- BaseDim
- Fundamental dimension in the force-based imperial system.
- Binary
Op - Binary operators in expression context.
- CallArg
- Call argument (positional or named).
- Callee
- Function or code-equation callee.
- CmpOp
- Comparison operators (reserved v1.1).
- Error
Code - Structured error codes (grammar-spec §9 + plan §5.3 extensions).
- Expr
Kind - Expression node kinds (grammar §5.2).
- Hint
- Optional structured hint for IDEs and calc sheets.
- Lint
Code - Lint codes (non-fatal).
- Mag
- Magnitude of a quantity: exact rational, or float after exactness loss.
- Severity
- Diagnostic severity.
- SymBinary
Op - Binary operators in symbolic residuals.
- SymNode
- Node in a symbolic expression tree.
- SymUnary
Op - Unary operators in symbolic residuals.
- Token
- Lexer token (grammar-spec §3).
- UnaryOp
- Unary operators.
- Unit
Exponent - Exponent on a unit factor (
ft^2,psi^(1/2),psi^0.5). - Unit
Expr - A unit expression preserving user syntax (e.g.
kip·ft,lbf/ft^2). - Value
- Result of evaluation: fully known or partially symbolic.
Constants§
- DEMO_
PACK_ TOML - Liberally licensed demo pack for tests and documentation.
- PARALLEL_
THRESHOLD - Minimum subtree node count before
rayon::joinsplits siblings (M7). - VERSION
- Crate version string (matches
Cargo.toml).
Traits§
- Resolver
- Resolve free symbols to known or symbolic values during parse/eval.
Functions§
- convert_
quantity - Convert a quantity to another unit expression (same dimension).
- eval
- Evaluate a parsed expression against a frozen registry and symbol resolver.
- eval_
batch - Evaluate many independent expressions concurrently (M7).
- eval_
checked - Evaluate and collect lints (mirror of
lex_checked/parse_checked). - eval_
scenarios - Evaluate one expression under many resolver scenarios (M7).
- format_
quantity - Format a quantity per options (never mutates the input quantity).
- lex
- Lex source into tokens; returns error on first hard lex failure.
- lex_
checked - Lex source, collecting lints and continuing past non-fatal issues where possible.
- load_
packs - Parse TOML packs into a standalone equation registry (units must already exist).
- load_
packs_ into - Load equation packs into a registry builder (also ingests optional
[defs]). - parse
- Parse source into an immutable shared AST (M3).
- parse_
checked - Parse with resolver-aware shadow lints (M3).
Type Aliases§
- LexSpan
- Lexer span type (alias for
crate::diag::Span).