ANTLR4: Obtaining list of tokens for a specific rule in Listener -
i extending listener in antlr4 , want of tokens associated particular rule in parser, there method in doing that?
i.e.
myconfiguration: config equals parameters ; parameters: alphanumeric+ config: 'config' ; alphanumeric: [a-za-z0-9] ; how can tell listener lookup value of config , equals when entering myconfiguration parsing rule?
is there loop of sort use?
for( tokens in rule) { system.out.println(token.gettext()); } i can see there list of tokens through parser class cant find list of tokens associated current rule.
the reason why asking can avoid re-typing token names require in listener , in grammar. doing can check whether or not each token type in particular rule has been found without having type in name manually.
this might you're looking for.
list<terminalnode> terminalnodes = new arraylist<terminalnode>(); (int = 0; < context.getchildcount(); i++) { if (context.getchild(i) instanceof terminalnode) { terminalnodes.add((terminalnode)context.getchild(i)); } } antlr4
No comments:
Post a Comment