antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

[Go] Add Super property for Base*Visitor struct

Open terwey opened this issue 4 years ago • 2 comments

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())

terwey avatar Feb 17 '21 16:02 terwey

This is pretty interesting approach.

mitar avatar May 04 '21 04:05 mitar

@terwey is this superseded by https://github.com/antlr/antlr4/pull/3299 ?

parrt avatar Dec 28 '21 22:12 parrt