|
|
Re: Context-dependent Name Resolution [message #1732511 is a reply to message #1732508] |
Tue, 17 May 2016 19:25 |
|
e.g. (implemented with Xtext >= 2.9.x)
Model:
elements+=Element*;
Element:
Struct | StructInstance | WithClause
;
Struct:
"struct" name=ID "{"
properties += Property*
"}"
;
Property:
name=ID ";"
;
StructInstance:
struct=[Struct] name=ID ";"
;
WithClause:
"with" "(" structInstance=[StructInstance] ")" "{"
assignments+=Assignment*
"}"
;
Assignment:
property=[Property] "=" value=INT
;
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override getScope(EObject context, EReference reference) {
if (reference == MyDslPackage.Literals.ASSIGNMENT__PROPERTY) {
val withClause = EcoreUtil2.getContainerOfType(context, WithClause)
if (withClause != null) {
return Scopes.scopeFor(withClause.structInstance.struct.properties)
}
}
super.getScope(context, reference)
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Re: Context-dependent Name Resolution [message #1732514 is a reply to message #1732511] |
Tue, 17 May 2016 19:37 |
|
A scope is a collection of ieobjectdescriptions (basically a pair of name and eobject(uri))
Well - it depends.
How the names for the xtext index are built is the IQualifiedNameProvider which is usually implemented by DefaultDeclarativeQualifiedNameProvider
For the scope provider: there are other methods inside the scopes class e.g. One that takes the list of objects (the scope) the parent scope (I scope.nullscope) and a function that calculates the qualified name for a given eobject
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Context-dependent Name Resolution [message #1732518 is a reply to message #1732514] |
Tue, 17 May 2016 19:53 |
Charles Baker Messages: 9 Registered: May 2016 |
Junior Member |
|
|
Is there any alternative to Scopes.scopeFor that lets me provide my own way of mapping names to URIs? I need "a" to resolve to "#MyStruct/a" (if that's the correct syntax) instead of just "#a". By printing the URIs, I've discovered that it just appends the name of the property, without the name of the structure, and that can't possibly work because I need to be able to have different structures that share a property name. as in:
struct MyStructA { int a; }
struct MyStructB { int a; }
Perhaps I can somehow create the IScope manually?
[Updated on: Tue, 17 May 2016 20:01] Report message to a moderator
|
|
|
|
|
Re: Context-dependent Name Resolution [message #1732521 is a reply to message #1732520] |
Tue, 17 May 2016 20:11 |
Charles Baker Messages: 9 Registered: May 2016 |
Junior Member |
|
|
No matter what I try, I keep getting a "Couldn't resolve reference" error in Eclipse. Could the URIs of my EObjects be wrong somehow?
I tried this:
var descriptions = new ArrayList<IEObjectDescription>();
for (Attribute attribute : context.type.attributes) {
descriptions.add(EObjectDescription.create(QualifiedName.create(attribute.name), attribute);
}
return new SimpleScope(descriptions);
I guess I should also mention it accepts this:
with (myStruct) { "StructureName.a" = 5; }
but not this:
with (myStruct) { a = 5; }
The latter gets a "Couldn't resolve reference to Attribute 'a'" error.
According to my QualifiedNameProvider, the fully qualified name of "a" is "program.MyStructure.a".
[Updated on: Tue, 17 May 2016 20:15] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03934 seconds