-
Notifications
You must be signed in to change notification settings - Fork 86
Description
Langium version: 4.1.2
Package name: langium
Steps To Reproduce
- Have a infix rule which with an explicit return type with a name different from the rule name.
- The
$typeproperty of the AstNode is the name of the rule, not the name of the return type.
Grammar example:
grammar HelloWorld
entry Model:
expression=OperatorExpression;
interface BaseExpression {}
interface IdExpression extends BaseExpression {
id: string;
}
interface ComplexExpression extends BaseExpression {
operator: string;
left: BaseExpression;
right: BaseExpression;
}
IdExpression returns IdExpression:
id=ID;
infix OperatorExpression on IdExpression returns ComplexExpression:
'%'
> '^'
> '*' | '/'
> '+' | '-';
BOOLEAN returns boolean:
'true' | 'false';
hidden terminal WS: /\s+/;
terminal ID: /[_a-zA-Z][\w_]*/;
hidden terminal ML_COMMENT: /\/\*[\s\S]*?\*\//;
hidden terminal SL_COMMENT: /\/\/[^\n\r]*/;
Code to parse:
a + b
The current behavior
The AstNode for the + expression has $type: "OperatorExpression"
The expected behavior
The AstNode for the + expression has $type: "ComplexExpression"
Suspected cause
computeRuleType in langium-parser.ts directly returns rule.name for the infix case, ignoring the explicit return type.
Possible solution
Use the same logic in the infix case as in the else case at the end.
Note: the type is still used for the operatorPrecedence lookup, there, the rule name should still be used (which must thus be passed through in addition to the type).
Metadata
Metadata
Assignees
Labels
No labels