Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [Xtext] Multiple objects in one line
[Xtext] Multiple objects in one line [message #482335] Wed, 26 August 2009 05:56 Go to next message
Eclipse UserFriend
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 07:30 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: [Xtext] Multiple objects in one line [message #482426 is a reply to message #482335] Wed, 26 August 2009 09:56 Go to previous messageGo to next message
Eclipse UserFriend
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 15:39 Go to previous messageGo to next message
Eclipse UserFriend
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 16:44 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: [Xtext] Multiple objects in one line [message #700100 is a reply to message #700099] Fri, 22 July 2011 16:48 Go to previous message
Eclipse UserFriend
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: Sat Jul 12 16:34:03 EDT 2025

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

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

Back to the top