Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Weird behaviour with multiple multi line comments
Weird behaviour with multiple multi line comments [message #645382] Thu, 16 December 2010 22:03 Go to next message
No real name is currently offline No real nameFriend
Messages: 25
Registered: April 2010
Junior Member
Hi,

I am trying to implement something similar to java doc in xtext (because the language supports it). Currently I have multiple problems with Xtext.

1) There seems to be a weird bug. Consider the following example grammar:

grammar org.xtext.example.mydsl.MyDsl hidden(WS, DOC_COMMENT, ML_COMMENT, SL_COMMENT)

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Model:
	a='a';
	 
terminal DOC_COMMENT: '/**' -> '*/';
terminal ML_COMMENT	: '/*' -> '*/';
terminal SL_COMMENT 	: '//' !('\n'|'\r')* ('\r'? '\n')?;

terminal WS			: (' '|'\t'|'\r'|'\n')+;

terminal ANY_OTHER: .;


This seems to show a very weird behaviour when using the compiled Editor. The following code:

a
/**
*
*/<EOF>


works as expected. It seems to show weird behaviour when the end of File is on the next line or after a space, where the /** */ doesnt get lexed properly. If I remove one of the multiline comments (e.g. If I only have DOC_COMMENT and not ML_COMMENT) everything works as expected. If I change the characters for DOC_COMMENT everything works fine. Is this a bug or am i doing something horribly wrong? If this is the wrong approach, how would I go about doing this correctly?

I would love the DOC_COMMENT to be a production rule, but then I cannot color the whole text, and have other problems (e.g. cannot make the rule hidden)

Finally, I would also like to be able to nest a DOC_COMMENT inside a ML_COMMENT, is that possible at all?
Re: Weird behaviour with multiple multi line comments [message #645443 is a reply to message #645382] Fri, 17 December 2010 09:33 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I don't know what you are trying to do, but if you want to make the rule hidden anyway and not store (only doc) comments in the model, why not simply use only ML_COMMENT. If you want to process a doc comment, it does not really matter whether you check the name of the terminal rule or check whether the ML_COMMENT terminal actually starts with "/**".

Alex
Re: Weird behaviour with multiple multi line comments [message #645483 is a reply to message #645443] Fri, 17 December 2010 12:35 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 25
Registered: April 2010
Junior Member
Hi,

Thanks for the answer. It turned out that it can be done by using such terminal rules:

terminal DOC_COMMENT: '/**' -> '*/';
terminal ML_COMMENT	: '/*'!'*' .* (DOC_COMMENT .*)* '*/';


The point was, to be able to have a different color for /** */ comments than for regular ML_comments, and DOC comments were allowed to be nested in regular comments:

e.g.

/*
/**
*
*/
*/

would translate to a single ML_Comment. With the default terminals, it would also give you a single ML_comment but also a trailing */ which would case a syntax error.
Re: Weird behaviour with multiple multi line comments [message #645500 is a reply to message #645483] Fri, 17 December 2010 14:03 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

with your definition, do you get different highlighting for nested doc comments? I assume not. Also the comment "/**/" should cause a syntax error with your definition.

Regarding the syntax error for nested case with the default implementation, you are of course right.

Alex
Re: Weird behaviour with multiple multi line comments [message #645515 is a reply to message #645500] Fri, 17 December 2010 15:16 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 25
Registered: April 2010
Junior Member
yes, you are right, but the parser is required to be able to parse document comments inside multiline comments (because it is so in preexisting code, which is out of my control). It seems that there are no /**/ comment instances.

I have have yet to figure out if there is an alternative to that which allows for nested comments and the case /**/

Also, I was wondering, is it possible to write lexer fragments which can be used in terminals? Or do I have to use a custom lexer to do that?
Re: Weird behaviour with multiple multi line comments [message #645724 is a reply to message #645382] Mon, 20 December 2010 09:03 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
We have a similar documentation feature in the context of hovers in
Xtext 2.0.
You could have a look at the source code for inspiration, especially
/org.eclipse.xtext/src/org/eclipse/xtext/documentation/impl/ MultiLineCommentDocumentationProvider.java

Am 16.12.10 23:03, schrieb Wattos@gmail.com:
> Hi,
>
> I am trying to implement something similar to java doc in xtext (because
> the language supports it). Currently I have multiple problems with Xtext.
>
> 1) There seems to be a weird bug. Consider the following example grammar:
>
>
> grammar org.xtext.example.mydsl.MyDsl hidden(WS, DOC_COMMENT,
> ML_COMMENT, SL_COMMENT)
>
> generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
>
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
>
> Model:
> a='a';
> terminal DOC_COMMENT: '/**' -> '*/';
> terminal ML_COMMENT : '/*' -> '*/';
> terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?;
>
> terminal WS : (' '|'\t'|'\r'|'\n')+;
>
> terminal ANY_OTHER: .;
>
>
> This seems to show a very weird behaviour when using the compiled
> Editor. The following code:
>
>
> a
> /**
> *
> */<EOF>
>
>
> works as expected. It seems to show weird behaviour when the end of File
> is on the next line or after a space, where the /** */ doesnt get lexed
> properly. If I remove one of the multiline comments (e.g. If I only have
> DOC_COMMENT and not ML_COMMENT) everything works as expected. If I
> change the characters for DOC_COMMENT everything works fine. Is this a
> bug or am i doing something horribly wrong? If this is the wrong
> approach, how would I go about doing this correctly?
>
> I would love the DOC_COMMENT to be a production rule, but then I cannot
> color the whole text, and have other problems (e.g. cannot make the rule
> hidden)
> Finally, I would also like to be able to nest a DOC_COMMENT inside a
> ML_COMMENT, is that possible at all?


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Hidden production rules?
Next Topic:combining JavaVMTypes and own types
Goto Forum:
  


Current Time: Sat Sep 21 02:50:45 GMT 2024

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

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

Back to the top