MPS
 
Get MPS

Editor cookbook

Last modified: 11 February 2024

This document, intended for advanced language designers, should give you the answers to the most common questions related to the MPS editor. You may also like to read the Editor documentation, which contains exhaustive information on the subject.

To enter such variable declaration, you can always pick the variable concept (by its alias) from the completion menu and then fill in the name:

var1.png
var2.png
var3.png

You can, however, add a simple substitution action into the substitution menu that will enable users to simply type the desired name of the variable on the empty line and have the variable created for you automatically:

var5.png
var6.png

The menu may look something like this:

var7.png
  1. It can be substituted whenever a non-empty pattern has been typed and it does not match an alias of any of the known sub-concepts applicable in the position

  2. A new node is created when the action is run and the pattern is copied into the name of the variable

  3. The "selection handler" ensures that the cursor stays within the "name" cell after creating the variable so that the user can continue typing the name even after the variable has already been created (it is created as soon as there is no other option in the completion menu (the "selection handler" returns null, since when a non-null node is returned, MPS places the caret itself on the returned node and ignores the "select" command)

You may also experiment with checking the "strictly" flag to further customize the behavior:

var4.png

Here's the menu:

var8.png

Changes:

  1. The description provides a customized description message to display in the completion menu alongside the "variable" alias

  2. The pattern ensures the so far typed text is suggested as the name of the variable to be created (when the code-completion menu is visible)

  3. The can substitute handler reacts to the value of the strictly parameter, so that as long as there are other subconcepts available in the menu this action is also available, but only for non-strict matching.