Features

Generic support for commenting out nodes in MPS

MPS now provides a universal way to comment out nodes in models. In previous versions  this functionality had to be implemented in all languages separately, either through node attributes or dedicated “comment” nodes. In 3.3 the information about a node being commented out is stored in the model in a generic way. The smodel language ignores commented out nodes by default so that your queries do not have to filter out commented out nodes explicitly.

Additionally, actions have been created to comment/uncomment out a node.

How to use it

You can select any node in MPS, except roots, and press ctrl/cmd + “/”. That node will be commented out.

Let’s watch some examples.

You can comment out an IfStatement’s condition

a method parameter

a variable type

an editor cell

In fact, every single node can be commented out.

To uncomment the node you simply press ctrl/cmd + “/” on commented node.

How does it work in the model

When one comments out the node, it is placed as a child (wrapped) in a special “child attribute”, called BaseCommentAttribute. Then the instance of this attribute is attached to the commented node’s link in the former parent of the commented node.

The child attribute is the same as the link attribute, but the child attribute is attached to the aggregation link.

So the commented nodes are not stored as the usual children, and they won’t appear in queries like node.children, node.descendants, etc.

But the MPS editor knows about comments and it will draw both children and the commented nodes, in this role.

Customization

By default every commented node is drawn surrounded by /* */ . You can define a custom commented editor for the concept.

Just define the usual editor with the hint “comment”.

Note that the children of the commented node should be drawn with their usual editor so you need to remove the comment hint in child cells

Also you can override the comment action in the editor.

For example, we don’t want the %expression% in the ExpressionStatement to be commented out ever.  We want the whole statement to be commented out instead.

So we define the action map for the ExpressionStatement and attach it to the child %expression% cell.

Since can execute block returns false, the COMMENT action will not be executed on %expression% cell. MPS will try to execute the COMMENT action on parent cell, and then the whole statement will be commented out.

Update: A dedicated documentation page is now available in the User Guide. A short video has been published.

image description