Scoping question, references to sub-elements of auto-imported elements [message #813401] |
Mon, 05 March 2012 03:10  |
Eclipse User |
|
|
|
Hi,
Bit of a n00b question, sorry. I have a DSL that contains things similar to the following:
Dsl_Type:
'Dsl_Type' name = ID body = (Enumeration_Type | Integer_Type | etc) ';'
;
Enumeration_Type:
'Enumerated' '(' enums += Enum_Val (',' enums += Enum_Val)* ')'
;
Enum_Val:
name = ID
;
Check_Type:
'Check_Type' ref = [Dsl_Type] ';'
;
Enum_Ref:
'Check_Enum' ref = [Enum_Val] ';'
;
And I might have in one file:
Dsl_Type the_enum Enumerated ( foo, bar, smith );
And in the other:
Check_Type the_enum;
Check_Enum foo;
My MWE2 has:
fragment = scoping.ImportNamespacesScopingFragment { ignoreCase = true }
My problem is that Check_Type works but Check_Enum fails to link. I've been building up a custom MyDslScopeProvider that (successfully) does custom scoping work in other parts of the DSL but so far it only has needed to traverse the parse tree within a single source file. I've found that my ScopeProvider's superclass (AbstraceDeclarativeScopeProvider) has a delegate which is an ImportedNamespaceAwareLocalScopeProvider, and that that delegate is successfully finding the names of all top-level objects in all files in the project. Therefore, Check_Type works without any effort on my part because the delegate can find the names of all the types declared throughout the project.
The problem is that it doesn't find all the Enum_Vals because they're buried a couple of layers deeper.
How do I (presumably in MyDslScopeProvider) obtain a project-global list of all top-level objects? If I had that, I could find all of my enum types and therefore build a scope containing all of the Enum_Val names.
I tried the obvious (to me) path of repeatedly calling eContainer() on context inside getScope() to get to the root, but that only works if the enum is declared in the same file as the Check_Enum because eContainer() halts at the top of the current file. I need to get the global set of Dsl_Type, just like the default mechanism is managing to do.
thanks...
|
|
|
|
Re: Scoping question, references to sub-elements of auto-imported elements [message #814015 is a reply to message #813410] |
Mon, 05 March 2012 18:52  |
Eclipse User |
|
|
|
Hi Christian,
The DSL itself is old and has a huge codebase, so I can't make any changes like (2) that require references to an enum to be fully qualified. I found your excellent instructions* for (1) and that has solved this particular problem, thanks.
* "IQualifiedNameProviders in Xtext 2.0" on christiandietrich.wordpress.com if anyone is googling, but I can't link to it because the forum thinks I could be spamming
[Updated on: Mon, 05 March 2012 18:52] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.05896 seconds