Reputation: 3281
I have a grammar within Xtext that has a custom ScopeProvider
, which extends AbstractDeclarativeScopeProvider
. I am using this scope provider to accurately scope elements within the same DSL file.
It is simple to scope within the file, as one can simply traverse upwards/downwards through the model.
However, I'd now like to support imports from other classes. But I'm stuck how to find the elements in the other files from within my scope provider.
I can find instances of the import, which are specified in the grammar as:
Import:
"import" importURI=STRING
;
I can obtain the references to the import from the model, but this just contains the strings that are the URIs that reference the other files.
How to I get to the elements within the imported file?
Upvotes: 0
Views: 880
Reputation: 11868
hi i am not quite sure what your usecase is. the import statements simply makes the elements from the imported resources visible so that you can reference them
Model:
imports+=Import*
defines+=Define*
uses+=Use*
;
Import:
"import" importURI=STRING
;
Define:
"def" name=ID
;
Use:
"use" use=[Define]
;
with
a.mydsl
def a
b.mydsl
import "a.mydsl"
use a
i dont know why you explicitly want to search find it in the scopeprovider. they are visible automatically
you may call
delegeteGetScope(ctx,ref)
in the scopeprovider to access the outer scope (the one from the imported files) but what todo with it highly depends on your usecase
Upvotes: 2