How to create textual content in target model ?

Hi,

First thank you very much for this fabulous tool that is MPS. I am very eager to develop on this.
So I am making a proof of concept. I need to generate xml file.
So I am using mps.xml language as target for the generator.
I created a language which contains conditions represented as Expression (from baseLanguage).
Now in my template for xml document, I want to transform the Expression (baseLanguage) to an xml attribute value.
So I created an element like this :
<transition cond="$COPY_SRC$(condition)"/>
copy_src : node.condition; (which is of type Expression)
I have a reduction rule in the main description of generator:
reduction_rules:
(concept Expression) –> <T $(expression) T> // content of template is XmlValuePart or XmlTextValue

But I don't know what to put as a property macro for $(expression)
I want to do something like node.toString(); but it is not possible
Is it possible to call textgen component ?
I created a textgen component for some Expression (like Reference which extends Expression), and I don't know how to call it.
I also tried to something like :
(concept PlusExpression) –> <T left + right T>   // content of template is XmlValuePart or XmlTextValue
And I want to have two macros, one on left and one right, but when I want to add a macro I can have only this :
(concept PlusExpression) –> <T $(left + right) T>
and not this :
(concept PlusExpression) –> <T $(left) + $(right) T>

I tried to do something like GText screencast but it is not working. The reduction rule :
(concept Expression) –> <T wrapper $COPY_SRC$("expression") T>
is not called.

So I need advice ! How to generate text from model for say xml attributes ?
2 comments
So in fact, there are multiple issues in this post.
  • First is I don't understand why my reduction rule for Expression is not executed from the COPY_SRC macro in the main template.
  • Second is I was not able to create a template (inline or new) with multiple property macro inside the string content.
  • Third I want to know if there is a way to call textgen components from templates
0
Now the solution which works but is not very elegant.
In the main template I do a $CALL$reduce_Expression (I would have prefer a $COPY_SRC$ and then reduce rule is called but this is not working)
Then in the reduce_Expression I create a wraper element (internal concept in my language) which wrap the expression
Then I create a textgen component for the wraper, which append the expression directly (which I suppose should call the textgen from baseLanguage textgen components)

So my understanding and working solution (learned from the very good GText screencast), is first to wrap elements (wraper class extends target metamodel), then create textgen components for them and since we are in textgen, we can do anything string related.
0

Please sign in to leave a comment.