parser
parser copied to clipboard
Node.OriginTextPosition() always return 0 and Text() return empty
I want to got foreach Node OriginTextPosition and Text, but ican't got it, why
type FingerprintVisitor struct{}
func (f *FingerprintVisitor) Enter(n ast.Node) (node ast.Node, skipChildren bool) { fmt.Printf("[%T] %d --> %s\n", n, n.OriginTextPosition(), n.Text()) return n, false }
func (f *FingerprintVisitor) Leave(n ast.Node) (node ast.Node, ok bool) { fmt.Printf("[%T] %d <-- %s\n", n, n.OriginTextPosition(), n.Text()) return n, true }
func main(){
sql = select * from tb force index(a)
pa := parser.New()
if node, err := pa.ParseOneStmt(sql, "", ""); err == nil {
var v = &FingerprintVisitor{}
node.Accept(v)
} else {
fmt.Println(err)
}
}