Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Scoping question, references to sub-elements of auto-imported elements
Scoping question, references to sub-elements of auto-imported elements [message #813401] Mon, 05 March 2012 08:10 Go to next message
William Brodie-Tyrrell is currently offline William Brodie-TyrrellFriend
Messages: 4
Registered: March 2012
Junior Member
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 #813410 is a reply to message #813401] Mon, 05 March 2012 08:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13416
Registered: July 2009
Senior Member
Hi, you enums have the name
Dsltypename.enumname

So you have
(1) change this using a custom IQualifiedNameProvider e.g. by
Subclassing DefaultDeclarativeQualifiedName Provider

(2) change the grammar to allow Qualified names
FQN:ID ("." ID)*; ref=[Type|FQN]


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Scoping question, references to sub-elements of auto-imported elements [message #814015 is a reply to message #813410] Mon, 05 March 2012 23:52 Go to previous message
William Brodie-Tyrrell is currently offline William Brodie-TyrrellFriend
Messages: 4
Registered: March 2012
Junior Member
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 23:52]

Report message to a moderator

Previous Topic:Help with xtext grammar void method
Next Topic:How can I let my xbase based language takes basic extension like Xtend does?
Goto Forum:
  


Current Time: Mon Mar 30 20:25:06 GMT 2020

Powered by FUDForum. Page generated in 0.04013 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top