I recently attempted to learn to use MPS by means of writing a simple language and generating java classes from it. I'm stuck at the following problem, which I thought could be solved with the "switch" macro, but I couldn't figure out how to make it work. There doesn't appear to be any documentation available on this macro, and there are only a few examples that use it. Unfortunately, one can scarcely guess how this macro works by simply looking at the examples. So, I would really appreciate if someone explains how to use them in a few words.
So, the problem I'm trying to solve is generating a tree-like structure from a source tree, using recursive templates. It's best described by an example:
E.g. for something like the following in XML:
One would write a corresponding transformation in XSLT similar to:
Which should produce
Now, how do I achieve the same result in MPS? My thought was I could employ the switch macro for this task, since it's the only tool I found that allows me to call templates recursively. Please correct me if I'm wrong and there is another, simpler and more elegant way.
I believe, one could simply create mapping from source nodes to templates and just run a substitution (AKA transformation) with the root source node. This would be most natural, but unfortunately it's unclear how one achieves this mapping.
Thanks in advance.