Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
9384fdc9
Commit
9384fdc9
authored
Nov 01, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/ast: add Inspect function for easy AST inspection w/o a visitor
R=rsc CC=golang-dev
https://golang.org/cl/2770044
parent
035696c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
src/pkg/go/ast/walk.go
src/pkg/go/ast/walk.go
+19
-0
No files found.
src/pkg/go/ast/walk.go
View file @
9384fdc9
...
...
@@ -321,3 +321,22 @@ func Walk(v Visitor, node interface{}) {
v
.
Visit
(
nil
)
}
type
inspector
func
(
node
interface
{})
bool
func
(
f
inspector
)
Visit
(
node
interface
{})
Visitor
{
if
node
!=
nil
&&
f
(
node
)
{
return
f
}
return
nil
}
// Inspect traverses an AST in depth-first order: If node != nil, it
// invokes f(node). If f returns true, inspect invokes f for all the
// non-nil children of node, recursively.
//
func
Inspect
(
ast
interface
{},
f
func
(
node
interface
{})
bool
)
{
Walk
(
inspector
(
f
),
ast
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment