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 07: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 09:36 Go to previous message
Christian Dietrich is currently online Christian Dietrich
Messages: 6246
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 14:08]

Report message to a moderator

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


Current Time: Tue Sep 02 05:13:07 EDT 2014

Powered by FUDForum. Page generated in 0.01836 seconds