Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [xText] reference scope
[xText] reference scope [message #675333] Tue, 31 May 2011 03:44 Go to next message
Eclipse UserFriend
Hi,
I'd like to build a DSL for something similar to UML composite structure diagrams or SysML internal
block diagrams. In short, in these models you have components that can have ports and consist of
parts ("component instances"). The parts are typed by components. Furthermore, the parts can be
connected by connectors. In addition to connecting the parts, the ends of the connectors refer to a
certain port that shall be connected. The ports, however, are only defined in the components that
type the parts.

One example in the concrete syntax should look like this:
....
component TestComp {
port in implements FlowIn requires FlowOut;
port out implements FlowOut requires FlowIn;
}

component System {
part c1:TestComp;
part c2:TestComp;
connect c1.out to c2.in;
}
....
See that the connector refers to the parts "c1" and "c2" in the component "System" and it refers to
the ports "out" and "in" of the component "TestComp", which types the parts "c1" and "c2".

The grammar for this model looks like this so far:
....
Component:
'component' name=ID '{'
port+=Port*
part+=Part*
connector+=Connector*
'}';

Part:
'part' name=ID ':' type=[Component] ';';

Connector:
'connect' sourceEnd+=ConnectorEnd 'to' targetEnd+=ConnectorEnd ';';

ConnectorEnd:
partWithPort=[Part] '.' port=[Port];

Port:
'port' name=ID ...


The problem is, however, that the connector end does not "see" the ports defined in another
component. There is probably an issue with the scope in which the port definition is visible. I
would like to specify that the port that one may write after the dot must be a port defined for the
component that types the part written before the dot.

Any ideas how to do that?
I suppose that this is not such a rare case, so maybe you can point me to examples?
Thanks!

Joel
Re: [xText] reference scope [message #675343 is a reply to message #675333] Tue, 31 May 2011 04:36 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

what about something like

public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
	
	public IScope scope_ConnectorEnd_port(ConnectorEnd ce, EReference r) {
		return Scopes.scopeFor(ce.getPartWithPort().getType().getPort());
	}

}


~Christian
Re: [xText] reference scope [message #675346 is a reply to message #675333] Tue, 31 May 2011 04:43 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

the short answer is:
write a scopeing function for port with context ConnectorEnd, extract its partWithPort from there navigate to type, and return the scope for all the ports of that type. You will find the Scopes#scopeFor() method quite useful (once you extracted the ports).

Alex
Re: [xText] reference scope [message #675400 is a reply to message #675343] Tue, 31 May 2011 07:57 Go to previous message
Eclipse UserFriend
Perfect!

Thanks so much!

Joel

On 31.05.2011 10:36, Christian Dietrich wrote:
> Hi,
>
> what about something like
>
>
> public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
>
> public IScope scope_ConnectorEnd_port(ConnectorEnd ce, EReference r) {
> return Scopes.scopeFor(ce.getPartWithPort().getType().getPort());
> }
>
> }
>
>
> ~Christian
Previous Topic:Adding comments to the Node Model
Next Topic:[xtext 2.0] mwe2 new serializer fragment not found.
Goto Forum:
  


Current Time: Tue Jul 08 05:47:45 EDT 2025

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

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

Back to the top