Child pages
  • Shapes - an introductory MPS tutorial

Versions Compared

Key

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

...

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

Can you see the light-bulb symbol on the first line of the concept declaration? (You may need to move your cursor to the first line for the light-bulb to show up. It is a bit shy.) The light-bulb is hiding a contextual menu with tips of what you can possibly do to your code at the cursor position. Alt + Enter gives you access to the light-bulb menu (we call it Intentions menu) from the keyboard.


When positioned on the name of the Concept, the Alt + Enter keyboard shortcut brings up a contextual pop-up menu, which gives you the option to apply the "Make Abstract" intention to the Concept. Once you choose that option, the concept is marked as abstract. Now we could add properties, children and references that should be shared by all sub-concepts of Shape, but we will leave that for later to make our learning curve flat.

...

Circles should inherit capabilities from Shape, so we need to indicate than in the extends clause. Position the cursor at the beginning of the cell holding the "BaseConcept" text and hit the most useful keyboard shortcut in MPS - Control + Space - to invoke code completion.
Image RemovedMPS  MPS will show you a list of options applicable as replacements for the "BaseConcept" text. We need to select select Shape here to make make Circle extend  extend Shape.
Image Added

If you do not see Shape in the completion menu, it is because your cursor in not on the first position of the word.

Image Added

The characters to the left of the cursor are used as a filter to show only options that match the these characters. The further to the right your cursor goes, the fewer options will be displayed in the completion menu.

Image Added

You have to move your cursor with the left arrow or, if you press Control + Space again, MPS will move the cursor to the very left of the current word for you.


So this is our first concrete concept that will be used by users of our language. To give the concept a nice textual representation in code-completion dialogs and enable MPS to be smart about creating an instance of Circle whenever the user types "circle", you need to give the concept an alias 'circle'.

...