Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Post trim not working(post (trim()) seems to do nothing)
Post trim not working [message #1765385] Fri, 09 June 2017 05:51 Go to next message
Philip Schröder is currently offline Philip SchröderFriend
Messages: 28
Registered: January 2017
Junior Member
Hello folks,
I would like to structure my code, and with Acceleo it mostly feels like I need to put everything in one line to make it work.
Thus I tried out post (trim()), but it doesn't seem to do anything.

Here is what I tried:

[template public generateTrimTests(c : Class)]
[comment @main/]
[file ('src/' + c.name + '.h', false, 'UTF-8')]
	[trimBeforeWrite(c)/]
[/file]
[/template]

[template public trimBeforeWrite(c : Class) post (trim())]
[for(a : Property | c.attribute)]
Whatevertype [a.name/];
[/for]
[if (2 < 3)]
		Blablubs: [c.name/] foo 
[else]
		BingBong!
[/if]
bla
[/template]


The Papyrus diagram looks like this

index.php/fa/29594/0/

Now I would expect something like this

	Whatevertype Attribute1; Whatevertype Attribute2;   Blablubs: SomeClass foo bla


Instead I get this

	Whatevertype Attribute1;
	Whatevertype Attribute2;
			Blablubs: SomeClass foo 
	bla


To me it seems as if post (trim()) does nothing, any idea?

Thank you for your time and trouble.

Best

Philip.

[Updated on: Fri, 09 June 2017 05:54]

Report message to a moderator

Re: Post trim not working [message #1765947 is a reply to message #1765385] Wed, 14 June 2017 14:39 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

"trim" will remove the spaces "around" the result of your template call, not all spaces inside it; there are no such white spaces in your trimBeforeWrite template.

The whitespaces you see are the ones added by your for loop, specifically the carriage return after ";". You could remove that carriage returns by having the end of your for loop on the same line:
[for(a : Property | c.attribute)]
Whatevertype [a.name/];[/for]


LIkewise, the carriage return before "bla" is the one inside your "if", and you'd need to remove it as well:

[if (2 < 3)]
		Blablubs: [c.name/] foo[else]
		BingBong![/if]


This is probably not the answer you wanted, but we made the choice to preserve these particular line endings as significant in the template writing, so you need to work around them if you happen not to want them generated.

Note that you could use something other than "trim" if you want to remove all line separators from the template call, regardless of their position (i.e. also the ones "in the middle" of the text generated by the template.

For example, replace could work for your case:
[template public trimBeforeWrite(c : Class) post (replace('\\\\s', ''))]


would remove "all" whitespace.

[template public trimBeforeWrite(c : Class) post (replace('\\\\r|\\\\n', ''))]


would remove the line endings.

Laurent Goubet
Obeo
Previous Topic:language
Next Topic:Invalid type for iteration Error
Goto Forum:
  


Current Time: Sat Jul 27 10:43:30 GMT 2024

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

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

Back to the top