Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » data type rule - list
data type rule - list [message #685923] Mon, 20 June 2011 19:11 Go to next message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
Hi,
suppose a section of my grammar looks like this:
Vector3 :
    '('FLOAT','FLOAT','FLOAT')';

terminal FLOAT returns ecore::EFloat : ('+'?|'-')('0'..'9')*'.'('0'..'9')+;


I'd like a Vector3 object to be some kind of a list.
I wrote my value converter that transforms the parsed string to a java::util::ArrayList<double>, and successfully registered it (thanks to Petter Graff and its blog)

Then I realized that my data type rule return an EString by default, whatever my value converter, so I added a returns:
Vector3 returns ecore::EJavaObject :
    '('FLOAT','FLOAT','FLOAT')';


Is there any better way instead the hack of using an EJavaObject?
I mean, what is the preferred way to get lists out of some parser rule?

I'd like to be able to handle the data as a list in the xpand/xtend files, for code generation.
The ecore::EJavaObject works, I can see that in the generated java code there is 'Object', but how can I exploit this in the template file? I am not able to "import" java.util.List or similar.

I know there could be easier ways, like modelling a Vector3 with three properties x, y, z (and no list at all), but this is just an example; I'd like to learn how to proper exploit data type rules for "complex" types, from the grammar to the code generation step.


Thank you
B
Re: data type rule - list [message #685931 is a reply to message #685923] Mon, 20 June 2011 20:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

why don't you use a list of floats in a eclass?

Vector3 :
'(' floats+=FLOAT ',' floats+=FLOAT ',' floats+=FLOAT')';

Xtend(1)s handling of DataTypes in kind of hardcoded (see EmfRegistryMetaModel) so its hard to adopt.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 20 June 2011 20:18]

Report message to a moderator

Re: data type rule - list [message #685975 is a reply to message #685931] Tue, 21 June 2011 08:28 Go to previous messageGo to next message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
Thank you,

I didn't know I could do that (I mean setting elements of a list feature with anything else than (floats+=FLOAT)*, which cannot enforce a fixed length)

I'll try it out.

But I am still wondering how to properly exploit complex data types that my value converters might return.
I don't quite understand your last comment: which DataTypes you mean? Java types? What should I read about EmfRegistryMetaModel? Its source code?
I am sorry but my background knowledge of EMF or whatever meta-stuff is behind xtext/xpand is still quite limited..

Thanks again
B
Re: data type rule - list [message #686015 is a reply to message #685975] Tue, 21 June 2011 11:40 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the emf registry metamodel should be not nonger relevant if you use JavaBeansMetamodel (Default) in you Xpand Code generator.
this Generator then should work with the Java Class you assign to the Datatype. So in your case you may have to crate a own ecore model (+ generate its java classes) for you complex datatypes mapping to a java class that fulfils your requirements.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Integrate Xtext editor in a multipageEditor
Next Topic:Cross reference - not sure how to do it here
Goto Forum:
  


Current Time: Fri Apr 19 23:32:42 GMT 2024

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

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

Back to the top