Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Convert Sequence to String in Acceleo
Convert Sequence to String in Acceleo [message #1786809] Sat, 12 May 2018 18:20 Go to next message
mamad . is currently offline mamad .Friend
Messages: 15
Registered: March 2018
Junior Member
Hi guys,
Do you have any idea about how to convert a sequence of strings to a string
for example my sequence is : Sequence { 'a' , 'b' , 'c' } and i want to convert it to a single string variable with value 'abc'
.tostring() method gives no error but gives a warning and actually dont work and gives empty output.

Thanks in advance,
Re: Convert Sequence to String in Acceleo [message #1786810 is a reply to message #1786809] Sat, 12 May 2018 18:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7674
Registered: July 2009
Senior Member
Hi

You need to use iterate: Sequence{'a','b','c'}->iterate(ch, acc:String ='' | acc+ch)

One day you might be able to:do: Sequence{'a','b','c'}->sum()

Regards

Ed Willink
Re: Convert Sequence to String in Acceleo [message #1786824 is a reply to message #1786810] Sun, 13 May 2018 14:30 Go to previous messageGo to next message
mamad . is currently offline mamad .Friend
Messages: 15
Registered: March 2018
Junior Member
Hi Ed and thank you for your contribution.
your code gives a couple of errors :
first of all it say :
1:39:1:39 "::" expected instead of ":"
and
1:53:1:53 "," expected instead of "|"
with solving the expectations it say again :
Unrecognized variable: (ch)
Unrecognized variable: (acc)
what do you mean by ch and acc ?
I clear every thing inside Iterate but it sayes :Cannot find operation (iterate()) for the type (Sequence(String))
Re: Convert Sequence to String in Acceleo [message #1786828 is a reply to message #1786824] Sun, 13 May 2018 16:04 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7674
Registered: July 2009
Senior Member
Hi

I actually tested my example. Did you cut and paste or retype. I see an opprtunity for a double-singlequote / doublequote misunderstnading.

The meaning of variables are defined in the iterate examples.

Regards

Ed Willink
Re: Convert Sequence to String in Acceleo [message #1786836 is a reply to message #1786828] Sun, 13 May 2018 23:47 Go to previous messageGo to next message
mamad . is currently offline mamad .Friend
Messages: 15
Registered: March 2018
Junior Member
I copy and paste your code exactly but it gives some errors .
would you please give a me link of where i can find an example about using Iterate ?
  • Attachment: a.jpg
    (Size: 36.54KB, Downloaded 225 times)
Re: Convert Sequence to String in Acceleo [message #1786837 is a reply to message #1786836] Mon, 14 May 2018 05:29 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7674
Registered: July 2009
Senior Member
Hi

Apologies, I tested it in the Interactive Xtext OCL Console (that users the Xtext-based parser which matches up arguments to iterators to avoid hardwiring the iterator syntaxes in the grammar). This tolerates a typo; for iterate the result/accumultor should be preceded by a ";" rather than a ",". The OCL Console using the old LPG-based parser gives a similar error to what you see. The following works in both:

Evaluating:
Sequence{'a','b','c'}->iterate(ch; acc:String ='' | acc+ch)
Results:
'abc'

There are very adequate examples in "7.6.6 Iterate Operation" of the OCL specification. Warm&Kleppe providers a useful section too but withy the dsame typo as my original solution.

Regards

Ed Willink
Re: Convert Sequence to String in Acceleo [message #1786838 is a reply to message #1786837] Mon, 14 May 2018 05:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7674
Registered: July 2009
Senior Member
Hi

Correction: Warmer&Kleppe.

Regards

Ed Willink
Re: Convert Sequence to String in Acceleo [message #1786842 is a reply to message #1786838] Mon, 14 May 2018 07:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7674
Registered: July 2009
Senior Member
Hi

"This tolerates a typo;" https://bugs.eclipse.org/bugs/show_bug.cgi?id=534626 raised.

"::" expected instead of ":" and "," expected instead of "|" are a consequence of an unfortunate language design choice for OCL; the minimal iteration short form "anInteration(name)" for "anIteration(n : NamedElement | n.name)" is syntactically indistinguishable from the "anOperation(name)" shortform for "anOperation(self.name)". The ambiguity is worse for "iterate". LL parsers such as Xtext use backtracking to resolve the conflict leading to the 'wrong' error message for simple typos. LALR parsers such as LPG use narrow rules that pick the wrong alternative for simple typos and again give the 'wrong' error message.

Regards

Ed Willink
Re: Convert Sequence to String in Acceleo [message #1786868 is a reply to message #1786838] Mon, 14 May 2018 14:32 Go to previous message
mamad . is currently offline mamad .Friend
Messages: 15
Registered: March 2018
Junior Member
Sequence{'a','b','c'}->iterate(ch; acc:String ='' | acc+ch)

Thank you so much , it works
Previous Topic:How pass string array[] as argument of a java service wrapper in acceleo ?
Next Topic:How to export my Acceleo code generator as a standalone desktop application ?
Goto Forum:
  


Current Time: Fri Oct 04 20:21:45 GMT 2024

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

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

Back to the top