Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend, rich strings and SEPARATOR option
Xtend, rich strings and SEPARATOR option [message #876315] Thu, 24 May 2012 11:05 Go to next message
Aran A is currently offline Aran A
Messages: 22
Registered: January 2011
Junior Member

Hello,

In a previous post I have seen this code with rich strings

toString(Entity e) '''
«e.name»
«FOR member: e.members BEFORE "(" SEPARATOR "," AFTER ")"»
«member.toString»
«ENDFOR»
'''


The result will be the members separated by commas, in parentheses. If there
are no members, there won't be parentheses.

OK, but how can I do if I have a conditional inside the FOR?, as in the example:

toString(Entity e) '''
«e.name»
«FOR member: e.members BEFORE "(" SEPARATOR "," AFTER ")"»
«IF (a condition...)»«member.toString»«ENDIF»
«ENDFOR»
'''


Then, the result could be something like: m1, , , , m5, m6, m7, , , , , , m13,
How can I do if I want a result will be m1, m5, m6, m7, m3 ? Do I have to work it by hand?

Thanks in advance,

Aran
Re: Xtend, rich strings and SEPARATOR option [message #876379 is a reply to message #876315] Thu, 24 May 2012 13:36 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6378
Registered: July 2009
Senior Member
What about wrapping it into an extra extension using map and filter?

e.g.

toString(Entity e) '''
«e.name»
«FOR member: e.members.filter(m|a condition) BEFORE "(" SEPARATOR "," AFTER ")"»
«member.toString»
«ENDFOR»
'''

[Updated on: Thu, 24 May 2012 18:08]

Report message to a moderator

Previous Topic:J2SE-1.7 Problem
Next Topic:greedy option in xtext
Goto Forum:
  


Current Time: Tue Oct 21 02:12:22 GMT 2014

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

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