Plugin spotlight: Generate Python or Ruby with MPS-plaintextgen

The guys of DSLFoundry have brought my attention to the MPS-plaintextgen plugin recently. The plugin offers a language that models textual documents as collections of lines and words, supports layouts, alignment and indentation, and in addition to that, it comes with decent editing experience built in.

The binaries of the plugin can be obtained from the JetBrains plugin repository.

The language is primarily meant to be used in generators to ease transformation of complex models into text. Unlike with the TextGen aspect in MPS, the plaintextgen language allows you to leverage the model-to-model capabilities of the MPS Generator and enjoy the comfort of the projectional editor when defining the transformations. You simply model the output document and parametrize it with values from the input model.

This can be useful in several interesting ways:

  • generate textual documents from your models without the need for TextGen
  • quickly mock the generator for your prototype languages during development
  • generate code of limited complexity in general-purpose languages, for which MPS does not have support

As a proof-of-concept, I’ve created a sample project that uses the MPS plaintextgen language to generate Python and Ruby as well as plain text. You can check out the MultiLangEntities project on GitHub.

ml4

ml1

The Drive to Develop
-JetBrains MPS Team

This entry was posted in Announcement, Feature and tagged , , . Bookmark the permalink.

4 Responses to Plugin spotlight: Generate Python or Ruby with MPS-plaintextgen

  1. Very interesting, I also tried it for a while.
    But not so user friendly, at least to me (or maybe because I lack of experience with MPS?): after many tries I just cannot format the output as I need (for example, the loop always outputs in a single line: how can I add a newline at the end of each iteration?)
    However, the idea behind the plugin seems to me very useful: I’m trying to write an editor for chatbot rules and the language is not Java…
    Thank you for your answer

    • Remi Bosman says:

      If you struggle with manual editing of plaintextgen models then switching to the structural view may help. Right-click anywhere in the model –> Push Editor Hints –> com.dslfoundry.plaintextgen –> Structural: View under-the-hood structure.

      This view is less compact but provides explicit boundary markers which makes it significantly easier to insert new lines or words at specific places.

  2. Well, I found the way to include the carriage return: it’s simple, (just highlight also the CR before sorrounding it with a macro), but not intuitive and if you forget it you have to destroy the macro and redo it. At least there is a workaround.
    Anyway, nice plugin

  3. Vaclav Pech says:

    Yes, including the end-of-line in a macro is necessary in all target languages. I agree that the UX of macro manipulation could be improved.

Leave a Reply

Your email address will not be published. Required fields are marked *