Create structure and items, then refer them

I want to create a language where I can define some structure-like containers. In this example, I want MyOperation to refer a previously defined container, and Uses to be a list of Element from it (in this case, MyContainer A). I'm trying to help domain experts to be able to define these containers by helping them with autocomplete, etc.

MyContainer A {
Element a
Element b
}
MyContainer B {
Element c
Element d
}
MyOperation op {
Refers :  A
Uses {
a, b
}
}

How can this be accomplished? 

1
3 comments
Official comment

Hi Leonardo,

this is pretty easy to achieve with references and scoping. Perhaps you should investigate https://confluence.jetbrains.com/display/MPSD20181/Scopes.

Additionally, you may learn about scoping from the Calculator tutorial - https://confluence.jetbrains.com/display/MPSD20181/Fast+Track+to+MPS#FastTracktoMPS-Step8-Calculatortutorial

Cheers,

Vaclav

By the way, I'm trying using contraints and references but there is little documentation and it all appears to be out of date (i.e., enclosingNode, etc.)

0

Also, with your MPS Installation, there should come a bunch of example projects: /Users/you/MPSSamples201X.Y.Z

The examples projects "stateChart" and "componentDependency" might also be worth a look, since they are similar in structure at least.

0

Please sign in to leave a comment.