Skip to content

rune-langium / core/src / insertImplicitBrackets

Function: insertImplicitBrackets() ​

ts
function insertImplicitBrackets(text): string;

Defined in: packages/core/src/services/rune-dsl-parser.ts:242

Scans Rune DSL source text and inserts [ and ] around bare expressions that follow extract, filter, or reduce operators.

Parameters ​

ParameterTypeDescription
textstringRaw Rune DSL (.rosetta) source text.

Returns ​

string

Transformed text with implicit brackets inserted where needed.

Remarks ​

This is a pure text transformation applied before Chevrotain tokenization. It normalizes both forms — extract [body] (explicit) and extract expr (bare) — into the extract [body] form that the Langium grammar expects.

Algorithm:

  1. Scan character-by-character, skipping strings and comments
  2. When a functional operator keyword is found: a. Check if followed by [ — if so, skip (already InlineFunction) b. Check if followed by ID [ or ID , — if so, skip (closure param form) c. Otherwise, insert [ before the bare expression and ] at its end
  3. Expression end is determined by tracking nesting depth and looking for terminators (comma, closing bracket, newline + statement keyword)

Multi-line support: when the keyword is at end of line (followed by newline + whitespace), we look at the next line. If it starts with an expression token (ID, (, -, +, etc.) and NOT a statement keyword, we treat the next line as the start of a bare expression.

Pitfalls ​

  • The transformation is regex/character-scan based and cannot handle all edge cases in heavily nested multi-line expressions. When in doubt, use explicit [ ] brackets in your .rosetta source.
  • Do NOT call this function on arbitrary text — it is designed specifically for Rune DSL (Rosetta) source and may corrupt non-Rosetta input.

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