Skip to content

rune-langium / core/src / parseExpression

Function: parseExpression() ​

ts
function parseExpression(text): ExpressionParseResult;

Defined in: packages/core/src/api/parse-expression.ts:69

Synchronously parse a bare Rune DSL expression snippet (e.g. a Condition, Operation, or ShortcutDeclaration body) into a typed RosettaExpression.

Parameters ​

ParameterType
textstring

Returns ​

ExpressionParseResult

Remarks ​

Parses from the grammar's ExpressionWithAsKey rule via Langium's LangiumParser.parse(text, { rule }) — no document, no DocumentBuilder, no linking pass. ExpressionWithAsKey is a strict superset of Expression (its trailing as-key is optional), so it covers all three body forms. The project's RuneDslParser applies implicit-bracket insertion to the input, exactly as it does for full documents.

Use When ​

  • Parsing an expression body in isolation (editor previews, round-trip tests)
  • Validating user-typed expression text without a synthetic wrapper document

Avoid When ​

  • You need resolved cross-references — use parse()/parseWorkspace() with a full document instead.

Pitfalls ​

  • Cross-references are NEVER resolved: a bare snippet has no scope at all, so ref is always undefined — only $refText carries the name. This is stronger than parse()'s cross-file caveat.
  • Error offsets refer to the implicit-bracket-transformed text, which can differ slightly from the input (same behavior as parse()).

Example ​

ts
import { parseExpression } from '@rune-langium/core';
const r = parseExpression('quantity > 0 and price exists');
if (!r.hasErrors) console.log(r.value.$type); // 'LogicalOperation'

Core packages released under MIT. Studio app released under FSL-1.1-ALv2.