func (l *Scanner) Scan() *token.Token {
	for {
		select {
		case item := <-l.items:
			return item
		default:
			if l.state == nil {
				return nil
			}
			l.state = l.state(l)
		}
	}
}
Scan returns the next item from the input (or nil)
package scanner
import (
	"bytes"
	"fmt"
	"regexp"
	"strings"
	"unicode/utf8"
	"github.com/arnodel/golua/token"
)
type Scanner struct {
	name             string  
	input            []byte  
	start, last, pos token.Pos
	items            chan *token.Token  
	state            stateFn
	errorMsg         string
}
func New(name string, input []byte) *Scanner {
	l := &Scanner{
		name:  name,
		input: normalizeNewLines(input),
		state: scanToken,
		items: make(chan *token.Token, 2),  
		pos:   token.Pos{Line: 1, Column: 1},
		start: token.Pos{Line: 1, Column: 1},
	}
	return l
}
type stateFn func(*Scanner) stateFn
func (l *Scanner) emit(tp token.Type) {
	lit := l.lit()
	if tp == token.INVALID {
		fmt.Println("Cannot emit", string(lit))
		panic("emit bails out")
	}
	l.items <- &token.Token{
		Type: tp,
		Lit:  lit,
		Pos:  l.start,
	}
	l.start = l.pos
}
func (l *Scanner) lit() []byte {
	return l.input[l.start.Offset:l.pos.Offset]
}
func (l *Scanner) next() rune {
	if l.pos.Offset >= len(l.input) {
		l.last = l.pos
		return -1
	}
	c, width := utf8.DecodeRune(l.input[l.pos.Offset:])
	l.last = l.pos
	l.pos.Offset += width
	if c == '\n' || c == '\r' {
		l.pos.Line++
		l.pos.Column = 1
	} else {
		l.pos.Column++
	}
	return c
}
func (l *Scanner) ignore() {
	l.start = l.pos
	l.last = token.Pos{}
}
func (l *Scanner) backup() {
	l.pos = l.last
}
func (l *Scanner) peek() rune {
	next := l.next()
	l.backup()
	return next
}
func (l *Scanner) accept(valid string) bool {
	if strings.ContainsRune(valid, l.next()) {
		return true
	}
	l.backup()
	return false
}
func (l *Scanner) errorf(format string, args ...interface{}) stateFn {
	l.errorMsg = fmt.Sprintf(format, args...)
	l.items <- &token.Token{
		Type: token.INVALID,
		Lit:  l.lit(),
		Pos:  l.start,
	}
	return nil
}