By looking at channel(HIDDEN)
, it seems you're using ANTLR4, which does not have the rewrite functionality anymore: ANTLR 4 tree inject/rewrite operator. Besides, if you'd be using ANTLR3, I doubt you'd be able to rewrite the AST is such a way.
You should see this as two operations: 1) parse the input, and 2) walk/visit the parse tree and [by using plain programming] rewrite the parsed tree into something else. This last step is done by yourself in tree listener- or visitor of which ANTLR generates base classes for.