Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Local Scope and Shadowing
Local Scope and Shadowing [message #705343] Fri, 29 July 2011 18:55 Go to next message
Rafael Angarita is currently offline Rafael AngaritaFriend
Messages: 94
Registered: November 2010
Member
Hello, I've been reading other posts and blogs about local scoping but I don't getting, I think I am missing something.

Here is my example:

Model:
	A |
	R
;

A:
	'A' name=ID
;

R:
	'R' name=ID
	objectReference=ObjectReference
	innerObject=InnerObject
;
InnerObject:
	'innerObject' name=STRING
;

ObjectReference:
	object=[ecore::EObject]
;



My scope provider, where I filter objects by they file extension:

public IScope scope_ObjectReference_object(EObject i, EReference r) {
		return new org.eclipse.xtext.scoping.impl.FilteringScope(delegateGetScope(i, r),new Predicate<IEObjectDescription>() {
			@Override
			public boolean apply(IEObjectDescription input) {
				
				return input!=null && input.getEObjectURI()!=null &&  input.getEObjectURI().fileExtension()!=null &&
						(input.getEObjectURI().fileExtension().equals("a")
								);

			};
		});
		
	}


Now, I want to write this code:

file: R.r
R myr
mya   
innerObject 'mya' 


file: mya.a

A mya


, but as expected, innerObject 'mya' shadows the object in mya.a, so I get "Couldn't resolve reference to EObject 'mya'".

How should I do this?

Thank you very much for your help and advices.


PD: I noted the filtering does not work since the local object "mya" shadows the global object before the call to the scope_ObjectReference_object method.

[Updated on: Fri, 29 July 2011 18:59]

Report message to a moderator

Re: Local Scope and Shadowing [message #705361 is a reply to message #705343] Fri, 29 July 2011 19:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
Hi, if you want to ref only stuff of yourdsl why don't you state this in the grammar? why referening an eobject?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Local Scope and Shadowing [message #705365 is a reply to message #705361] Fri, 29 July 2011 19:42 Go to previous messageGo to next message
Rafael Angarita is currently offline Rafael AngaritaFriend
Messages: 94
Registered: November 2010
Member
Hi, Christian.

How can I do that if I have different types of eobjects I could reference there? For example, if I try:

ObjectReference:
	object= ([A]|[B])
;


I get " Decision can match input such as "'innerObject'" using multiple alternatives: 1, 2"
Re: Local Scope and Shadowing [message #705386 is a reply to message #705365] Fri, 29 July 2011 20:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13898
Registered: July 2009
Senior Member
Hi,

if you have control over the types: create a common supertype e.g. by adding a rule
AorB : A | B; to your a dsl.

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Local Scope and Shadowing [message #705426 is a reply to message #705386] Fri, 29 July 2011 21:27 Go to previous message
Rafael Angarita is currently offline Rafael AngaritaFriend
Messages: 94
Registered: November 2010
Member
I guess that would be the easier and less error prone way to go, so the right way.

Thank you very much.
Previous Topic:Creating grammar mixin
Next Topic:[Xtext2.0] Validation
Goto Forum:
  


Current Time: Fri Apr 23 15:19:33 GMT 2021

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

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

Back to the top