Ambiguous cross reference [message #1740812] |
Thu, 18 August 2016 16:47 |
Maged Elaasar 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 #1740826 is a reply to message #1740821] |
Thu, 18 August 2016 18:12 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03442 seconds