Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Ambiguous cross reference
Ambiguous cross reference [message #1740812] Thu, 18 August 2016 16:47 Go to next message
Maged Elaasar is currently offline Maged ElaasarFriend
Messages: 23
Registered: September 2013
Junior Member
My Xtext grammar has rules that resemble the following:

A:
    'A' name=ID;
B:
    'B' name=ID;
C:
    'C' name=ID;
D:
    A|B;
Relationship:
    ('A' source=[A] | 'B' source=[B]) '=>' target=[C];


I do not get any errors or warnings about ambiguity from Xtext.

I can express models like the following with no errors:

A a1
B b1
C c1
A a1 => c1 // expected
B b1 => c1 // expected
A b1 => c1 // not expected
B a1 => c1 // not expected

My question is why the last two statements do not give errors? How can I change the grammar (rather than the metamodel since it's given) to enforce that? Also, when I create a model, using the Ecore reflective model editor, that creates (a1, b1 and c1) and then a relationship from b1 to c1, and then I look at how it got serialized in the Xtext editor, I see it

A b1 => c 1 //not expected

Thanks for your help.

[Updated on: Thu, 18 August 2016 16:50]

Report message to a moderator

Re: Ambiguous cross reference [message #1740813 is a reply to message #1740812] Thu, 18 August 2016 16:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
The cross referencing is done by the inferred metamodel and not the grammar

So what about naming the references sourcea and sourceb


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Ambiguous cross reference [message #1740814 is a reply to message #1740813] Thu, 18 August 2016 16:56 Go to previous messageGo to next message
Maged Elaasar is currently offline Maged ElaasarFriend
Messages: 23
Registered: September 2013
Junior Member
That would involve changing the metamodel, right? As I said earlier, the metamodel is given not inferred, and source is of type D.
Re: Ambiguous cross reference [message #1740817 is a reply to message #1740814] Thu, 18 August 2016 17:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Is the syntax given as well?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Ambiguous cross reference [message #1740819 is a reply to message #1740814] Thu, 18 August 2016 17:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Maged

It seems like a bug to me, but without a working example I cannot
experiment.

You might try bring more explicit:

.... returns A:
.... source=[A|ID]

Regards

Ed Willink





On 18/08/2016 17:56, Maged Elaasar wrote:
> That would involve changing the metamodel, right? As I said earlier, the
> metamodel is given not inferred, and source is of type D.


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Re: Ambiguous cross reference [message #1740820 is a reply to message #1740819] Thu, 18 August 2016 17:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
If you stick to the grammar you can adapt linking/scopeprovider content assist and maybe the serializer

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Ambiguous cross reference [message #1740821 is a reply to message #1740820] Thu, 18 August 2016 17:30 Go to previous messageGo to next message
Maged Elaasar is currently offline Maged ElaasarFriend
Messages: 23
Registered: September 2013
Junior Member
The grammar (and syntax) is not given, I can change it. It's only the metamodel I cannot change.

[Updated on: Thu, 18 August 2016 17:31]

Report message to a moderator

Re: Ambiguous cross reference [message #1740826 is a reply to message #1740821] Thu, 18 August 2016 18:12 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
what you can do is

Relationship:
    ({Relationship}'A' source=[A] | {Relationship} 'B' source=[B]) '=>' target=[C];


class MyDslScopeProvider extends AbstractMyDslScopeProvider {
	
	@Inject
	MyDslGrammarAccess ga
	
	override getScope(EObject context, EReference reference) {
		if (context instanceof Relationship) {
			if (reference == MyDslPackage.Literals.RELATIONSHIP__SOURCE) {
				val node = NodeModelUtils.findActualNodeFor(context)
				if (node != null) {
					for (cn : node.asTreeIterable) {
						if (cn.grammarElement === ga.relationshipAccess.AKeyword_0_0_0) {
							return delegateGetScope(context, EcoreFactory.eINSTANCE.createEReference=>[EType = MyDslPackage.Literals.A])
						} else if (cn.grammarElement === ga.relationshipAccess.BKeyword_0_1_0) {
							return delegateGetScope(context, EcoreFactory.eINSTANCE.createEReference=>[EType = MyDslPackage.Literals.B])
						}
					}
				}
			}
		}
		super.getScope(context, reference)
	}

}



class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	override completeRelationship_Source(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		val n = context.currentNode
		if(n instanceof HiddenLeafNode) {
			if ("A" == n.previousSibling?.text) {
				lookupCrossReference(context.getCurrentModel(), EcoreFactory.eINSTANCE.createEReference=>[EType = MyDslPackage.Literals.A], acceptor, Predicates.<IEObjectDescription> alwaysTrue(), getProposalFactory("ID", context));
				return
			} else if ("B" == n.previousSibling?.text) {
				lookupCrossReference(context.getCurrentModel(), EcoreFactory.eINSTANCE.createEReference=>[EType = MyDslPackage.Literals.B], acceptor, Predicates.<IEObjectDescription> alwaysTrue(), getProposalFactory("ID", context));
				return
			}
		} else if (n instanceof LeafNode) {
			if ("A" == n.previousSibling?.previousSibling?.text) {
				lookupCrossReference(context.getCurrentModel(), EcoreFactory.eINSTANCE.createEReference=>[EType = MyDslPackage.Literals.A], acceptor, Predicates.<IEObjectDescription> alwaysTrue(), getProposalFactory("ID", context));
				return
			} else if ("B" == n.previousSibling?.previousSibling?.text) {
				lookupCrossReference(context.getCurrentModel(), EcoreFactory.eINSTANCE.createEReference=>[EType = MyDslPackage.Literals.B], acceptor, Predicates.<IEObjectDescription> alwaysTrue(), getProposalFactory("ID", context));
				return
			}
		}
		super.completeRelationship_Source(model, assignment, context, acceptor)
		
	}
	
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:xtext create open declaration
Next Topic:Import Resolution - XBase
Goto Forum:
  


Current Time: Thu Apr 25 15:31:56 GMT 2024

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

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

Back to the top