Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,042 changes: 1,042 additions & 0 deletions cassandra/ast/node.go

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions cassandra/ast/walk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ast

// Visitor defines the interface for AST traversal.
type Visitor interface {
Visit(node Node) Visitor
}

// Walk traverses an AST in depth-first order. It calls v.Visit(node); if that
// returns a non-nil Visitor w, Walk recurses into the children of node with w,
// then calls w.Visit(nil).
func Walk(v Visitor, node Node) {
if node == nil {
return
}
if v = v.Visit(node); v == nil {
return
}
walkChildren(v, node)
v.Visit(nil)
}

// Inspect traverses an AST in depth-first order, calling f for each node.
// If f returns true, Inspect recurses into the children of node.
func Inspect(node Node, f func(Node) bool) {
Walk(inspector(f), node)
}

type inspector func(Node) bool

func (f inspector) Visit(node Node) Visitor {
if node == nil || !f(node) {
return nil
}
return f
}
Loading
Loading