Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext-Ecore problem with cross-reference and abstraction/specialization
Xtext-Ecore problem with cross-reference and abstraction/specialization [message #1036590] Mon, 08 April 2013 15:25 Go to next message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
Registered: November 2010
Member
Hi all,

I have a project were I defined three meta-models based on EMF.
In particular the third model has cross-references to the first two (i.e. some of the classes defined in the third model (C) contains references to objects of types defined in the first two (A and B)).

For the models A and B I've implemented a graphical representation with GMF.
For the model C I'm actually using the tree-editor provided by EMF.
With that Editor I'm able to cross-referencing entities defined in the A and B by importing them by means of the command "load resources".

I would like to implement a textual DSL for the model C and I thought to use XText.

I have two problems:

1) How can I cross-reference an object defined in A or B which are defined with my GMF editors?

In the grammar I used the syntax 'xyz' zyx=[model_alias::xyz|STRING]. However when I start the Xtext Editor I don't find an analogue of the EMF command "load resource" which allows me to reference the field "xyz" to one of the objects defined in A or B. How can I implement it?

2) Actually the model C is made of C1, C2, C3. C1 defines some abstract concepts which are specialized in C2 and C3. For these concept I wrote the rules (the rules also shows the reference to objects of the other models [problem 1]):

AbstractElement returns model_C1::AbstractElement :
	ConcreteElementA |  ConcreteElementB
	
;

ConcreteElementA returns model_C2::ConcreteElementA:
	xyz+=[model_A::Xyz] ("," xyz+=[model_A::Xyz])
;

ConcreteElementA returns model_C3::ConcreteElementB:
	xyz+=[model_A::Xyz] ("," xyz+=[model_A::Xyz])
;


The compilation here returns the error:

warning(200): ../myDSL/src-gen/myDSL/parser/antlr/internal/InternalResolutionDSL.g:295:1: Decision can match input such as "RULE_ID ',' RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
error(201): ../myDSL/src-gen/myDSL/parser/antlr/internal/InternalResolutionDSL.g:295:1: The following alternatives can never be matched: 2

When I remove the string "| ConcreteElementB" from the rules "AbstractElement" I'm able to compile without erros. How can I fix the second problem?
Re: Xtext-Ecore problem with cross-reference and abstraction/specialization [message #1036601 is a reply to message #1036590] Mon, 08 April 2013 15:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
HI,

the grammar must not be ambigous.
the only way to solve this is
(a) change the syntax
(b) introduce a common supertype and have only one rule

for referenceing non xtext model you have to implement an iresourceserviceprovider
http://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext-Ecore problem with cross-reference and abstraction/specialization [message #1036674 is a reply to message #1036601] Mon, 08 April 2013 17:23 Go to previous messageGo to next message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
Registered: November 2010
Member
Hi,

Christian Dietrich wrote on Mon, 08 April 2013 11:42
HI,

the grammar must not be ambigous.
the only way to solve this is
(a) change the syntax


Can you provide an example please? I'm really new to XText.

Christian Dietrich wrote on Mon, 08 April 2013 11:42
(b) introduce a common supertype and have only one rule


Actually in the metamodels AbstractElement is already a supertype of ConcreteElementA abd ConcreteElementB. Is that what you means?

Christian Dietrich wrote on Mon, 08 April 2013 11:42
for referenceing non xtext model you have to implement an iresourceserviceprovider
http://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/

Re: Xtext-Ecore problem with cross-reference and abstraction/specialization [message #1036682 is a reply to message #1036674] Mon, 08 April 2013 17:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
If you have

instead of:

X:A|B;
A: a=[A]
B: b=[B]

use

Y: aorb=[AorB]

with AorB being supertype of a and b in the metamodel.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext-Ecore problem with cross-reference and abstraction/specialization [message #1037082 is a reply to message #1036682] Tue, 09 April 2013 06:44 Go to previous messageGo to next message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
Registered: November 2010
Member
Thanks Christian.

I'm sorry but I don't understand how to do it.

Currently I have:

Container returns model_C1::Container :
 	('elements' elements=AbstractElement)?
:

AbstractElement returns model_C1::AbstractElement :
	ConcreteElementA |  ConcreteElementB
	
;

ConcreteElementA returns model_C2::ConcreteElementA:
	xyz+=[model_A::Xyz] ("," xyz+=[model_A::Xyz])
;

ConcreteElementA returns model_C3::ConcreteElementB:
	abc+=[model_A::Abc] ("," xyz+=[model_A::Abc])
;


In my metamodel Container contains 1 Abstract Element, which is an abstract class specilized by ConcreteElementA and ConcreteElementB.

I tried:


  • To remove the second rule(AbstractElement), and to
  • To write ('elements' elements=[model_C::AbstractElement])? in the second rule


But none of them work. I always have syntactical errors.

In other words I didn't understand how to do this:

Christian Dietrich wrote on Mon, 08 April 2013 13:30

use

Y: aorb=[AorB]

with AorB being supertype of a and b in the metamodel.


For what regards the other problem I will try to apply the idea suggested in your link.

Thanks again
Re: Xtext-Ecore problem with cross-reference and abstraction/specialization [message #1037099 is a reply to message #1037082] Tue, 09 April 2013 07:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I mean

AbstractElement returns model_C1::AbstractElement :
whatever+=[model_A::XyzOrAbc] ("," whatever+=[model_A::XyzOrAbc])

;

You have to add XyzOrAbc to the metamodel and add it as supertype to Abc and Xyz



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext-Ecore problem with cross-reference and abstraction/specialization [message #1037105 is a reply to message #1037099] Tue, 09 April 2013 07:12 Go to previous messageGo to next message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
Registered: November 2010
Member
Ok,

Now I think I have understood.
The problem is that I cannot modify the elements contained in the model_A and model_B.

Hence I cannot define an element XyzOrAbc which is a supertype of Xyz and Abc.

This is why I encapsulated them in ConcreteElement1 and ConcreteElement2, wihch are subtypes of AbstractElement.

Is there an alternative?
Re: Xtext-Ecore problem with cross-reference and abstraction/specialization [message #1037117 is a reply to message #1037105] Tue, 09 April 2013 07:29 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Yes change the syntax

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Code completion following ambiguous operator
Next Topic:RFC: Indentation based grammar
Goto Forum:
  


Current Time: Tue Apr 23 07:27:25 GMT 2024

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

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

Back to the top