ANTLR4: TokenStreamRewriter output doesn't have proper format (removes whitespaces)

后端 未结 1 1913
甜味超标
甜味超标 2021-01-11 23:50

I am using Antlr4 and java7 grammar (source) for modifying an input Java Source file. More specifically, I am using the TokenStreamRewriter class to modify some tokens. The

1条回答
  •  清酒与你
    2021-01-12 00:46

    The issue is that the lexer is not sending white space to the parser, which means that the rewrite stream doesn't have access to the tokens either. It is because of the skip lexer command:

    WS : [ \t\r\n\u000C]+ -> skip ;

    You have to change all those to -> channel(HIDDEN) which will send them to the parser on a different channel, making them available in the token stream, but invisible to the parser.

    0 讨论(0)
提交回复
热议问题