Skip to content

Instantly share code, notes, and snippets.

@bopjiang
Last active April 2, 2019 00:59
Show Gist options
  • Save bopjiang/b5d7de1471d1a1be3387e33c6eb30591 to your computer and use it in GitHub Desktop.
Save bopjiang/b5d7de1471d1a1be3387e33c6eb30591 to your computer and use it in GitHub Desktop.
ast go run select.go
package main
import (
"strings"
"fmt"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser"
_ "github.com/pingcap/tidb/types/parser_driver"
)
type visitor struct{}
var (
level = 0
sp = "++"
)
func (v *visitor) Enter(in ast.Node) (out ast.Node, skipChildren bool) {
s := strings.Repeat("\t", level)
fmt.Printf("L-%d %s%T %s\n", level, s, in, in.Text())
level += 1
return in, false
}
func (v *visitor) Leave(in ast.Node) (out ast.Node, ok bool) {
level -= 1
//s := strings.Repeat("\t", level)
//fmt.Printf("L%d%s%T\n", level, s, in)
return in, true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment