How to make child references with Xtext? [message #556141] |
Mon, 30 August 2010 23:29  |
Eclipse User |
|
|
|
I want to enable textual entry for an existing EMF model. Basically, this is the model:
* Model contains Device contains Port.
* Model contains Connection with 2 references to Port.
* Device has a unique key within the model but Port is only unique within the context of a Device.
Based on the options I've set for EMF (namely some eKeys), I get XMI serialization like so:
<connection
port1="#//@devices[name='host01']/@ports[name='0']
port2="#//@devices[name='switch01']/@ports[name='1']/>
Note the type of each reference is still a Port but it needs both Device and Port to identify the referenced element.
In Xtext, I would like a simple grammar something like:
Connection returns Connection :
'connection'
device1=[Device|NAME] ':' port1=[Port|NUM]
device2=[Device|NAME] ':' port2=[Port|NUM];
I have experimented with this and even have implemented scoping to help choose the port from the device. However, there's no such attribute in my model as device1 and it would be hard for me to change the model.
How do I specify to Xtext that the reference for port1 should be constructed with a value for a Device NAME and a Port NUM?
|
|
|
|
|
|
Re: How to make child references with Xtext? [message #556534 is a reply to message #556141] |
Wed, 01 September 2010 12:43  |
Eclipse User |
|
|
|
The easiest way is to refer to the port only by using its qualified name:
Connection:
port=[Port|PortFQN]...
PortFQN:
ID ':' NUM;
That defines the syntax of the cross reference to be an ID followed by a
colon and a number. Now you have to make sure to calculate the qualified
name for existing ports correctly by implementing your own
IQualifiedNameProvider, like
public class MyFQNProvider extends DefaultDeclarativeQualifiedNameProvider {
String qualifiedname(Port p) {
return p.getDevice().getName() + ":" + p.getName();
}
}
and bind it in your Guice module.
Hope that helps
Jan.
Regards
Jan
Am 31.08.10 05:29, schrieb Ian Buchanan:
> I want to enable textual entry for an existing EMF model. Basically,
> this is the model:
> * Model contains Device contains Port.
> * Model contains Connection with 2 references to Port.
> * Device has a unique key within the model but Port is only unique
> within the context of a Device.
>
> Based on the options I've set for EMF (namely some eKeys), I get XMI
> serialization like so:
>
> <connection port1="#//@devices[name='host01']/@ports[name='0']
> port2="#//@devices[name='switch01']/@ports[name='1']/>
>
> Note the type of each reference is still a Port but it needs both Device
> and Port to identify the referenced element.
>
> In Xtext, I would like a simple grammar something like:
>
> Connection returns Connection :
> 'connection'
> device1=[Device|NAME] ':' port1=[Port|NUM]
> device2=[Device|NAME] ':' port2=[Port|NUM];
>
> I have experimented with this and even have implemented scoping to help
> choose the port from the device. However, there's no such attribute in
> my model as device1 and it would be hard for me to change the model.
>
> How do I specify to Xtext that the reference for port1 should be
> constructed with a value for a Device NAME and a Port NUM?
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
Powered by
FUDForum. Page generated in 0.03971 seconds