|
|
Re: How to make child references with Xtext? [message #556300 is a reply to message #556149] |
Tue, 31 August 2010 16:20 |
Ian Buchanan Messages: 2 Registered: July 2009 |
Junior Member |
|
|
I'm not sure I follow. As far as I understand, the following references (the ports in Connection) are equivalent:
Port:
'port' name=ID
Connection:
'connection'
port1=[Port|ID]
port2=[Port]
In other words, removing the stuff after '|' only makes an implicit call the the ID rule. I was unaware that the ID rule was special. Is it?
I have my own rules for assigning values to the "name" attribute:
Device:
'device' name=NAME
'{' ports+=(Port)* '}';
Port:
'port' name=NUM
Because I had set things in ecore, I thought those settings would be respected. In particular, in ecore the name attribute for Device is set to ID=true (which I thought meant something very different than the Xtext rule ID). Because Ports are not uniquely named for the whole document (only for a Device), I have the name attribute for Port set to ID=false. Given my model, it feels like I need something like this:
Connection:
'connection'
port1=([Device|NAME] ':' [Port|NUM])
port2=([Device|NAME] ':' [Port|NUM])
I need both a Device value and Port value to have a unique reference to a Port. I imagine this is a problem for Xtext because it's not a 1:1 mapping between a value and a reference. I was hoping it might be possible with some code. Is it?
[Updated on: Tue, 31 August 2010 16:20] Report message to a moderator
|
|
|
|
Re: How to make child references with Xtext? [message #556534 is a reply to message #556141] |
Wed, 01 September 2010 16:43 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
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
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Powered by
FUDForum. Page generated in 0.02811 seconds