Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » EGL: How to send a sequence as a parameter to a template
EGL: How to send a sequence as a parameter to a template [message #1736255] Mon, 27 June 2016 22:07 Go to next message
Alireza Rouhi is currently offline Alireza RouhiFriend
Messages: 126
Registered: December 2015
Senior Member
Hi,

I have an EGL template which generates a list of transformation rules.
So, I would like to send a sequence of elements as a parameter to apply in the generated rules in the template (in the target .egx file).

For example:
My .egl file is as follows:
[% var s = Sequence {"first", "second", "third"};

var i: Integer = 0;
while (i < 2) { %]
rule generate[%= i %] 
		transform s : SourceModel!Type {
		
		parameters {
    		var params : new Map;
    		params.put("s", [%= s %]);
    		
    		return params;
		}
		
		template : "template.egl"

		target : "target.txt"
}

[%
	i = i + 1;
}
%]


and the generated .egx file is as follows:
rule generate0 
		transform s : SourceModel!Type {
		
		parameters {
    		var params : new Map;
    		params.put("s", [first, second, third]); // erroneous
    		
    		return params;
		}
		
		template : "template.egl"

		target : "target.txt"
}

rule generate1 
		transform s : SourceModel!Type {
		
		parameters {
    		var params : new Map;
    		params.put("s", [first, second, third]); // erroneous
    		
    		return params;
		}
		
		template : "template.egl"

		target : "target.txt"
}


Is there any way to resolve this issue?

Best regards,
Alireza
Re: EGL: How to send a sequence as a parameter to a template [message #1736276 is a reply to message #1736255] Tue, 28 June 2016 07:57 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 470
Registered: January 2010
Senior Member
You could pass a comma-separated list of values and then use the split method in String:

var list = stringParam.split(",").asSequence();

Re: EGL: How to send a sequence as a parameter to a template [message #1736278 is a reply to message #1736276] Tue, 28 June 2016 08:01 Go to previous messageGo to next message
Alireza Rouhi is currently offline Alireza RouhiFriend
Messages: 126
Registered: December 2015
Senior Member
Hi Antonio,

Thanks a lot for your solution. But, how to apply this solution to a Sequence(Sequence) parameter?

Best regards,
Alireza

[Updated on: Tue, 28 June 2016 09:00]

Report message to a moderator

Re: EGL: How to send a sequence as a parameter to a template [message #1736286 is a reply to message #1736278] Tue, 28 June 2016 09:03 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 470
Registered: January 2010
Senior Member
A nested sequence will be trickier, of course. If you have a bounded number of nesting levels (say, sequence of sequence of integers) you could use different separators, say "," for first level and ";" for second level. Maybe something like:

var nested = stringParam.split(",").asSequence().collect(e|e.split(";").asSequence()).asSequence();


That splits by ",", and then splits again by ";".
Re: EGL: How to send a sequence as a parameter to a template [message #1736290 is a reply to message #1736286] Tue, 28 June 2016 09:31 Go to previous message
Alireza Rouhi is currently offline Alireza RouhiFriend
Messages: 126
Registered: December 2015
Senior Member
Thank you very much.

Best regards,
Alireza
Previous Topic:About temporary/on-the-fly (~) model attributes
Next Topic:EGL: How to resolve the Java heap space error
Goto Forum:
  


Current Time: Mon Jan 22 12:45:13 GMT 2018

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

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