Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xText] reference scope
[xText] reference scope [message #675333] Tue, 31 May 2011 07:44 Go to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
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 08:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14668
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [xText] reference scope [message #675346 is a reply to message #675333] Tue, 31 May 2011 08:43 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
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


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: [xText] reference scope [message #675400 is a reply to message #675343] Tue, 31 May 2011 11:57 Go to previous message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
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: Fri Apr 26 18:29:54 GMT 2024

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

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

Back to the top