In my grammar, I have a whitespace token that is sent to the HIDDEN
channel:
SP : [ \u00A0\u000B\t\r\n] -> channel(HIDDEN);
I know that I can get the text of a parsed rule, including hidden tokens, with TokenStream#getText(Context)
. I'd like to have all whitespace collapsed when I call that.
I also know there's a TokenStreamRewriter
for rewriting specific tokens, but I don't see a way to rewrite all of a certain type.
Is there any way to collapse all SP
tokens to output as a single space?