Module parser

Module parser 

Source
Expand description

Pest-backed parser with full source-side expression support.

Two public entry points:

  • parse_quantity turns a user input like "10 kg*m/s^2", "5 m + 3 ft", or "sqrt(9 m^2)" into a Quantity by parsing it into an [Expr] AST and evaluating under a default EvalContext. This is a thin wrapper around parse_and_eval.
  • parse_unit_name takes a bare unit expression like "m/s" or "kg*m/s^2" and resolves it to a composed Unit. Target-side parsing stays pure โ€” no math, no identifiers beyond unit names.

Grammar lives in grammar.pest. Expression grammar is documented there; the AST walker lives in crate::expr and the tree walker / evaluator lives in crate::eval.

Structsยง

QuantityParser

Enumsยง

Rule

Constantsยง

_PEST_GRAMMAR_QuantityParser ๐Ÿ”’

Functionsยง

check_affine_composition ๐Ÿ”’
Check that neither operand is affine before composing.
parse_and_eval
Parse an expression and evaluate it under a caller-provided context.
parse_quantity
Parse a full quantity string and evaluate it under a default context.
parse_unit_name
Parse a bare unit expression (e.g. "m/s", "kg*m/s^2").
resolve_unit_expr ๐Ÿ”’
Recursively resolve a pest unit_expr parse tree into a composed Unit.