antlr4
antlr4 copied to clipboard
[Go] Add Super property for Base*Visitor struct
Add a super property to the Base*Visitor generated code allowing to only override the required Visitors vs implementing each one in its entirety.
Example code:
type fooVisitor struct {
*parser.BaseFooVisitor
}
is := antlr.NewInputStream("4+6")
lexer := parser.NewAnalyzerLexer(is)
stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)
p := parser.NewAnalyzerParser(stream)
fv := &fooVisitor{}
fv.BaseFooVisitor = &parser.BaseFooVisitor{}
// this is new
fv.BaseAnalyzerVisitor.SetSuper(fooVisitor)
fv.Visit(p.Prog())
This is pretty interesting approach.
@terwey is this superseded by https://github.com/antlr/antlr4/pull/3299 ?