What I want to realize: Treating comment by ANTLR4 in JavaScript
Now I'm coding interpret C script by antlr4js, and I want to take comment content. example:
/* this is my function */
int add(int a, int b);
then, I want get string "this is my function"
, and attach to add()
.
I googled and found that I can use hidden channel
.
Here is the page that I refer to :
This is Stuff: Tackling Comments in ANTLR Compiler
I can code collecting comment after lexing (describing at Collecting Hidden Tokens in above page), but I can't follow next section Merging Tokens With AST because I can't find out CommonTree class what base class.
problem point
The image to code.(in above page)
public class HiddenTokenAwareTree extends CommonTree {
private List<Token> preceding = new LinkedList<Token>();
private List<Token> orphans = new LinkedList<Token>();
private List<Token> following = new LinkedList<Token>();
// ... constructors, getters and setters follow
}
This is Java code, so when implement in javascript, code will be like this:
var CommonTree = require("antlr4/PATH/TO/COMMONTREE").CommonTree;
class HiddenTokenAwareTree{
}
I can't find out this PATH/TO/COMMONTREE
.
my project setting
node: 6.14.6 $ npm list --depth=0 ├── antlr4@4.8.0 ├── webpack@4.44.1 └── webpack-cli@3.3.12 I installed antlr4 by $ npm i antlr4.
Thanks for any advices !