Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom terminal rule for /**-style documentation
Custom terminal rule for /**-style documentation [message #878889] Wed, 30 May 2012 06:19 Go to next message
Ralph Mayr is currently offline Ralph MayrFriend
Messages: 13
Registered: August 2011
Junior Member
Hello,

I'm trying to implement a grammar with a special terminal rule for documentation, which should be highlighted in a different color than normal comments, but otherwise behave analogously. (Basically like in Java where JavaDoc-Comments starting with /** are highlighted differently to ordinary comments starting with /* ).

My first attempt was to create an additional terminal rule, and add it to the "hidden" rules of my grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals hidden(WS, ML_DOCUMENTATION, ML_COMMENT, SL_COMMENT)

...

Model:
	greetings+=Greeting*;

Greeting:
	'Hello' name=ID '!';
	
terminal ML_DOCUMENTATION : '/**' -> '*/';


Unfortunately, this leads to unexpected parsing errors at runtime. E.g. in the following test:
/**
 * Documentation.
 */
Hello world!

I get a parser error in the very first line (- no viable alternative at character '<EOF>', - missing EOF at '*'), as soon as I enter the code in the fourth line. Without the code in the fourth line, the comment parses fine.

I also tried a few different versions (copying all terminals defined in org.eclipse.xtext.common.Terminals to my grammar, changing the order of the terminals in the grammar, ...) but could not find a valid solution.

I would be grateful for any hints!

Thanks,
Ralph.
Re: Custom terminal rule for /**-style documentation [message #879064 is a reply to message #878889] Wed, 30 May 2012 13:04 Go to previous message
Ralph Mayr is currently offline Ralph MayrFriend
Messages: 13
Registered: August 2011
Junior Member
Hello,

just found the solution in an old forum post - using the following terminals, it works as expected:

terminal ML_DOCUMENTATION: '/**' -> '*/' ;
terminal ML_COMMENT : '/*' (!'*') -> '*/' ;
terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')? ;
Previous Topic:mixed uri and namespace imports
Next Topic:[mwe2] Conditions and global variables
Goto Forum:
  


Current Time: Thu Apr 25 02:09:36 GMT 2024

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

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

Back to the top