Skip to main content



      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
Eclipse UserFriend

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
Eclipse UserFriend
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] by Moderator

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


Current Time: Thu Jul 10 00:12:53 EDT 2025

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

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

Back to the top