| How do I customize grammar for my topology feature? [message #1760287] |
Tue, 25 April 2017 10:19  |
Eclipse User |
|
|
|
Hi,
I would like to do a grammar feature that deviates a bit from the metamodel - but I am in doubt as to how to proceed and if the feature below can be implemented solely as addition to grammar?...
The problem:
In the metamodel instances of the Joint class references a parent (instance of Link class), and a child (also instance of Link class). See grammar below for details. This forms a tree topology. I would like the user to be able to define this tree using a graphviz inspired concrete syntax like seen in the TOPOLOGY rule below. The arrows represent edges=Joint instance in the topology.
TOPOLOGY:
('Link' name=ID ' -> ')+ 'Link' name=ID
;
I am thinking it would be very cool if the topology definition could generate stubs for the Link and Joint definitions in the editor. I am pretty sure I'll need a ValueConverter no matter what- but for starters I have to figure out if this topology topology can be done with grammar only or I need to update my metamodel with some kind of class or other kind of hook for this?
//-----This is my current grammar
grammar org.xtext.urdf.Dsl with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "http://www.example.org/uRDF" as uRDF
Robot returns uRDF::Robot:
'Robot' name=ID
link+=Link+
joint+=Joint*
;
Link returns uRDF::Link:
'Link' name=ID
[...]
;
Joint returns uRDF::Joint:
'Joint' name=ID
'ChildOf' ChildOf=[uRDF::Link|STRING]
'ParentOf' ParentOf=[uRDF::Link|STRING]
[...]
;
|
|
|
|
| Re: How do I customize grammar for my topology feature? [message #1760296 is a reply to message #1760288] |
Tue, 25 April 2017 11:17   |
Eclipse User |
|
|
|
Hi Christian, thank you for a very reply!
Here are some more details:
The metamodel I am trying to do a grammar for sort of has two different levels of description.
- the lower level of description tell us about the individual parts of the robot and their attributes (links are physical shapes, that have attributes like geometry, mass, etc - and joints connect the links, joints have a joint type, certain limits for bending, etc etc)
- the higher level of description tells us about the topology of the robot - how the individual joints and links are connected in child/parent relations.
The description would be a lot more easy to read, if this higher level of description was made more explicit by adding a special topology syntax for it - and removing it from the part, that defines individual Links and Joints and their attributes...
The concrete syntax for the topology should look something like this - arrows represent Joints connecting Links:
Link name=RobotsUpperArm -> Link name=RobotsLowerArm etc...
I hope this were the details you were looking for. If not let me know and I'll explain further
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: How do I customize grammar for my topology feature? [message #1760968 is a reply to message #1760287] |
Thu, 04 May 2017 12:46   |
Eclipse User |
|
|
|
Sven, Christian,
I'm working with Susie on this, and I follow this discussion as well. The solution suggested seems to be adaptable to what we need, but I would like to ask the same question in a different way, just to rule out that we are missing something obvious.
The case we are looking at, is not very exotic: we have a DSL where objects can be used without declaration, but some objects can be declared (in here the objects are "links"). So basically, we want a reference to be resolved to an existing object (link) if it was already declared, and otherwise, if the object is not declared, it should be declared and instantiated automatically.
Since automatic variable definition is seen in some programming languages, I was wondering if Xtext had some direct support for this. Are we on the right track using IDerivedState? Or is there a more direct way in the Xtext DSL?
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: How do I customize grammar for my topology feature? [message #1763558 is a reply to message #1763554] |
Wed, 17 May 2017 07:57  |
Eclipse User |
|
|
|
sorry i still cannot follow you. thus i cannot help you.
you have model x that is parsed.
then you have the derived state computer that produces model y.
that ever you do there lies in your hand.
but i dont see anything that i can reproduce .....
i have never seens an example model i can use. nor how the ast should look like you want to produce.
a robot has topologies.
a topology has references to (other ?!? robots???)
|
|
|
Powered by
FUDForum. Page generated in 0.29272 seconds