Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to avoid indentation (tabs) during code generation?(How to format the generated code?)
How to avoid indentation (tabs) during code generation? [message #1065747] Thu, 27 June 2013 11:19 Go to next message
Michael Genau is currently offline Michael GenauFriend
Messages: 9
Registered: April 2013
Junior Member
Hello,

I like to know how I can format the output of a code generator.

I implemented a class derived from IGenerator which writes the output without any special formatting but the output contains a tab at the beginning of each line for each element of my DSL.
If a value contains a comment I get
    value="//////////////////
    //
    //"

instead of
    value="//////////////////
//
//"

which is wrong because the content of value is different.

I tried to use the method Resource.save() and to enable formatting by the save options. This use case uses my formatter class derived from AbstractDeclarativeFormatter but it formats the content of the dsl file, not the content of the generated code.

Therefore the question is:
How can I format the generated code during or after the generation process?

Regards,
Michael
Re: How to avoid indentation (tabs) during code generation? [message #1065748 is a reply to message #1065747] Thu, 27 June 2013 11:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the generator gives (more or less) a String to an IFileSystemAccess
=> What you do with this string is yours.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to avoid indentation (tabs) during code generation? [message #1065750 is a reply to message #1065748] Thu, 27 June 2013 11:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.S: how does your template look like? (have a look at the "grayspace" in the template)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to avoid indentation (tabs) during code generation? [message #1065778 is a reply to message #1065750] Thu, 27 June 2013 13:03 Go to previous messageGo to next message
Michael Genau is currently offline Michael GenauFriend
Messages: 9
Registered: April 2013
Junior Member
Hi,

I checked the content of the CharSequence generated by compile methods.
It contains undesired tabs.

This is an example of the source:
I-Logix-RPY-Archive version 8.5.2 C++ 1508637
{ IComponent 
	- m_text = " /****************************************************************************

Record for the state management
 
 ****************************************************************************/";
 	- _id = GUID d7d1649c-de5b-4b45-9f73-4f1ab5ef64b6;
	- _myState = 8192; 
	- _properties = { IPropertyContainer  
		- Subjects = { IRPYRawContainer 
			- size = 1; 
			- value = 
			{ IPropertySubject 


And this is the result of the code generation:
$rhapsodyContent = generateOrderedHash( 
		"IComponent" => generateOrderedHash(
				"m_text" => q(" /****************************************************************************
				
				Record for the state management
				 
				 ****************************************************************************/") 
				,"_id" => q(GUID d7d1649c-de5b-4b45-9f73-4f1ab5ef64b6) 
				,"_myState" => q(8192) 
				,"_properties" => generateOrderedHash(
					"IPropertyContainer" => generateOrderedHash(
							"Subjects" => generateOrderedHash(
								"IRPYRawContainer" => generateOrderedHash(
										"size" => q(1) 


The content of m_value is indented but I need a solution to avoid the indentation at all or art least of multiline strings.

The code generator prints the following to the output:
	def compile(SimpleValue e){
		"q(" + e.value + ")"
	}

A SimpleValue could by a string or an other value.
As you see, I don't add tabs here. I doesn't matter if I use " " or ''' '''.

Re: How to avoid indentation (tabs) during code generation? [message #1065781 is a reply to message #1065778] Thu, 27 June 2013 13:10 Go to previous messageGo to next message
Michael Genau is currently offline Michael GenauFriend
Messages: 9
Registered: April 2013
Junior Member
Oh my God!
I found the error... Now I understand what you mean with "grayspace".

But my question is still unanswered...
How can I generate a code like:
"IComponent" => generateOrderedHash(
				"m_text" => q(" /****************************************************************************

Record for the state management

****************************************************************************/") 
				,"_id" => q(GUID d7d1649c-de5b-4b45-9f73-4f1ab5ef64b6) 
?

Re: How to avoid indentation (tabs) during code generation? [message #1065782 is a reply to message #1065781] Thu, 27 June 2013 13:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
so the space is in value right? then you have to trim value yourself

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to avoid indentation (tabs) during code generation? [message #1065785 is a reply to message #1065782] Thu, 27 June 2013 13:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.S: from your post i do not really get what the remaining problem is.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to avoid indentation (tabs) during code generation? [message #1065867 is a reply to message #1065785] Fri, 28 June 2013 04:31 Go to previous messageGo to next message
Michael Genau is currently offline Michael GenauFriend
Messages: 9
Registered: April 2013
Junior Member
The problem is shown in the post msg_1065778.
The spaces/tabs are not in the source but in the generated code.
Source:
	- m_text = " /****************************************************************************

Record for the state management
 
 ****************************************************************************/";


Result:
				"m_text" => q(" /****************************************************************************
				
				Record for the state management
				 
				 ****************************************************************************/") 


Expected result:
				"m_text" => q(" /****************************************************************************

Record for the state management
	 
 ****************************************************************************/") 


If we have a DSL like that and you add one tab in the code generation for A and one for B you get two tabs as result for B even if there is a line break in the string of B.
A:B;
B:C;

Now, the content of the variable m_text is different because it is a string and this string contains invalid tabs at the beginning of each line except line one.
Do you understand what I mean?
Re: How to avoid indentation (tabs) during code generation? [message #1065870 is a reply to message #1065867] Fri, 28 June 2013 05:02 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hmm i have no idea what Could cause this

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Disabling ID Terminal Uniqueness ?
Next Topic:mportedNamespaceAwareLocalScopeProvider
Goto Forum:
  


Current Time: Fri Apr 26 05:12:02 GMT 2024

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

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

Back to the top