Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Getting comments from the node model
Getting comments from the node model [message #1567778] Fri, 16 January 2015 15:19 Go to next message
Andy Ed is currently offline Andy EdFriend
Messages: 64
Registered: December 2009
Member
Hi,
I've been trying to get comments from a node model, so that I can inject them into an EMF model for separate persistence. But, it is not working as I expected. I assumed that the node associated with an EObject (representing a keyword in the text, for instance) would contain a tree (or some graph) of sub elements, related to the DSL spec.

To illustrate, I have a problem with comments on an axiom,

Axiom returns context::Axiom:
'@'name=EString
predicate=EString?
(theorem?='theorem')?
('//' comment=EString)?
;

When trying to obtain comments from the node model, if you can see the graphic attached, the comment associated with axm2 (note 1) using node.getText() is incorrect. In the xtext it is associated with axm1 (note 2). In some cases the comments are lost, so I am obviously doing something wrong.

In my code I use NodeModelUtils.getNode(eobj) to get a composite node, and ICompositeNode.getChildren() method to get an iterator. Is my assumption correct, that the comment should be navigable through an iterator obtained from the Axiom EObject?

Any hints would be appreciated.

Many thanks,
Andy
Re: Getting comments from the node model [message #1567851 is a reply to message #1567778] Fri, 16 January 2015 16:12 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Andy,

in the node model, comments almost always precede the following semantic
text. The semantic association of comments to EObject can be done by
means of the org.eclipse.xtext.parsetree.reconstr.ICommentAssociater.

Hope that helps,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Getting comments from the node model [message #1567879 is a reply to message #1567851] Fri, 16 January 2015 16:33 Go to previous messageGo to next message
Andy Ed is currently offline Andy EdFriend
Messages: 64
Registered: December 2009
Member
Ok thanks,

how do you make the framework aware that it should use an implementation of ICommentAssociater?

Andy
Re: Getting comments from the node model [message #1567901 is a reply to message #1567879] Fri, 16 January 2015 16:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
do you mean how to register your custom implementation? that should work std. way

public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
	
	public Class<? extends ICommentAssociater> bindICommentAssociater() {
		return YourDefaultCommentAssociater.class;
	}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting comments from the node model [message #1567910 is a reply to message #1567901] Fri, 16 January 2015 16:55 Go to previous messageGo to next message
Andy Ed is currently offline Andy EdFriend
Messages: 64
Registered: December 2009
Member
Great, I'll give it a go. Thanks
Re: Getting comments from the node model [message #1567935 is a reply to message #1567910] Fri, 16 January 2015 17:09 Go to previous messageGo to next message
Andy Ed is currently offline Andy EdFriend
Messages: 64
Registered: December 2009
Member
I've registered my ICommentAssociater implementation (of AbstractCommentAssociater ) but the associateCommentsWithSemanticEObjects method doesn't get called. Does this not called somewhere in the XText framework?
Re: Getting comments from the node model [message #1568063 is a reply to message #1567935] Fri, 16 January 2015 18:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi it depends on the usecase.
if you know how to find the comment why do you want to customize ICommentAssociater in the first place? i thought it is about serializing?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 16 January 2015 18:49]

Report message to a moderator

Re: Getting comments from the node model [message #1572526 is a reply to message #1568063] Mon, 19 January 2015 07:21 Go to previous messageGo to next message
Andy Ed is currently offline Andy EdFriend
Messages: 64
Registered: December 2009
Member
Hi, my query is about serialising an EMF model for use by another tool. Sebastian's comment, above, suggests that I use ICommentAssociater to link semantic text with comments. Presumably I can then retrieve a comment, given a node object, so that I can insert it in the correct place in my EMF model. In my DSL, comments follow the semantic text. I am just looking for the 'best way' to insert the comments, after text rather than before.
Re: Getting comments from the node model [message #1572552 is a reply to message #1572526] Mon, 19 January 2015 07:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
which serializer(fragment) do you use?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting comments from the node model [message #1572574 is a reply to message #1572552] Mon, 19 January 2015 08:00 Go to previous messageGo to next message
Andy Ed is currently offline Andy EdFriend
Messages: 64
Registered: December 2009
Member
This is specified in the MWE2 file:

// serializer 2.0
fragment = serializer.SerializerFragment auto-inject {
//generateStub = false
}
Re: Getting comments from the node model [message #1572621 is a reply to message #1572574] Mon, 19 January 2015 08:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the hook is only for the old parseTreeConstructor.ParseTreeConstructorFragment



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting comments from the node model [message #1572633 is a reply to message #1572621] Mon, 19 January 2015 08:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.S:

if you want to serialize it as non xtext? so you simply want to find the nodes on the existing nodemodel?
then your first approach in looking at the node model should be fine


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting comments from the node model [message #1572641 is a reply to message #1572633] Mon, 19 January 2015 08:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.P.S:

if your comments arent hidden at all mabye you should exclude them from the hidden clase

(hard to say with ony a partial grammar)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting comments from the node model [message #1572673 is a reply to message #1572641] Mon, 19 January 2015 09:09 Go to previous message
Andy Ed is currently offline Andy EdFriend
Messages: 64
Registered: December 2009
Member

>> if you want to serialize it as non xtext? so you simply want to find the nodes on the existing nodemodel?
>> then your first approach in looking at the node model should be fine

Ok, this works, but seems a bit messy since some of the comments (those on the first line of the my file) appear lower in the node model's tree than the semantic text they are associated with; most other comments appear higher in the tree than the associated text. I also seem to have spurious newline characters and text, when I get comment text from the node using INode.getText(), which is rather strange.

>> if your comments arent hidden at all mabye you should exclude them from the hidden clase

They are hidden wrt to parsing.

>> which serializer(fragment) do you use?

Which should I be using, if any needs to be specified?

Previous Topic:Issues importing into Eclipse via Git, MWE2 version problem?
Next Topic:Embedded languages
Goto Forum:
  


Current Time: Fri Apr 26 10:07:40 GMT 2024

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

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

Back to the top