Skip to content
Discussion options

You must be logged in to vote

I think the following grammar works fine for me:

grammar ClassModel

entry ClassModel:
    classes+=Class*;

Class:
    kind=ClassKind name=ID;

ClassKind:
    {infer ClassKind_Regular} 'class' |
    {infer ClassKind_Abstract} 'abstract' 'class' |
    {infer ClassKind_Interface} 'interface';

hidden terminal WS: /\s+/;
terminal ID: /[_a-zA-Z][\w_]*/;

I can automatically transform an AST node of the form { "$type": "ClassKind_Regular" } to a enum literal ClassKind::Regular. So we don't have to implement a custom AST <-> model mapping for each grammar and metamodel

And also such a grammar works fine for code printing (AST to code transformation)

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@AresEkb
Comment options

@AresEkb
Comment options

@AresEkb
Comment options

Answer selected by AresEkb
@msujew
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants