Skip to content

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

@zjcxc

Description

@zjcxc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions