Create a parser with optional cache limits. Omitted options share the default configuration. Separately supplied option objects isolate retention; passing an already resolved configuration reuses it.
Optionalconfig: ParserConfigInputEstimated retained expression plans and limits; excludes the separate token cache.
Immutable effective parser settings.
Release expression plans shared by this configuration; does not clear token or Quantity result caches.
Parse and evaluate a complete scalar/unit expression.
Expression supporting products, division, powers, groups, scientific notation, and Unicode multiplication/superscript notation.
Adapter used to evaluate scalars; supplied automatically by a configured Quantity.
Optionalscope: CacheScope
Optional Quantity cache scope; wrappers should forward it unchanged.
Optionalscalar: T
Optional replacement scalar. The parser validates the units and skips scalar evaluation.
A fresh definition with a backend scalar and frozen counted units. Unit arrays may be shared with cached plans.
QuantityParseError for invalid or incomplete syntax, unknown units, invalid exponents, and scalar-evaluation failures.
Parse without throwing for syntax or expression-evaluation failures.
Complete scalar/unit expression.
Backend used to evaluate the scalar.
A definition on success, or a structured error at the original location.
Like parse, this does not check absolute-temperature physics;
construct a Quantity from the successful definition for those checks.
import { PrattParser } from '@neutrium/quantity/parsers/pratt';
import { Quantity } from '@neutrium/quantity/number';
const result = new PrattParser().tryParse('kg/(m*s', new Quantity(1).numeric);
if (!result.success) {
result.error.code; // "UNEXPECTED_END"
result.error.offset; // 7 (the end of the input)
result.error.expected; // [')']
}
Parser for scalar products/division, compound units, powers, and nested groups. Powers bind first, then dot products; * / and whitespace evaluate left to right. Compiled expression plans are shared within a configuration; scalar evaluation follows the original operation order and the selected numeric adapter on every call.