rune-langium / core/src / RuneDslParser
Class: RuneDslParser
Defined in: packages/core/src/services/rune-dsl-parser.ts:48
Custom Langium parser for the Rune DSL that normalizes lexer input to insert implicit [ and ] brackets around bare expressions after extract, filter, and reduce operators.
Remarks
In the original Xtext-based Rune DSL, extract/filter/reduce can accept both bracket-delimited inline functions (extract [body]) and bare expressions (extract FuncName(item)), using the => syntactic predicate to resolve the ambiguity. Langium's LL(k) parser (Chevrotain) cannot replicate this — adding both alternatives causes the parser builder to hang indefinitely during FIRST(k) set computation.
This class works around the limitation by transforming lexer input using the same scanner as insertImplicitBrackets: bare expressions after extract/filter/reduce are wrapped in [ and ] so the standard InlineFunction grammar rule handles them transparently. Lexer locations are mapped back before parsing, so the CST and all downstream source regions use the original text. Synthetic brackets have empty images and zero-width CST ranges.
Pitfalls
- The text pre-processor is regex-based and operates on raw source text before tokenization. It cannot correctly handle multi-line bare expressions that span a block boundary — always use explicit
[]brackets in those cases. - Do NOT regenerate
ast.tswhile TypeScript is watching the project — the generated file will be partially written and TypeScript will pick up an inconsistent version, causing spurious type errors. Stop the watcher first, regenerate, then restart.
Use When
- This is used automatically by
createRuneDslServices()— you do not need to instantiate it directly.
Avoid When
- Subclassing for grammar experiments — prefer creating a separate grammar variant and a new services container instead.
See
Extends
LangiumParser
Constructors
Constructor
new RuneDslParser(services): RuneDslParser;Defined in: packages/core/src/services/rune-dsl-parser.ts:51
Parameters
| Parameter | Type |
|---|---|
services | LangiumCoreServices |
Returns
RuneDslParser
Overrides
LangiumParser.constructor
Properties
| Property | Modifier | Type | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|
_unorderedGroups | protected | Map<string, boolean[]> | - | LangiumParser._unorderedGroups | node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:89 |
allRules | protected | Map<string, RuleResult> | - | LangiumParser.allRules | node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:90 |
lexer | protected readonly | Lexer | LangiumParser.lexer | - | packages/core/src/services/rune-dsl-parser.ts:49 |
mainRule | protected | RuleResult | - | LangiumParser.mainRule | node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:91 |
wrapper | protected readonly | ChevrotainWrapper | - | LangiumParser.wrapper | node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:88 |
Accessors
definitionErrors
Get Signature
get definitionErrors(): IParserDefinitionError[];Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:152
Returns
IParserDefinitionError[]
Inherited from
LangiumParser.definitionErrors
unorderedGroups
Get Signature
get unorderedGroups(): Map<string, boolean[]>;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:103
Current state of the unordered groups
Returns
Map<string, boolean[]>
Inherited from
LangiumParser.unorderedGroups
Methods
action()
action($type, action): void;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:146
Parameters
| Parameter | Type |
|---|---|
$type | string |
action | Action |
Returns
void
Inherited from
LangiumParser.action
alternatives()
alternatives(idx, choices): void;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:93
Performs alternatives parsing (the | operation in EBNF/Langium)
Parameters
| Parameter | Type |
|---|---|
idx | number |
choices | IOrAlt<any>[] |
Returns
void
Inherited from
LangiumParser.alternatives
atLeastOne()
atLeastOne(idx, callback): void;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:96
Parses the callback 1 or more times (the + operation in EBNF/Langium)
Parameters
| Parameter | Type |
|---|---|
idx | number |
callback | DSLMethodOpts<unknown> |
Returns
void
Inherited from
LangiumParser.atLeastOne
consume()
consume(
idx,
tokenType,
feature
): void;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:136
Parameters
| Parameter | Type |
|---|---|
idx | number |
tokenType | TokenType |
feature | AbstractElement |
Returns
void
Inherited from
LangiumParser.consume
finalize()
finalize(): void;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:105
Returns
void
Inherited from
LangiumParser.finalize
getRule()
getRule(name): RuleResult | undefined;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:101
Returns the executable rule function for the specified rule name
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
RuleResult | undefined
Inherited from
LangiumParser.getRule
getRuleStack()
getRuleStack(): number[];Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:104
The rule stack indicates the indices of rules that are currently invoked, in order of their invocation.
Returns
number[]
Inherited from
LangiumParser.getRuleStack
isRecording()
isRecording(): boolean;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:102
Whether the parser is currently actually in use or in "recording mode". Recording mode is activated once when the parser is analyzing itself. During this phase, no input exists and therefore no AST should be constructed
Returns
boolean
Inherited from
LangiumParser.isRecording
many()
many(idx, callback): void;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:95
Parses the callback 0 or more times (the * operation in EBNF/Langium)
Parameters
| Parameter | Type |
|---|---|
idx | number |
callback | DSLMethodOpts<unknown> |
Returns
void
Inherited from
LangiumParser.many
optional()
optional(idx, callback): void;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:94
Parses the callback as optional (the ? operation in EBNF/Langium)
Parameters
| Parameter | Type |
|---|---|
idx | number |
callback | DSLMethodOpts<unknown> |
Returns
void
Inherited from
LangiumParser.optional
parse()
parse<T>(input, options?): ParseResult<T>;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:124
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends AstNode | AstNode |
Parameters
| Parameter | Type |
|---|---|
input | string |
options? | ParserOptions |
Returns
ParseResult<T>
Inherited from
LangiumParser.parse
rule()
rule(rule, impl): RuleResult;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:121
Parameters
| Parameter | Type |
|---|---|
rule | ParserRule | InfixRule |
impl | RuleImpl |
Returns
RuleResult
Inherited from
LangiumParser.rule
subrule()
subrule(
idx,
rule,
fragment,
feature,
args
): void;Defined in: node_modules/.pnpm/[email protected]/node_modules/langium/lib/parser/langium-parser.d.ts:144
Parameters
| Parameter | Type |
|---|---|
idx | number |
rule | RuleResult |
fragment | boolean |
feature | AbstractElement |
args | Args |
Returns
void
Inherited from
LangiumParser.subrule