Search code examples
typescriptantlr4

Visitor/Listener pattern confusion in -Dlanguage=TypeScript


I am investigating moving from antlr4ts to the main Typescript target. The documentation for the Typescript target says Visitors and Listeners are defined differently ...

class CustomVisitor extends MyGrammarVisitor {
  visitRuleName(ctx: ParserRuleContext) {
    // code here ...
  }
}
class CustomListener extends MyGrammarListener {
    exitRuleName = (ctx: ParserRuleContext) => {
        // code here...
    }
}

However it appears that both listeners and visitors as defined in the typescript target are expected to be properties and not member functions.

This is the forum requested by the ANTLR maintainers for asking questions, so is the documentation correct, or is the code correct? Should I code to the actual generated parser (and submit a PR to fix the documentation) or does the documentation describe the intended behavior and I should file a bug against the implementation?

---- ADDED AFTER SOME HOURS ----

It appears to me that the documentaion is wrong in both cases, the correct code should be very similar to the way this was written in antlr4ts:

class CustomVisitor
  extends ParseTreeVisitor<T>
  implements MyGrammarVisitor<T> {

And similarly for the listeners. Question still remains, am I correct and should I try and fix the documentation?


Solution

  • This is definitely a documentation bug. Please submit a PR and I'll look into it.