EGL 101 [message #774360] |
Tue, 03 January 2012 14:08  |
Eclipse User |
|
|
|
Hi,
I'm trying to accomplish some model-to-text transformation with EGL.
I've setup Xtext to parse a text to a model. After that I want to use ETL to transform the model, and finally I want to use EGL to "unparse" the model to text again. Xtext generates an implicit meta-model on the fly (attached .ecore). I'm using this one and a test setup to transform my model to text, but I don't get the EGL (EOL) syntax...
[% for (eobj in EObject.allInstances()) { %]
[% if (eobj.isTypeOf(Model)) { %]
[% var m : Model := EObject.selectOne(e|e.isTypeOf(Model)); %]
[% } %]
[% if (eobj.isTypeOf(CharData)) { %]
[% var cd : CharData := new CharData; %]
[% cd := EObject.selectOne(d|d.isKindOf(CharData)); %]
[%cd.print();%]
[%=cd.value%]
[% } %]
[% } %]
What I basically trying in this EGL snippet is: Iterate each EObject (that should give me every object... because EObject is the supertype of everything) in my model... than look what type it is, according to the type do something with it, but: how do I type cast an EObject to XYZ? And how can I access the properties? Any suggestions? I'm really stuck here.
Best regards
Yves
|
|
|
|
Re: EGL 101 [message #774752 is a reply to message #774614] |
Wed, 04 January 2012 09:25  |
Eclipse User |
|
|
|
Hi Dimitris,
thanks for the answer, I somehow got it working this morning.
As a note... EObject was supposed to be Ecore's EObject, I imported the Ecore Meta-Model additionally to my own.
My code looks now like this:
[%
for (m in Model.allInstances()) { m.test(); }
operation Attribute test() {
(self + " is an Attribute").println();
out.print(self.key + "=" + self.value);
}
%]
Each of my objects "implements" such a test()-method.
Best regards
Yves
|
|
|
Powered by
FUDForum. Page generated in 0.20486 seconds