I need tob uild a nested array using antlr4 visitor (target language JavaScript).
parser.g4:
function
: FUNCTION_NAME OPEN_ROUND_BRACKET (expression (COMMA expression)*)? CLOSE_ROUND_BRACKET
;
visitor.js:
visitFunction(ctx) {
console.log("visitFunction", ctx.getText());
return this.visitChildren(ctx);
}
I need to get each part of function grammar rule as string (for example FUNCTION_NAME), but using ctx.getText() I get every child node also. How I can get only FUNCTION_NAME lexer part string from ctx?
Parser rules and lexer rules are methods of the context instance. So, in your case, the
functionparser rule:can be used like this: