Skip to main content



      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 14:46 Go to next message
Eclipse UserFriend
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 14:49 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Formatting Generated Code [message #1809221 is a reply to message #1809220] Thu, 11 July 2019 15:39 Go to previous messageGo to next message
Eclipse UserFriend
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 15:46 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Thu, 11 July 2019 15:47] by Moderator

Re: Formatting Generated Code [message #1809223 is a reply to message #1809222] Thu, 11 July 2019 18:58 Go to previous message
Eclipse UserFriend
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: Fri Apr 18 23:12:13 EDT 2025

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

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

Back to the top