Generating XmlAttribute of the xml.core from the properties of the custom DSL

Hi All, 

My task is to generate xml file from my custom DSL. For that I am using jetbrains.mps.core.xml as a target language for transformation. Currently I am trying to write a general recursive template, which converts concepts into xml like 

<conceptname conceptproperty="conceptproperty value"> children</conceptname>

I managed to successfully generate all children using $LOOP$ over node.children, but I can not find a way to iterate over concept properties. $LOOP$ seems to be working only with nodes, but properties seem to be not nodes. How do I iterate over properties in the generator? Any help would be very much appreciated! 

Vitaly

6 comments
Comment actions Permalink

If you need to iterate over data that isn't a node, you can create a special internal concept containing properties to hold the data and create a list of instances of that concept in the $LOOP$ macro. Look at the use of GeneratorInternal_String concept in MPS sources for an example.

1
Comment actions Permalink

Thanks Sergej, it helped a lot! Learning how to use MPS is a bit of pain, due to a lack of documentation. It is basically trial and error process still without a clear big picture in the head.  I have ordered the books on MPS from amazon, hope it helps avoiding too many questions. I am almost there, I have created an auxiliary conceptGeneratorConceptProperty and generate it in the loop. Still one small thing is missing, how do I get the property value having its name in the conceptProperty.name? 

(genContext, node, operationContext)->sequence<node<>> {
nlist<GeneratorConceptProperty> lst = new nlist<GeneratorConceptProperty>;
for (SProperty property : node.concept.getProperties()) {
node<GeneratorConceptProperty> conceptProperty = new node<GeneratorConceptProperty>();
conceptProperty.name = property.getName();
conceptProperty.value = ???
lst.add(conceptProperty);
}
return lst;
}

1
Comment actions Permalink

Use node/.getProperty(property), where the "/" is listed in the completion menu as a "semantic downcast" operation, meaning it converts its argument from node<> to SNode (they are both the same underlying type but node<> has higher-level operations while SNode has lower-level ones that you need in this case).

1
Comment actions Permalink

super! Works, thank you! References I could make analogously with the help of the documentation. Btw, how is one supposed to come to this solution? What would be the right way to proceed if I get stuck? I did look at https://confluence.jetbrains.com/display/MPSD20181/SModel+language , but it did not help much with the properties. 

Vitaly

1
Comment actions Permalink

The available MPS books help somewhat but overall there's no good reference manual for MPS unfortunately. I generally look through MPS sources (both in MPS and in IDEA) when I want to figure things out.

1
Comment actions Permalink

I found this post very helpful for it clears the path I need to follow in a similar problem but I still don´t know how does one generate a custom concept ( Using Java ).

 

@Sergej @Vitaluy would u mind elaborating?

1

Please sign in to leave a comment.