If you’re looking to export your data from MPS for use in a different application there are two approaches I would recommend:

  1. The simplest way: NodeSerializer from MPS-extensions, as described in yesterday’s post. This lets you quickly export your data in a rather nice XML structure.
  2. The most flexible approach: writing a custom exporter by using the MPS Open API to recursively traverse a node tree. You can output any format you want (XML, JSON, YAML, etc.) and customize the output as you like.

Here are two more approaches that you could be considering but that I would NOT recommend:

  1. Accessing the model (*.mps) files directly. While they are already in XML format, their structure is adapted to MPS' needs. It is normalized, meaning that a given piece of information is generally only stored once, and it also encodes node IDs in a particular way to save space. The format is also undocumented and could change in the future (although it hasn’t changed for the past several years).

  2. Using the MPS generator to convert your DSL to MPS' built-in XML language, jetbrains.mps.core.xml.

The reason I don’t recommend using the MPS generator is because the generator’s sweet spot is translating between two different MPS languages, e.g. from your custom DSL to Java.

While it is technically possible to write a generator rule that would apply to any MPS concept and convert it into an XML node, in the next step the generator would take your XML node and try to convert it into an XML node again. So you will need to stop this from occurring.

Another problem you will hit is that the MPS generator can only iterate (using the $LOOP$ macro) over MPS nodes. If you want to loop over e.g. each node property you will need to work around this limitation because a node property isn’t an MPS node.

Overall, using the MPS generator for this purpose would feel like swimming against the flow.

Of course, a question to consider is whether you really need to export the source models. Perhaps you would be better off generating code from your models or analyzing or interpreting them directly in MPS?