Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Producing multiple objects from one rule
Producing multiple objects from one rule [message #1754675] Tue, 21 February 2017 13:10 Go to next message
Eric Lépicier is currently offline Eric LépicierFriend
Messages: 25
Registered: October 2013
Junior Member
Hi,

I'm trying to parse things like :
int i, j;
double d,e;

and get a model containing Var objects with type and name, one for each of i, j, d, e.

I'd like to naively write a rule like this:
Model:
   vars+=VarDecl*
;
VarDecl:
   type=TypeSpec {Var} name=ID (',' {Var} name=ID)*
;
TypeSpec:
   {Int} 'int'
   | {Double} 'double'
;

But this is incorrect as one can't put two {Var} clauses in the same rule ?
Validation complains about "unassigned action not allowed when the current was already created".

I thought about rewriting my grammar in this way:
Model:
   vars+=VarDecl*
;
VarDecl:
   type=TypeSpec vars+=Var (',' vars+=Var)*
;
Var:
   name=ID
;
TypeSpec:
   {Int} 'int'
   | {Double} 'double'
;

But now, how to get a type property on Var object ?
How to remove the unwanted VarDecl grouping classifier ?

Is there a solution with XText ?

Cheers,
--Eric
Re: Producing multiple objects from one rule [message #1754676 is a reply to message #1754675] Tue, 21 February 2017 13:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14733
Registered: July 2009
Senior Member
getting rid? hard to do.
get it working: http://xtextcasts.org/episodes/18-model-optimization


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Producing multiple objects from one rule [message #1754703 is a reply to message #1754676] Tue, 21 February 2017 16:35 Go to previous messageGo to next message
Eric Lépicier is currently offline Eric LépicierFriend
Messages: 25
Registered: October 2013
Junior Member
Thanks Christian, exactly the topic ...
I didn't got the right keywords in my previous web searches ;-(

I'm gonna watch and read carefully the contents you mention.

Cheers,
--Eric
Re: Producing multiple objects from one rule [message #1754709 is a reply to message #1754703] Tue, 21 February 2017 17:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14733
Registered: July 2009
Senior Member
Depending on your usecase and Xtext version you will stumble over https://bugs.eclipse.org/bugs/show_bug.cgi?id=483209

Other possible workaround in to add uncalled rules to the grammar to manipulate the metamodel

Var:name=ID;
//uncalled
VarWithType returns Var:
type=TypeSpec name=ID;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Producing multiple objects from one rule [message #1754865 is a reply to message #1754709] Thu, 23 February 2017 10:45 Go to previous messageGo to next message
Eric Lépicier is currently offline Eric LépicierFriend
Messages: 25
Registered: October 2013
Junior Member
I'm working with Juno and XText 2.3 ;-( and still for a few months.

I read the doc and watched the screencast. It's really interesting, but in my case too complicated for the benefits.
For the moment, I'll keep an intermediate class like a "DeclarationBlock" with contained "Declaration"s.

Uncalled rules also seems an interesting concept, but I don't understand how it could solve my specific problem ?
Could you develop on your Var example, usage and effects on generated M2 ?

I also read the bug thread, I understand that metamodel and model postprocessing will no longer be supported in XText ?

Cheers,
--Eric
Re: Producing multiple objects from one rule [message #1754866 is a reply to message #1754709] Thu, 23 February 2017 10:45 Go to previous messageGo to next message
Eric Lépicier is currently offline Eric LépicierFriend
Messages: 25
Registered: October 2013
Junior Member
[Removed duplicate]

[Updated on: Thu, 23 February 2017 10:47]

Report message to a moderator

Re: Producing multiple objects from one rule [message #1754872 is a reply to message #1754866] Thu, 23 February 2017 12:05 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14733
Registered: July 2009
Senior Member
it is still supported but might not be forever.

// from here xtext inferrs a Class Var with an attribute name of type String
Var:name=ID;


//uncalled from here Xtext will detect that Var (the returns thing) also has a containment reference name "type" of type TypeSpec
VarWithType returns Var:
type=TypeSpec name=ID;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:JDT - Check Instance of RuntimeException
Next Topic:Problems when referencing Ecore elements using an imported Ecore model
Goto Forum:
  


Current Time: Thu Nov 14 04:44:11 GMT 2024

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

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

Back to the top