Child pages
  • Shapes - an introductory MPS tutorial

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info

If you misspelled the name of the concept and decide to change it, MPS will prompt you, whether you want to do a proper rename re-factoring, in order to update all possible references and usages of the concept in other parts of your code. Since we've just started and have no references to Shape, just hit the "No" buttonjust go ahead and change it. Renaming things in MPS is just as easy.

It is the time to practice the Alt + Enter keyboard shortcut now.

...

Now our language needs a way to indicate the desired color of a shape in our code. Thus Shape should be referring to one of the color constants in the accessory model of the Shapes language. MPS will automatically populate the completion menu with all available color constants, whenever the user is about to specify a color for a Shape.

Create a new concept in the Structure aspect model:

ColorReference keeps a reference (a pointer going across the AST hierarchy) pointing to a single color constant (node of the Color concept).

...

Let's start with the class for Canvas. You need to add a new entry in the root mapping roles, since Canvas is a root concept. Hit Enter to insert a new empty rule:

This will indicate that Canvas nodes should be replaces with a Java class. You need to use an Intention (Alt + Enter) the be able to select "New Root Template" from the pop-up menu.

This rule defines that a Canvas node should be replaced with a Java class. The template defines with what class:

The root template should be generating a Java class, so you need to pick "class".

...