Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Who to get the content of a Multiline-Comment?
Who to get the content of a Multiline-Comment? [message #883277] Fri, 08 June 2012 07:40 Go to next message
Christian Schwarz is currently offline Christian SchwarzFriend
Messages: 31
Registered: July 2009
Member
Hi,

i am writing a dsl to generate some java code and i want to use the content of multiline-comment (of the dsl) in the generated java code.

I figured out that i have to use my own set of terminal-symbols, because 'org.eclipse.xtext.common.Terminals' hides the ML_COMMENT.

My current gramma looks like this:

Attribute :
	(comment=(ML_COMMENT))?
	type=PrimitiveType name=ID optional='?'?;

PrimitiveType:
	'string' | 'int';

terminal ID:
	'^'? ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*;

terminal ML_COMMENT :
	'/*' .* '*/';


As you can see i replaced the 'org.eclipse.xtext.common.Terminals' ML_COMMENT by my own terminal definition '/*' .* '*/'.
The disadvantage of this definition is that i get a String, including '/*' and '*/', but i only want the content not the surrounding comment start- and end-symbols.

e.g. for

/*blah blub*/
string myAttribute


i get "/*blah blub*/" but i want "blah blub".

I found many ways that doesn'twork, may be some have a idea to solve the puzzle?

Thanks Chris
Re: Who to get the content of a Multiline-Comment? [message #883280 is a reply to message #883277] Fri, 08 June 2012 07:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13640
Registered: July 2009
Senior Member
Hi,

this is usually done by a ValueConverter

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Who to get the content of a Multiline-Comment? [message #883297 is a reply to message #883280] Fri, 08 June 2012 08:28 Go to previous messageGo to next message
Christian Schwarz is currently offline Christian SchwarzFriend
Messages: 31
Registered: July 2009
Member
..deleted

[Updated on: Fri, 08 June 2012 08:37]

Report message to a moderator

Re: Who to get the content of a Multiline-Comment? [message #883300 is a reply to message #883280] Fri, 08 June 2012 08:36 Go to previous messageGo to next message
Christian Schwarz is currently offline Christian SchwarzFriend
Messages: 31
Registered: July 2009
Member
Hi Christian, thank you for your answer! I implemented a ValueConverter by extending DefaultTerminalConverters, it works Smile!

Out of interest, is it possible to do the same within the gramma definition?

It tried this, but without success:
Attribute :
   ('/*' comment=(ANY_OTHER)* '*/')?
   type=PrimitiveType name=ID optional='?'?;
Re: Who to get the content of a Multiline-Comment? [message #883321 is a reply to message #883300] Fri, 08 June 2012 09:37 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13640
Registered: July 2009
Senior Member
Hi,

first of all ANY_OTHER is not a context sensitive any other.
then: you would have to write
comment+=(ANY_OTHER)*
and would get a list of junks

=> no. a valuevonverter is in this case the cleanest solution.

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:MWE2 Running as Standalone
Next Topic:OCl and Xtext
Goto Forum:
  


Current Time: Mon Oct 26 19:56:47 GMT 2020

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

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

Back to the top