Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext] Multiple objects in one line
[Xtext] Multiple objects in one line [message #482335] Wed, 26 August 2009 09:56 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Hi there,

I have to parse multiple objects in one line like e.g. variable
declarations in Java or C:

int a,b,c;
float d,e,f;

This should be parsed into 6 objects of class Variable and the first
three have a type attribute "int" and the last three a type attribute
"float".

How could I do this?

Variable:
type=Type name=ID;

this only parses a single variable.

Variable:
type=Type name=ID
(',' {Variable.left=current} name=ID)*;

this correctly creates new Variable objects, but they have no type.
Additionally the objects have a strange parent relationship.
Adding the type=Type also to the comma separated part would expect
another "int" token after each comma.

Any other idea?

Cheers,
Hauke
Re: [Xtext] Multiple objects in one line [message #482367 is a reply to message #482335] Wed, 26 August 2009 11:30 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi Hauke,

is it an option for you to access the variable type via a helper
function? I am thinking about the following:

Declaration: type=Type (variable+=Variable)+ ';';
Variable: name=ID;

Then you get the type of a variable via its eContainer;

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: [Xtext] Multiple objects in one line [message #482426 is a reply to message #482335] Wed, 26 August 2009 13:56 Go to previous messageGo to next message
Knut Wannheden is currently offline Knut WannhedenFriend
Messages: 298
Registered: July 2009
Senior Member
Hi Hauke,

In addition to Alex' grammar you may also want to use the post processor
hook to either add an EOperation getType() or an EReference "type" to
Variable. Both approaches have advantages and disadvantages -- YMMV. If
you add an EReference you should override the Linker service to initialize
the reference (probably with the value
eContainer().eGet(MyDslPackage.Literals.DECLARATION__TYPE, false)) for you.

Hope that helps,

--knut
Re: [Xtext] Multiple objects in one line [message #700067 is a reply to message #482426] Fri, 22 July 2011 19:39 Go to previous messageGo to next message
amey.par is currently offline amey.parFriend
Messages: 17
Registered: July 2011
Junior Member
Knut Wannheden wrote on Wed, 26 August 2009 09:56
Hi Hauke,

In addition to Alex' grammar you may also want to use the post processor
hook to either add an EOperation getType() or an EReference "type" to
Variable. Both approaches have advantages and disadvantages -- YMMV. If
you add an EReference you should override the Linker service to initialize
the reference (probably with the value
eContainer().eGet(MyDslPackage.Literals.DECLARATION__TYPE, false)) for you.

Hope that helps,

--knut


I really hate to bump such an old thread, but this is the only relevant info I could find after an hour of searching.

I've already implemented Alex's grammar and ran into the OP's problem. Knut, could you please explain how I should go about injecting getType for my "Variable"? I'm new to Xtext and couldn't find any example of anyone doing this.
Re: [Xtext] Multiple objects in one line [message #700099 is a reply to message #700067] Fri, 22 July 2011 20:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13614
Registered: July 2009
Senior Member
Hi,

a little googling gave me
http://wiki.eclipse.org/Xtext/FAQ#How_can_I_control_the_Xtext_meta_model_inference.C2.A0.3F
http://jevopisdeveloperblog.blogspot.com/2011_03_14_archive.html

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtext] Multiple objects in one line [message #700100 is a reply to message #700099] Fri, 22 July 2011 20:48 Go to previous message
amey.par is currently offline amey.parFriend
Messages: 17
Registered: July 2011
Junior Member
Hi,

I found the second link myself but failed to realize how I could adapt it to suit my requirement (like I said, I've just gotten started with Xtext)

Thanks a lot for the first link, it looks like something I can grasp.

Amey
Previous Topic:standalone parser and generator
Next Topic:[xtend] Generic return type for EOperation
Goto Forum:
  


Current Time: Wed Sep 30 00:03:22 GMT 2020

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

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

Back to the top