1
0
mirror of https://github.com/golang/go synced 2024-10-04 07:21:22 -06:00
go/src/cmd/godoc
Roger Peppe 80e17d6797 the AST walker currently provides no way to find out how the
nodes in the tree are nested with respect to one another.
a simple change to the Visitor interface makes it possible
to do this (for example to maintain a current node-depth, or a
knowledge of the name of the current function).

Visit(nil) is called at the end of a node's children;
this make possible the channel-based interface below,
amongst other possibilities.

It is still just as simple to get the original behaviour - just
return the same Visitor from Visit.

Here are a couple of possible Visitor types.

// closure-based
type FVisitor func(n interface{}) FVisitor
func (f FVisitor) Visit(n interface{}) Visitor {
	return f(n);
}

// channel-based
type CVisitor chan Visit;
type Visit struct {
	node interface{};
	reply chan CVisitor;
};
func (v CVisitor) Visit(n interface{}) Visitor
{
	if n == nil {
		close(v);
	} else {
		reply := make(chan CVisitor);
		v <- Visit{n, reply};
		r := <-reply;
		if r == nil {
			return nil;
		}
		return r;
	}
	return nil;
}

R=gri
CC=rsc
https://golang.org/cl/166047
2009-12-07 10:33:45 -08:00
..
doc.go tweak documentation of commands 2009-11-09 11:45:15 -08:00
godoc.go move ReadFile, WriteFile, and ReadDir into a separate io/ioutil package. 2009-12-02 22:02:14 -08:00
index.go the AST walker currently provides no way to find out how the 2009-12-07 10:33:45 -08:00
main.go some godoc cleanup: 2009-12-01 09:15:05 -08:00
Makefile go: makes it build for the case $GOROOT has whitespaces 2009-11-23 17:32:51 -08:00
snippet.go remove semis after statements in one-statement statement lists 2009-11-09 12:07:39 -08:00
spec.go - replaced gofmt expression formatting algorithm with 2009-11-09 21:09:34 -08:00