Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with content assist and scoping
Problem with content assist and scoping [message #684923] Thu, 16 June 2011 13:35 Go to next message
Romain  Aïssat is currently offline Romain AïssatFriend
Messages: 16
Registered: June 2011
Junior Member
Hi,

Here is my grammar, allowing to define integers (with '+' as the only operator, to simplify...) :

Model:
	'int' declarations += IntDeclaration (',' declarations += IntDeclaration)* ';' ;
	
IntDeclaration :
	alias = IntAlias '=' exp = IntExpression;
	
IntAlias :
	name = ID;
	
IntExpression returns IntExpression :
	  TerminalIntExpression ({Add.left = current} '+' right = TerminalIntExpression)*;
	  
TerminalIntExpression returns IntExpression :
	Integer | IntReference | '(' IntExpression ')';
	
Integer :
	val = INT;
	
IntReference :
	referred = [IntAlias];



Furthermore, I defined a template named "Add" (with IntExpression as context) :

${left:CrossReference('IntReference.referred')} + ${right:CrossReference('IntReference.referred')}


I've also configured scoping to allow only IntAliases in the current resource, meaning that if my model is :

int a = 1, b = 2, c = (*);

- where (*) stands for Ctrl-Space - and I choose the "Add" template in the pop-up, proposals for both left and right terms are a, b and c.

Here is what I want to do : I'd like to remove (in this particular case) the c proposal : for example "int c = 2 + c;" has no sense in my DSL (constants are defined once and for all and can't be modified).

My problem is that i'm a bit confused with the way to achieve this. I extended the AbstractDeclarativeProvider with a method that computes the right scope (it's signature is :
public IScope scope_IntDeclaration_exp(IntDeclaration d, EReference ref)
) but this alone isn't enough.

When I'm in the same situation as before (choosing the Add template), the name of the current declaration still appear in the pop-up (and if I choose it, i've got an error saying that the reference couldn't be resolved, so i guess scoping is ok...).

I looked at proposal provider to find a way to make it work with respect to scoping but in vain... Any advice would be really appreciated!

Thanks in advance,

Romain

PS : sorry for bad english, didn't practice for a while now...

Re: Problem with content assist and scoping [message #685108 is a reply to message #684923] Thu, 16 June 2011 20:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am not quite sure that your scoping method makes sense.

its generally
public IScope scope_Container_refernecename(EObject context, EReference ref)


so shouldn't it be
public IScope scope_IntReference_referred(IntReference r, EReference ref)

and to cover the other possible contexts something like
public IScope scope_IntReference_referred(TerminalIntExpression r, EReference ref)
public IScope scope_IntReference_referred(IntExpression e, EReference ref)
public IScope scope_IntReference_referred(IntDeclaration r, EReference ref)


i'd juste debug the getscope method of your scope provider and see whats in the context in different situations.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem with content assist and scoping [message #685295 is a reply to message #685108] Fri, 17 June 2011 08:10 Go to previous message
Romain  Aïssat is currently offline Romain AïssatFriend
Messages: 16
Registered: June 2011
Junior Member
That's it : by changing the signature of the scope method to
public IScope scope_IntReference_referred(IntDeclaration d, EReference ref)
it works perfectly fine.

Thanks a lot!
Previous Topic:Cannot set dynamic help on certain actions
Next Topic:Can't ignore WS in rule
Goto Forum:
  


Current Time: Fri Apr 26 01:17:59 GMT 2024

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

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

Back to the top