func (p *Parser) next() scanner.Token {
	if p.tok != nil {
		t := p.tok
		p.tok = nil
		return *t
	}
	tok := <-p.l.Tokens
	if tok.Type() == token.Illegal {
		panic(errors.NewError(tok.Value()))
	}
	return tok
}
next returns the next item from lookahead buffer if not empty or
from the Lexer
package parser
import (
	"fmt"
	"runtime"
	"strconv"
	"github.com/madlambda/nash/ast"
	"github.com/madlambda/nash/errors"
	"github.com/madlambda/nash/scanner"
	"github.com/madlambda/nash/token"
)
type (
	Parser struct {
		name       string  
		content    string
		l          *scanner.Lexer
		tok        *scanner.Token  
		openblocks int
		insidePipe bool
		keywordParsers map[token.Token]parserFn
	}
	parserFn func(tok scanner.Token) (ast.Node, error)
	exprConfig struct {
		allowArg      bool
		allowVariadic bool
		allowFuncall  bool
		allowConcat   bool
	}
)
func NewParser(name, content string) *Parser {
	p := &Parser{
		name:    name,
		content: content,
		l:       scanner.Lex(name, content),
	}
	p.keywordParsers = map[token.Token]parserFn{
		token.For:     p.parseFor,
		token.If:      p.parseIf,
		token.Fn:      p.parseFnDecl,
		token.Var:     p.parseVar,
		token.Return:  p.parseReturn,
		token.Import:  p.parseImport,
		token.SetEnv:  p.parseSetenv,
		token.Rfork:   p.parseRfork,
		token.BindFn:  p.parseBindFn,
		token.Comment: p.parseComment,
		token.Illegal: p.parseError,
	}
	return p
}
func (p *Parser) Parse() (tr *ast.Tree, err error) {
	var root *ast.BlockNode
	defer func() {
		if r := recover(); r != nil {
			if _, ok := r.(runtime.Error); ok {
				panic(r)
			}
			err = r.(error)
		}
	}()
	root, err = p.parseBlock(1, 0)
	if err != nil {
		return nil, err
	}
	tr = ast.NewTree(p.name)
	tr.Root = root
	return tr, nil
}