pingcap / parser

A MySQL Compatible SQL Parser
Apache License 2.0
1.41k stars 489 forks source link

Node.OriginTextPosition() always return 0 and Text() return empty #1425

Open zjcxc opened 2 years ago

zjcxc commented 2 years ago

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