Skip to main content


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 22:26 Go to next message
Frank Tagne is currently offline Frank TagneFriend
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 22:28]

Report message to a moderator

Re: Ambiguities in xText scoping "Context" [message #1006859 is a reply to message #1006852] Sun, 03 February 2013 00:42 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
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 09:17 Go to previous messageGo to next message
Frank Tagne is currently offline Frank TagneFriend
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 10:38 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
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 18:14 Go to previous messageGo to next message
Frank Tagne is currently offline Frank TagneFriend
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 23:12 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
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 10:41 Go to previous messageGo to next message
Frank Tagne is currently offline Frank TagneFriend
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 11:30 Go to previous message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 70
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 Apr 23 12:46:47 GMT 2024

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

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

Back to the top