Git Product home page Git Product logo

Comments (3)

at15 avatar at15 commented on September 24, 2024

After overriding the Visit method in AstBuilder I no longer have the nil error

func (b *AstBuilder) Visit(tree antlr.ParseTree) interface{} {
	return nil
}

so I guess BasewhileVisitor does not have Visit method? but why no compile error?

May need to list all the methods of a struct http://stackoverflow.com/questions/21397653/how-to-dump-methods-of-structs-in-golang

from tsdb-ql.

at15 avatar at15 commented on September 24, 2024

And using BasewhileVisitor also works, I think the problem is from embedding by pointer http://www.hydrogen18.com/blog/golang-embedding.html

Yes, it is https://groups.google.com/forum/#!topic/golang-nuts/ctRUq62cgME

One thing to keep in mind when you embed a pointer is that, well,
you're embedding a pointer. If you get a new(CardboardBox), then
RectPrism fields are not allocated yet - the pointer to the RectPrism
fields is zeroed.

And I don't think it's the case for visitor?

As to why one should use a pointer, one example is when one wants to
embed a struct containing unexported fields from another package.
Since the struct has unexported fields and is from a different
package, the -only- way to embed it is as a pointer. I proposed this
in another thread as a solution to provide a logger that closes its
output stream. Here's the reply:

from tsdb-ql.

at15 avatar at15 commented on September 24, 2024

So the problem is in the example, which use embedding by pointer

  • it works for listener because base listener does not embed other things
  • basevisitor embed BaseParseTreeVisitor, thus cause the nil problem when use it directly without explicit initialize the BaseTreeVisitor inside it
type PrinterwhileListener struct {
	*BasewhileListener
}
type BasewhileListener struct{}
type AstBuilder struct {
	*BasewhileVisitor
}

// tree.go
type BasewhileVisitor struct {
	*antlr.BaseParseTreeVisitor
}

// FIXME: this will cause SIGSEGV when using visit
func NewAstBuilder() *AstBuilder {
	return new(AstBuilder)
}

from tsdb-ql.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.