Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 341080

Summary: [xtend] FOR loop in rich strings should have separator/pre/post expression
Product: [Modeling] TMF Reporter: Jan Koehnlein <jan>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: 2.0.0Flags: jan: indigo+
Target Milestone: M7   
Hardware: All   
OS: All   
Whiteboard:

Description Jan Koehnlein CLA 2011-03-28 06:27:46 EDT
The FOR loop should support a separator expression that is executed in between two loop runs. 

A pre and post expression your also be nice. These should only be executed if the for loop runs at all.

The Xpand syntax might be a bit noisy, maybe we can find something nicer.
Comment 1 Sebastian Zarnekow CLA 2011-04-05 16:28:01 EDT
The semantics of the separator are somewhat unclear.
Consider the following template:
<<FOR a: iterable SEPARATOR ','>>
  <<a>>
<<ENDFOR>>
That is the trailing linebreak after the <<a>> is part of the for loop body. However, I would expect the result to be something like
a1,
a2,
a3
instead of 
a1
,a2
,a3
We could either implement a more complicated algorithm for separators and before / after or rely on the assumption that SEPARATORs will usually be used in singleline for loops like
<<FOR a: iterable SEPARATOR ', '>><<a>><<ENDFOR>>
which will result in 
a1, a2, a3
Comment 2 Sebastian Zarnekow CLA 2011-04-05 16:31:56 EDT
(In reply to comment #1)
> Static template text <<FOR a: iterable SEPARATOR ','>>
>   <<a>>
> <<ENDFOR>>

It is even worse, the leading line break before the <<a>> is part of the template body, too. The result would actually look like this:

Static template text
a1
,
a2
,
a3

So there may be a need to implement something more complicated for loops in rich strings.
Comment 3 Sven Efftinge CLA 2011-04-06 02:44:37 EDT
That's a pity. I think the second situation boils down to a general problem with the whitespace handling.
That is you typically introduce those line breaks in order to split template line into two lines for readability which in the output should be one line. 

This happens quite often, because the extra template logic makes lines longer.

Maybe we need something to suppress line breaks explicitly?

Something like:

> Static template text <<FOR a: iterable SEPARATOR ','->>
>   <<a>> <<->>
> <<ENDFOR>>

(note the hyphen) comes to mind :-)
Comment 4 Sebastian Zarnekow CLA 2011-04-06 03:33:13 EDT
What I've implemented so far is

'''  
  «FOR i: 1..3 SEPARATOR ','»
      «i»
  «ENDFOR»
'''

->

1,
2,
3

I think we should give this one a try and see how it works in practice. What do you think?
Comment 5 Sven Efftinge CLA 2011-04-06 03:40:50 EDT
+1
Comment 6 Sebastian Zarnekow CLA 2011-04-06 03:55:31 EDT
pushed to master.
Comment 7 Karsten Thoms CLA 2017-09-19 16:54:28 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 8 Karsten Thoms CLA 2017-09-19 17:05:19 EDT
Closing all bugs that were set to RESOLVED before Neon.0