parser icon indicating copy to clipboard operation
parser copied to clipboard

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

Open zjcxc opened this issue 3 years ago • 0 comments

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

zjcxc avatar Sep 14 '22 08:09 zjcxc