Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatting Generated Code(The output of my code generator should be formated as XML)
Formatting Generated Code [message #1809218] Thu, 11 July 2019 18:46 Go to next message
Daniel San Martín is currently offline Daniel San MartínFriend
Messages: 44
Registered: October 2012
Member
Hello,

I implemented a code generator and the output is a xml file. I would like to have this output formatted. Here is a little example:

Current output (snippet) :
<model xsi:type="...." name="Planned Architecture">
<structureElement xsi:type="..." name="managing_1">
<structureElement xsi:type="..." name="controller_1">
<structureElement xsi:type="..." name="monitor_1">
</structureElement>
</structureElement>
</structureElement>
</model>


Desirable output:

<model xsi:type="..." name="Planned Architecture">
    <structureElement xsi:type="..." name="managing_1">
            <structureElement xsi:type="..." name="controller_1">
                <structureElement xsi:type="..." name="monitor_1">
               </structureElement>
            </structureElement>
    </structureElement>
</model>


I read that IFilePostProcessor should help in my purpose but cannot find enough examples to use it properly.

Regards,


Re: Formatting Generated Code [message #1809220 is a reply to message #1809218] Thu, 11 July 2019 18:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13152
Registered: July 2009
Senior Member
I Wonder in you make improper use of Rich String in the First Place so that you have the Problem at all.

The Second question would be: that is exactly unclear about IFilePostProcessor


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Formatting Generated Code [message #1809221 is a reply to message #1809220] Thu, 11 July 2019 19:39 Go to previous messageGo to next message
Daniel San Martín is currently offline Daniel San MartínFriend
Messages: 44
Registered: October 2012
Member
Maybe the question is: What are the mechanisms for indenting the file that contains the generated code?. At this moment I just use the default code generator of xtex. As you mention "Rich String" which is part of Xbase, I infer I must create a custom code generator with Xbase in order to indent the code. Am I right?
Re: Formatting Generated Code [message #1809222 is a reply to message #1809221] Thu, 11 July 2019 19:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13152
Registered: July 2009
Senior Member
No if you have a rich string
'''
    Demo
'''

You will see that it distinguishes between whitespace
And grey space .
The gray space will end up in the generated file
So in this case you will get a
     Demo

In the generated file

Same with IF and FOR inside the rich string.

See the generator example in the tutorial
https://www.eclipse.org/Xtext/documentation/103_domainmodelnextsteps.html#tutorial-code-generation


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 11 July 2019 19:47]

Report message to a moderator

Re: Formatting Generated Code [message #1809223 is a reply to message #1809222] Thu, 11 July 2019 22:58 Go to previous message
Daniel San Martín is currently offline Daniel San MartínFriend
Messages: 44
Registered: October 2012
Member
Thank you very much. It worked.
Previous Topic:How to access grammar keywords in formatter
Next Topic:XText Generator making random mistakes while generating java classes
Goto Forum:
  


Current Time: Tue Oct 15 14:36:28 GMT 2019

Powered by FUDForum. Page generated in 0.02202 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top