I'm trying to get cross-references to work in my DSL. Here's a stripped down version of the grammar (a modified version of the standard example DSL):
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Releases:
releases+=Release*
;
terminal VERSION : ('0'..'9')+'.'('0'..'9')+('.'('0'..'9'|'x')+)?;
Release:
'release' version = VERSION ('extends' parent = [Release|VERSION])?
;
Since I'm not using the standard name = ID
pattern, I followed this blog post about how to create my own IQualifiedNameProvider
:
public class MyDslQNP extends DefaultDeclarativeQualifiedNameProvider {
QualifiedName qualifiedName(Release e) {
Package p = (Package) e.eContainer();
return QualifiedName.create(p.getName(), e.getVersion());
}
}
From another answer on SO, I gathered that I should implement my own scope provider:
public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
IScope scope_Release_parent(Release release, EReference ref) {
Releases releases = (Releases) release.eContainer();
return Scopes.scopeFor(releases.getReleases());
}
}
I've also bound these in the runtime module:
public class MyDslRuntimeModule extends
org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
@Override
public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
return MyDslQNP.class;
}
@Override
public Class<? extends IScopeProvider> bindIScopeProvider() {
return MyDslScopeProvider.class;
}
}
When running the generated editor I create a file which looks like this:
release 1.2.3
release 1.2.2 extends 1.2.3
The problem is that (1) the editor won't autocomplete on the 'extends' clause, and (2) the editor shows an error message Couldn't resolve reference to Release '1.2.3'
.
What am I missing?