func (t *Tree) leave(n Node) {
	for _, v := range t.Visitors {
		v.Leave(n)
	}
}
Leave is called just before the state exits the given Node.
package parse  
import (
	"bytes"
	"io"
)
type NodeVisitor interface {
	Enter(Node)  
	Leave(Node)  
}
type Tree struct {
	lex *lexer
	root   *ModuleNode
	blocks []map[string]*BlockNode  
	macros map[string]*MacroNode    
	unread []token  
	read   []token  
	Name string  
	Visitors []NodeVisitor
}
func NewTree(input io.Reader) *Tree {
	return NewNamedTree("", input)
}
func NewNamedTree(name string, input io.Reader) *Tree {
	return &Tree{
		lex: newLexer(input),
		root:   NewModuleNode(name),
		blocks: []map[string]*BlockNode{make(map[string]*BlockNode)},
		macros: make(map[string]*MacroNode),
		unread: make([]token, 0),
		read:   make([]token, 0),
		Name:     name,
		Visitors: make([]NodeVisitor, 0),
	}
}
func (t *Tree) Root() *ModuleNode {
	return t.root
}
func (t *Tree) Blocks() map[string]*BlockNode {
	return t.blocks[len(t.blocks)-1]
}
func (t *Tree) Macros() map[string]*MacroNode {
	return t.macros
}
func (t *Tree) popBlockStack() map[string]*BlockNode {
	blocks := t.Blocks()
	t.blocks = t.blocks[0 : len(t.blocks)-1]
	return blocks
}
func (t *Tree) pushBlockStack() {
	t.blocks = append(t.blocks, make(map[string]*BlockNode))
}
func (t *Tree) setBlock(name string, body *BlockNode) {
	t.blocks[len(t.blocks)-1][name] = body
}
func (t *Tree) enrichError(err error) error {
	if err, ok := err.(ParsingError); ok {
		err.setTree(t)
	}
	return err
}
func (t *Tree) peek() token {
	tok := t.next()
	t.backup()
	return tok
}
func (t *Tree) peekNonSpace() token {
	var next token
	for {
		next = t.next()
		if next.tokenType != tokenWhitespace {
			t.backup()
			return next
		}
	}
}
func (t *Tree) backup() {
	var tok token
	tok, t.read = t.read[len(t.read)-1], t.read[:len(t.read)-1]
	t.unread = append(t.unread, tok)
}
func (t *Tree) backup2() {
	t.backup()
	t.backup()
}
func (t *Tree) backup3() {
	t.backup()
	t.backup()
	t.backup()
}
func (t *Tree) next() token {
	var tok token
	if len(t.unread) > 0 {
		tok, t.unread = t.unread[len(t.unread)-1], t.unread[:len(t.unread)-1]
	} else {
		tok = t.lex.nextToken()
	}
	t.read = append(t.read, tok)
	return tok
}
func (t *Tree) nextNonSpace() token {
	var next token
	for {
		next = t.next()
		if next.tokenType != tokenWhitespace {
			return next
		}
	}
}
func (t *Tree) expect(typs ...tokenType) (token, error) {
	tok := t.nextNonSpace()
	for _, typ := range typs {
		if tok.tokenType == typ {
			return tok, nil
		}
	}
	return tok, newUnexpectedTokenError(tok, typs...)
}
func (t *Tree) expectValue(typ tokenType, val string) (token, error) {
	tok, err := t.expect(typ)
	if err != nil {
		return tok, err
	}
	if tok.value != val {
		return tok, newUnexpectedValueError(tok, val)
	}
	return tok, nil
}
func (t *Tree) enter(n Node) {
	for _, v := range t.Visitors {
		v.Enter(n)
	}
}