Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-reference without dot symbol(Cross-reference without dot symbol)
Cross-reference without dot symbol [message #1820561] Wed, 22 January 2020 21:19 Go to next message
kolchanov Mising name is currently offline kolchanov Mising nameFriend
Messages: 20
Registered: October 2011
Junior Member
Hello,
I have a test grammar with cross-reference
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	items+= (Entity | Sublist)* ;

FQN: ID ('.' ID)*;

Entity: 
	'entity' name=ID '{'
	attrs+=Attribute*
	'}' 
;

Attribute:  name=ID ';' ;

Sublist:
	'sublist' entity = [Entity|ID] '{'
		(attrs+=[Attribute|FQN] ';')*
	'}' ;

And all is ok with file
entity EntityA { a;b;c; }
sublist EntityA { EntityA.a; EntityA.b;	}


Is it possible to implement cross-reference to Attribute without dot symbol like
entity EntityA { a;b;c; }
sublist EntityA { a; b;	}

and filter attributes by Entity in custom scope provider?
Re: Cross-reference without dot symbol [message #1820570 is a reply to message #1820561] Thu, 23 January 2020 05:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

You should implement a scope provider for the sublists
Attribute

from the context retrieve the entity of the sublists
Ask it for it's attributes and put it into the scope


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-reference without dot symbol [message #1820574 is a reply to message #1820570] Thu, 23 January 2020 07:54 Go to previous message
kolchanov Mising name is currently offline kolchanov Mising nameFriend
Messages: 20
Registered: October 2011
Junior Member
Thank you!

Simple scope provider solves my question:
public class MyDslScopeProvider extends AbstractMyDslScopeProvider {

	@Override
	public IScope getScope(EObject context, EReference ref) {
		
		if (ref == MyDslPackage.Literals.SUBLIST__ATTRS) {
			Sublist sublist=(Sublist) context;			
			return Scopes.scopeFor(sublist.getEntity().getAttrs());
		}
		return super.getScope(context, ref);
	}
}



Previous Topic:Orion Web Editor: xtext-web functions are not available
Next Topic:The filename or extension is too long
Goto Forum:
  


Current Time: Tue Apr 16 12:28:23 GMT 2024

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

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

Back to the top