Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Generator no NEW LINE
Xtext Generator no NEW LINE [message #1706104] Sun, 23 August 2015 08:09 Go to next message
Hansi Knaus is currently offline Hansi KnausFriend
Messages: 3
Registered: August 2015
Junior Member
Hello!
I have a big problem. If I code in the Xtext Generator a for loop like:

«FOR param: sig.eAllContents.toIterable.filter(typeof(parameter))»
«param.compile»
«ENDFOR»

and then I code the function param.compile and then the next for loop ist:

«FOR numeric_value:sig.eAllContents.toIterable.filter(typeof(numeric_value))»
«numeric_value.compile»
«ENDFOR»

I get as result:

parameter
numeric_value

My problem is that I don't neet the NEW LINE. I need a result like:
parameter numeric_value

How can I get rid of this NEW LINE?
Re: Xtext Generator no NEW LINE [message #1706193 is a reply to message #1706104] Mon, 24 August 2015 15:32 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hi Hansi,

you can avoid the newline by putting the expression in one line:

«FOR numeric_value:sig.eAllContents.toIterable.filter(typeof(numeric_value))»«numeric_value.compile»«ENDFOR»

Cheers,
Stefan
Re: Xtext Generator no NEW LINE [message #1706226 is a reply to message #1706193] Tue, 25 August 2015 07:04 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
to get a more readable code,
create a def which returns the result for each FOR loop
and just call these in your code:

«loop_parameter() loop_numeric()»

def loop_parameter '''
«FOR param: sig.eAllContents.toIterable.filter(typeof(parameter))»
«param.compile»
«ENDFOR»'''

def loop_numeric '''
«FOR numeric_value:sig.eAllContents.toIterable.filter(typeof(numeric_value))»
«numeric_value.compile»
«ENDFOR»'''

Greetings from Frankfurt/Germany,
Uli
Re: Xtext Generator no NEW LINE [message #1706288 is a reply to message #1706226] Tue, 25 August 2015 13:25 Go to previous messageGo to next message
Hansi Knaus is currently offline Hansi KnausFriend
Messages: 3
Registered: August 2015
Junior Member
Both versions does not work!
Version 1 does not work because I have a function an in this function the for loop gets invoket so I have still new lines.
Version 2 does not work because in the new function I can't get access to sig.

[Updated on: Tue, 25 August 2015 13:25]

Report message to a moderator

Re: Xtext Generator no NEW LINE [message #1706299 is a reply to message #1706288] Tue, 25 August 2015 14:02 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

We are giving you the best suggestions we can based on the limited information. If you want a definitive answer, you'll have to share the full code.
Re: Xtext Generator no NEW LINE [message #1706353 is a reply to message #1706299] Wed, 26 August 2015 08:25 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Version 2 does not work because in the new function I can't get access to sig.

so add in the def line your sig as a parameter to the function:
def loop_parameter (Signature sig) ''' ...

and if you have a look at the Greetings Generator, you see a way to create a comma separated list out of a collection using map() and join()
Re: Xtext Generator no NEW LINE [message #1706740 is a reply to message #1706353] Sat, 29 August 2015 13:10 Go to previous messageGo to next message
Hansi Knaus is currently offline Hansi KnausFriend
Messages: 3
Registered: August 2015
Junior Member
I discovered that when I look in to xtend-gen folder and than the generator file that the generator does not generate a newLine but in my gernerated file there is a newLine.
What can I do?
Re: Xtext Generator no NEW LINE [message #1706743 is a reply to message #1706740] Sat, 29 August 2015 14:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
can you provide a sample grammar, model and generator?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Generator no NEW LINE [message #1707079 is a reply to message #1706743] Wed, 02 September 2015 07:03 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Another more universal suggestion:

what about creating a routine noNewlines which replaces the newlines with an empty string (or a space).
You can use them in the generator coding wherever you feel that a section of text should not contain newlines
Previous Topic:formatter2 - problem with nested objects
Next Topic:New formatter API
Goto Forum:
  


Current Time: Tue Mar 19 10:29:47 GMT 2024

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

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

Back to the top