eclipse / epsilon

Epsilon is a family of Java-based scripting languages for automating common model-based software engineering tasks, such as code generation, model-to-model transformation and model validation, that work out of the box with EMF (including Xtext and Sirius), UML (including Cameo/MagicDraw), Simulink, XML and other types of models.
https://eclipse.org/epsilon
Eclipse Public License 2.0
55 stars 11 forks source link

Add support for ATL-style partial enumeration literals #42

Closed agarciadom closed 12 months ago

agarciadom commented 1 year ago

This pull request adds support for partial enumeration literals, in the style of ATL. If you have a model M with a TrafficLight from package traffic with a state which can take the enumeration value RED, now you can use:

The new logic is distributed between several places:

The EOL grammar was changed to support these new enumeration literals. The enum part of the pathName rule was dropped, leaving it as just:

pathName
    :   (metamodel=NAME '!'!)?
        head=packagedType^
        {
            if ($metamodel != null) {
                $head.tree.token.setText(metamodel.getText() + "!" + $head.tree.token.getText());       
            }
        }
    ;

A new enumLiteral rule was added:

enumLiteral
    : (metamodel=NAME '!'!)? (typename=packagedType)? '#'! label=NAME^
    {
        $label.tree.token.setType(ENUMERATION_VALUE);
        $label.tree.token.setText('#' + $label.tree.token.getText());
        if (typename != null) {
            $label.tree.token.setText(typename.tree.token.getText() + $label.tree.token.getText());
        }
        if ($metamodel != null) {
            $label.tree.token.setText($metamodel.getText() + '!' + $label.tree.token.getText());
        }
    }
    ;

A bit of custom lookahead was needed to resolve the ambiguity between enumLiteral, featureCall, and pathName:

primitiveExpression 
    :   literalSequentialCollection | literalMapCollection | literal
        | ((NAME '!')? packagedType? '#') => enumLiteral
        | featureCall | collectionType |
        pathName | specialType | logicalExpressionInBrackets | newExpression | variableDeclarationExpression
    ;
agarciadom commented 1 year ago

Tests passed on Jenkins and on my local Eclipse install (both the EpsilonEclipseTestSuite and the plugged-in tests).

@kolovos could you give the PR a look?