-
I need to parse the following code:
Here is the grammar:
I get the following AST:
But I need kind attribute to have one of the values: 'Regular', 'Abstract' or 'Interface'. How to implement it in Langium? |
Beta Was this translation helpful? Give feedback.
Answered by
AresEkb
May 1, 2025
Replies: 1 comment 4 replies
-
Hey @AresEkb, doing that with enum-like types isn't possible. You could do something different however:
That should resolve this issue within the type system by giving you |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the following grammar works fine for me:
I can automatically transform an AST node of the form
{ "$type": "ClassKind_Regular" }
to a enum literalClassKind::Regular
. So we don't have to implement a custom AST <-> model mapping for each grammar and metamodelAnd also such a grammar works fine for code printing (AST to code transformation)