Comments (3)
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.
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.
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)
- Change name HOT 1
- Ref HOT 1
- ANTLR Golang visitor pattern implementation/example HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tsdb-ql.