Catching (and keeping) all comments with ANTLR

前端 未结 6 1173
抹茶落季
抹茶落季 2020-12-10 19:49

I\'m writing a grammar in ANTLR that parses Java source files into ASTs for later analysis. Unlike other parsers (like JavaDoc) I\'m trying to keep all of the comments. This

6条回答
  •  Happy的楠姐
    2020-12-10 20:19

    For ANTLR v3:

    The whitespace tokens are usually not processed by parser, but they are still captured on the HIDDEN channel.

    If you use BufferedTokenStream, you can get to list of all tokens through it and do a postprocessing, adding them as needed.

提交回复
热议问题