Empty lines and comments are not the first thing that one models when creating a language since they do not have semantic meaning. However, they make lengthy root nodes much easier to deal with. Their contribution to the UX of a language cannot be underestimated.

MPS provides you with built-in (“generic”) comments and empty lines (called “generic placeholders”). You create a generic placeholder by pressing Ctrl/Cmd+Shift+Enter. If you also import jetbrains.mps.lang.text language into your model, you can type [ to convert the placeholder into a textual comment.

NOTE: MPS also provides generic functionality to comment out a piece of code, but for the sake of brevity I will not discuss it in this e-mail.

These placeholders are provided to you by MPS “for free”, you do not have to alter your language definition in any way to use them. However, language users have to pay for that by having to deal with a worse user experience.

The users have to remember to use the special key combination to insert them and the MPS editor treats empty lines and comments differently from the surrounding code. When selecting several statements to copy and paste, the comments are jumped over:

This is not just a visual quirk, copying the selection above and pasting it elsewhere results in comments being skipped:

Therefore, I recommend that you create custom concepts for empty lines and comments when you find that you need them. Your users will reward you with gratitude.

However, generic comments and placeholders are not all bad. Even though implementing custom placeholders is quite easy, adding them for each and every child collection is still unrealistic and infeasible. Generic comments and placeholders can be of a great help to language users in cases where the custom implementations are not available.

Tomorrow we will take a look at implementing custom empty lines and comments.