Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Ambiguities in xText scoping "Context"
Ambiguities in xText scoping "Context" [message #1006852] Sat, 02 February 2013 17:26 Go to next message
Frank Tagne is currently offline Frank Tagne
Messages: 7
Registered: August 2012
Junior Member
Hello,

I'm dealing an scoping problem in my xtext language.

Let's see the grammar below and the associated MM (see attached)

CallService returns CallService:
	{CallService}
	'CallService' (=>'::'name=EString)?
	'{'
	     ('sourcePort' sourcePort=PortRef)?	
             ('targetPort' targetPort=PortRef)?
		
    '}';

PortRef returns PortRef: {PortRef} referencedPort=[PortEvent];
PortEvent returns PortEvent:'PortEvent'{PortEvent} (=>'::'name=EString)?;


index.php/fa/13271/0/

I would like to provide scoping rules for targetPort and sourcePort in such that the targetPort's scope should not contained PortRef assigned to sourcePort ( and vis versa).

big question here is : how can i know where am i ?

To do it, i need to know where i'm : the Context. Precisly, i would like have the "PortRef" instance as Context's return in the function getScope(context, Ereference), but it's not the case.

I tried this function scope_PortRef_referencedPort(Ctx,ref) in scope, but the Context passed in my function is an instance of CallService and not of PortRef like it supposed to be.

And that despite of the fact that i put {PortRef} intructions to force that the object creation.

Am i missing something ?

i hope i was clear.

Best regards.
F.

[Updated on: Sat, 02 February 2013 17:28]

Report message to a moderator

Re: Ambiguities in xText scoping "Context" [message #1006859 is a reply to message #1006852] Sat, 02 February 2013 19:42 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevitt
Messages: 65
Registered: December 2012
Location: Belfast
Member
In the scoping function, could you get the PortRef you need from the passed in CallService context using context.getSourcePort() or context.getTargetPort()?
Re: Ambiguities in xText scoping "Context" [message #1006962 is a reply to message #1006859] Sun, 03 February 2013 04:17 Go to previous messageGo to next message
Frank Tagne is currently offline Frank Tagne
Messages: 7
Registered: August 2012
Junior Member
Yes Ian, i can do context.getSourcePort() or context.getTargetPort.

my question is exactly for which of both EReference ( sourcePort or targetPort) i'am scoping ?

Because i can not just do (context.getSourcePort() != null ) or (context.getTargetPort !=null) to know which one of both EReference user hint Crtl+Space. That will not cover users udaptes.

Re: Ambiguities in xText scoping "Context" [message #1006967 is a reply to message #1006962] Sun, 03 February 2013 05:38 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevitt
Messages: 65
Registered: December 2012
Location: Belfast
Member
Maybe try two separate scope_CallService_sourcePort and scope_CallService_targetPort instead. The context may still be a CallService but you'd know which referenced item you were in.
Re: Ambiguities in xText scoping "Context" [message #1006998 is a reply to message #1006967] Sun, 03 February 2013 13:14 Go to previous messageGo to next message
Frank Tagne is currently offline Frank Tagne
Messages: 7
Registered: August 2012
Junior Member
I tried your proposition but it doesn't work.
Those two functions are never run. It seems to be logic because i'm scoping the reference "referencePort" at the end. But the context return are not the good one Crying or Very Sad

Re: Ambiguities in xText scoping "Context" [message #1007013 is a reply to message #1006998] Sun, 03 February 2013 18:12 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevitt
Messages: 65
Registered: December 2012
Location: Belfast
Member
Just so I understand - you're saying that in your function scope_PortRef_referencedPort(Ctx,ref) the Ctx is a CallService and not a PortRef?

I'm hoping the ref parameter is a ReferencedPort so perhaps its getName() will be either "sourcePort" or "targetPort".

if (ref instanceof ReferencedPort)
{
  ReferencedPort refPort = (ReferencedPort)ref;
  String portName = refPort.getName();
  if (portName.equals("sourcePort")) { }
}


It doesn't look elegant I'll admit so possibly someone else will have a better way.
Re: Ambiguities in xText scoping "Context" [message #1007069 is a reply to message #1007013] Mon, 04 February 2013 05:41 Go to previous messageGo to next message
Frank Tagne is currently offline Frank Tagne
Messages: 7
Registered: August 2012
Junior Member
Re,

Quote:
I'm hoping the ref parameter is a ReferencedPort so perhaps its getName() will be either "sourcePort" or "targetPort".

ref parameter is an EReference. Its getName() is "referencedPort" and its eContainer() return an EClass ( not an EObject).

F.
Re: Ambiguities in xText scoping "Context" [message #1067567 is a reply to message #1007069] Tue, 09 July 2013 07:30 Go to previous message
Ian McDevitt is currently offline Ian McDevitt
Messages: 65
Registered: December 2012
Location: Belfast
Member
Revisting this after seeing it in another post, as I've been moving my work to xtext 2.4 and had to rework the scoping.

It looks like the extra layer of PortRef doesn't help. If you simplify to this:
CallService:
        {CallService}
	'CallService' ('::' name=EString)?
	'{'
	     ('sourcePort' sourcePort=[PortEvent])?	
             ('targetPort' targetPort=[PortEvent])?
		
        '}';

PortEvent: {PortEvent} 'PortEvent' ('::' name=EString)?;


Then in your scope provider (or delegate) scoping method check if reference == YourDSLPackage$Literals::CALL_SERVICE__SOURCE_PORT or CALL_SERVICE__TARGET_PORT to see which one you are in. You won't care what the context is.
(if you're pre-2.4 with a Java scoping class then its '.' instead of $ or ::)
Previous Topic:Questions about scoping
Next Topic:Possible characters in STRING terminal rule
Goto Forum:
  


Current Time: Tue Jul 22 19:52:48 EDT 2014

Powered by FUDForum. Page generated in 0.02273 seconds