Scoping vs Naming [message #938924] |
Wed, 10 October 2012 05:24  |
Eclipse User |
|
|
|
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 #939364 is a reply to message #939013] |
Wed, 10 October 2012 13:43  |
Eclipse User |
|
|
|
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!
|
|
|
Powered by
FUDForum. Page generated in 0.06064 seconds