This site describes solve-engine as it is on main: 2.43.0, which npm does not have yet. npm installs 2.40.0, so a page may show an answer that version does not give yet.
PrecedenceParser
Defined in: packages/engine/src/parser/PrecedenceParser.ts:59
── Hybrid Precedence Climbing Parser ─────────────────────────────────────────
Two-tier dispatch strategy:
Tier 1 (Fast Path): Inline switch on token.typeId for built-in operators. - Prefix: NUMBER, IDENT, LPAREN, MINUS, PLUS, STRING - Infix: checked via static BP_TABLE (Uint8Array indexed by typeId) - No Map.get(), no parselet function call overhead for ~95% of tokens
Tier 2 (Plugin Path): ParseletRegistry fallback for custom/plugin tokens. - Prefix: Map.get(tokenTypeId) for PrefixParselet - Infix: Map.get(tokenTypeId) for InfixParselet - Full flexibility for custom syntax
The parser emits directly to a BytecodeBuilder, no AST intermediate. Implements the same public API as the legacy Parser class so existing parselets continue to work without modification.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PrecedenceParser( parseletRegistry, maxDepth?, localeCode?, pluginFunctionIndex?, calendar?): PrecedenceParser;Defined in: packages/engine/src/parser/PrecedenceParser.ts:172
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
parseletRegistry | ParseletRegistry | undefined |
maxDepth | number | 50 |
localeCode | string | "en" |
pluginFunctionIndex? | ReadonlyMap<string, number> | undefined |
calendar? | CalendarBackend | DATE_CALENDAR |
Returns
Section titled “Returns”PrecedenceParser
Properties
Section titled “Properties”infixMinBindingPower
Section titled “infixMinBindingPower”infixMinBindingPower: number = 0;Defined in: packages/engine/src/parser/PrecedenceParser.ts:100
The binding power the current infix parselet is being invoked at, i.e. the
minBp of the expression it sits inside. Set immediately before each Tier-2
parselet runs. A parselet that decides whether to swallow a following
loose operator (UomLiteralParselet with a trailing in/to) reads this to
respect precedence it cannot otherwise see: 120 km / 2 hours in kph must
group as (120 km / 2 hours) in kph, not 120 km / (2 hours in kph).
BP_TABLE
Section titled “BP_TABLE”readonly static BP_TABLE: Uint8Array;Defined in: packages/engine/src/parser/PrecedenceParser.ts:121
Static binding power table, built once at module load, shared across all instances. Index = tokenTypeId, value = binding power (0 = not a built-in infix).
Methods
Section titled “Methods”consume()
Section titled “consume()”consume(expectedType?): Token;Defined in: packages/engine/src/parser/PrecedenceParser.ts:1026
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
expectedType? | string |
Returns
Section titled “Returns”getCalendar()
Section titled “getCalendar()”getCalendar(): CalendarBackend;Defined in: packages/engine/src/parser/PrecedenceParser.ts:202
The calendar backend a parselet reads a date with at parse time: the engine’s own, so a fused literal reads back through the backend that built it. See the field’s doc for the sites that need it.
Returns
Section titled “Returns”getLocaleCode()
Section titled “getLocaleCode()”getLocaleCode(): string;Defined in: packages/engine/src/parser/PrecedenceParser.ts:193
Get locale code for NumberParselet to normalize separators
Returns
Section titled “Returns”string
load()
Section titled “load()”load(tokens, hasParens?): void;Defined in: packages/engine/src/parser/PrecedenceParser.ts:220
Load tokens for parsing. Identical to Parser.load().
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
tokens | Token[] | - |
hasParens? | boolean | if false, skips the O(n) paren balance scan (~90% of expressions) |
Returns
Section titled “Returns”void
match()
Section titled “match()”match(expectedType): boolean;Defined in: packages/engine/src/parser/PrecedenceParser.ts:1052
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
expectedType | string |
Returns
Section titled “Returns”boolean
parseExpression()
Section titled “parseExpression()”parseExpression(minBp?, _builder?): void;Defined in: packages/engine/src/parser/PrecedenceParser.ts:290
Parse a full expression starting at the current token position.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
minBp | number | 0 | minimum binding power (precedence climbing threshold). For left-associative operators, the recursive call uses bp + 1. For right-associative operators (^), it uses bp - 1. |
_builder? | BytecodeBuilder | undefined | accepted for parselet API compatibility; always uses this.builder. |
Returns
Section titled “Returns”void
peek()
Section titled “peek()”peek(): Token | undefined;Defined in: packages/engine/src/parser/PrecedenceParser.ts:1061
Returns
Section titled “Returns”Token | undefined
peekAt()
Section titled “peekAt()”peekAt(offset): Token | undefined;Defined in: packages/engine/src/parser/PrecedenceParser.ts:1085
Read-only lookahead offset tokens past the current position, without
consuming anything, peekAt(0) is equivalent to peek.
this.tokens is a plain in-memory array (not a stream), so this is a
simple, safe index read; no rewind/checkpoint mechanism is needed since
nothing is consumed.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
offset | number |
Returns
Section titled “Returns”Token | undefined
previous()
Section titled “previous()”previous(): Token | undefined;Defined in: packages/engine/src/parser/PrecedenceParser.ts:1089
Returns
Section titled “Returns”Token | undefined
setBuilder()
Section titled “setBuilder()”setBuilder(builder): void;Defined in: packages/engine/src/parser/PrecedenceParser.ts:1102
Set the builder to use for the current parse. Called by ExpressionEngine.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
builder | BytecodeBuilder |
Returns
Section titled “Returns”void
setDiagnosticPipeline()
Section titled “setDiagnosticPipeline()”setDiagnosticPipeline(pipeline, expression): void;Defined in: packages/engine/src/parser/PrecedenceParser.ts:210
Set the diagnostic pipeline for parselet matching events. Cleared after each non-cached parse to avoid holding refs.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
pipeline | DiagnosticPipeline | undefined |
expression | string |
Returns
Section titled “Returns”void