Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatter ignoring "comment" rules - remember to provide own IHiddenTokenHelper implementa
Formatter ignoring "comment" rules - remember to provide own IHiddenTokenHelper implementa [message #997155] Fri, 04 January 2013 03:21 Go to next message
Barrie Treloar is currently offline Barrie TreloarFriend
Messages: 55
Registered: July 2009
Member
To help google...

My grammar doesn't have SL_COMMENT or ML_COMMENT.
Its got "REM"s.

So in the grammar I include REM as a hidden rule
grammar com.exmaple.MyDsl hidden(WS, REM)


Everything works fine until you get to formatting and you notice that the configureFormatting rules are not being used for your comment.

This is because IHiddenTokenHelper's default implementation is DefaultHiddenTokenHelper.

DefaultHiddenTokenHelper hard codes isComment() to be ML_COMMENT AND SL_COMMENT.

So if your grammar doesn't have theses rules, or uses different rule names for comments then you need to provide your own implementation and remember to bind this in you MyDslRuntimeModule:

{MyDslRuntimeModule}
    public Class<? extends IHiddenTokenHelper> bindIHiddenTokenHelper() {
        return MyDslHiddenTokenHelper.class;
    }


It's probably easiest to extend Default and just override isComment...
public class MyDslHiddenTokenHelper extends DefaultHiddenTokenHelper {

    @Override
    public boolean isComment(AbstractRule rule) {
        return rule != null && "REM".equals(rule.getName());
    }

}
Re: Formatter ignoring &quot;comment&quot; rules - remember to provide own IHiddenTokenHelpe [message #997163 is a reply to message #997155] Fri, 04 January 2013 08:44 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Barrie,

thanks for comming back to this topic and the nice writeup.

As an additional note: If you change the rule name for single line
comments, make sure to customize the
org.eclipse.xtext.ui.editor.toggleComments.ISingleLineCommentHelper, too
in order make toggle comment work in the editor.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 04.01.13 04:21, schrieb Barrie Treloar:
> To help google...
>
> My grammar doesn't have SL_COMMENT or ML_COMMENT.
> Its got "REM"s.
>
> So in the grammar I include REM as a hidden rule
>
> grammar com.exmaple.MyDsl hidden(WS, REM)
>
>
> Everything works fine until you get to formatting and you notice that
> the configureFormatting rules are not being used for your comment.
>
> This is because IHiddenTokenHelper's default implementation is
> DefaultHiddenTokenHelper.
>
> DefaultHiddenTokenHelper hard codes isComment() to be ML_COMMENT AND
> SL_COMMENT.
>
> So if your grammar doesn't have theses rules, or uses different rule
> names for comments then you need to provide your own implementation and
> remember to bind this in you MyDslRuntimeModule:
>
>
> {MyDslRuntimeModule}
> public Class<? extends IHiddenTokenHelper> bindIHiddenTokenHelper() {
> return MyDslHiddenTokenHelper.class;
> }
>
>
> It's probably easiest to extend Default and just override isComment...
>
> public class MyDslHiddenTokenHelper extends DefaultHiddenTokenHelper {
>
> @Override
> public boolean isComment(AbstractRule rule) {
> return rule != null && "REM".equals(rule.getName());
> }
>
> }
>
Re: Formatter ignoring &quot;comment&quot; rules - remember to provide own IHiddenTokenHelpe [message #997185 is a reply to message #997163] Fri, 04 January 2013 10:20 Go to previous message
Barrie Treloar is currently offline Barrie TreloarFriend
Messages: 55
Registered: July 2009
Member
Sebastian Zarnekow wrote on Fri, 04 January 2013 03:44
Hi Barrie,

thanks for comming back to this topic and the nice writeup.

As an additional note: If you change the rule name for single line
comments, make sure to customize the
org.eclipse.xtext.ui.editor.toggleComments.ISingleLineCommentHelper, too
in order make toggle comment work in the editor.


Thanks.
My grammar is so junky they aren't real single line comment either Smile

It's

REM ".*"


as the comment.
Previous Topic:[Xtend] error occurs by changing method-order in Java base class
Next Topic:import xtext resource file from other projects
Goto Forum:
  


Current Time: Thu Apr 25 05:41:01 GMT 2024

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

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

Back to the top