Shadowing with ImportedNamespaceAwareSP [message #669278] |
Mon, 09 May 2011 17:32 |
Simon Stratmann Messages: 27 Registered: February 2011 |
Junior Member |
|
|
Hello,
I've been trying to adjust the ImportedNamespaceAwareScopeProvider.
Say this is part of my language:
entity e
var v;
block b
var v;
end entity;
Here the two different "v" variables aren't a problem because their QN are e.v and e.b.v respectively.
But look at this:
entity e
var v;
for v = 1 to 5
refTo v; //needs to refer to the loop counter
refTo e.v; //needs to refer to the "upper" v
end for;
end entity;
Here the second v has the same QN as the first one, so the validator shows an error, saying there's a duplicate variable. But the second should shadow the first one.
Any ideas on how I would achieve that? There are several cases / surrounding elements where this would need to be done.
Thanks,
Simon
[Updated on: Mon, 09 May 2011 17:52] Report message to a moderator
|
|
|
|
|
Re: Shadowing with ImportedNamespaceAwareSP [message #670516 is a reply to message #670506] |
Sat, 14 May 2011 16:05 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
Hi,
please make your scoping smart! The snippet you provide is not pointing in that direction.
a) Use EcoreUtil2.eAllContents only as a last resource. You know your model structure and thus can navigate to the elements you want in the scope
b) Use the inner/outer-scope possibilities (see blog posts by Sven Efftinge on the concept itself, the Scopes-method allow defining scopes with an inner and an outer one). Your language has a block structure, so the variables in the current block would go to the inner scope, those of containing block to the outer one (note, the outer scope has the same layer structure again). That way you automatically achieve the shadowing you want. Variables in the inner scope automatically hide variables with the same name in the outer scope as they are found first. Note that if an inner scope contains two variables with the same name, they hide each other.
c) use polymorphic dispatch in the scope provider. That way you don't have to do instance-of-cascades
Alex
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
|
|
|
Powered by
FUDForum. Page generated in 0.03554 seconds