rune-langium / core/src / insertImplicitBrackets
Function: insertImplicitBrackets()
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
| Parameter | Type | Description |
|---|---|---|
text | string | Raw 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:
- Scan character-by-character, skipping strings and comments
- When a functional operator keyword is found: a. Check if followed by
[— if so, skip (alreadyInlineFunction) b. Check if followed byID [orID ,— if so, skip (closure param form) c. Otherwise, insert[before the bare expression and]at its end - 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.rosettasource. - Do NOT call this function on arbitrary text — it is designed specifically for Rune DSL (Rosetta) source and may corrupt non-Rosetta input.