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] Thu, 03 January 2013 22:21 Go to next message
Barrie Treloar is currently offline Barrie Treloar
Messages: 52
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 03:44 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
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 05:20 Go to previous message
Barrie Treloar is currently offline Barrie Treloar
Messages: 52
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: Mon Sep 01 03:35:54 EDT 2014

Powered by FUDForum. Page generated in 0.02386 seconds