Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scoping vs Naming
Scoping vs Naming [message #938924] Wed, 10 October 2012 09:24 Go to next message
Quentin Boucher is currently offline Quentin BoucherFriend
Messages: 27
Registered: July 2012
Junior Member
Hello,

I am a bit confused with naming and scoping notions. I started to implement scoping methods but I realise it is (probably) not the right solution for me.

In practice, my requirements are the following:
- All elements are available from anywhere
- An element can be referenced from anywhere either with its simple name, e.g. D, or its qualified name A.B.C.D.
- Some keywords have been defined like this, root, parent

I have tried to implement scoping methods but it is not the right solution for me. At least, I think it is the right way to implement the "this", "root" and "parent" keyword. But how do I implement qualified and simple name resolution and auto-completion?

Thank you for your help!
Re: Scoping vs Naming [message #939013 is a reply to message #938924] Wed, 10 October 2012 10:51 Go to previous messageGo to next message
Quentin Boucher is currently offline Quentin BoucherFriend
Messages: 27
Registered: July 2012
Junior Member
Actually, scoping seems to be the right way. I was just using them in a wrong way.
Re: Scoping vs Naming [message #939364 is a reply to message #939013] Wed, 10 October 2012 17:43 Go to previous message
Quentin Boucher is currently offline Quentin BoucherFriend
Messages: 27
Registered: July 2012
Junior Member
I've made some progress. However I am now stuck.

Here is an excerpt of my grammar:

Hierarchical_Feature:
	    optional?=('opt')? name=ID (group=Feature_Group)?
	  | shared?='shared' ref=[Hierarchical_Feature|ID];

Feature_Group:
	'group' cardinality=Cardinality '{' sub_features+=Hierarchical_Feature (',' sub_features+=Hierarchical_Feature)* '}';

Long_IDHeadAbstract: Feature | Hierarchical_Feature | Constant;

Long_ID: (head=[Long_IDHeadAbstract]| keyword=Shortcut) tail=(Long_IDTail)?;

Long_IDTail: '.' (head=[Hierarchical_Feature] (tail=Long_IDTail)?) | head=[Attribute];


Currently, I'm implementing the scoping of Long_IDTail's head attribute. Everything is implemented except that I don't have access to 'shared' features in my current implementation.

Here is the code accessing the Group elements:

if (feature.getGroup()!=null) {
				return Scopes.scopeFor(feature.getGroup().getSub_features());			}


I am able to access non-shared features but not shared ones. I made some tests and "feature.getGroup().getSub_features()" contains the shared features. It might be related to the lack of name for the referenced (shared) feature. So I implemented the following CustomNameProvider:

QualifiedName qualifiedName(Hierarchical_Feature feature) {
			if (!feature.isShared()) {
				return QualifiedName.create(feature.getName());
			}
			else {
				List<INode> nodes = NodeModelUtils.findNodesForFeature(feature,TVLPackage.Literals.FEATURE__REF);
				if (!nodes.isEmpty()) {
					INode first = nodes.get(0);
					return QualifiedName.create(NodeModelUtils.getTokenText(first));
				}
				return QualifiedName.create("Shared error");//TODO: improve
			}
		}


Do you have a clue to solve this?

Thank you in advance!

Previous Topic:Xtext 2.3 Nature and Builder Issues
Next Topic:Xtext interpreter to instantiate EMF Object
Goto Forum:
  


Current Time: Thu Mar 28 10:37:11 GMT 2024

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

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

Back to the top