func (l *Lexer) emit(t Type) {
	var tok string
	if t == BlankLine {
		tok = "\n"
	} else if t == EOF {
		tok = ""
	} else {
		tok = l.lines[l.line][l.start:l.index]
	}
	l.id++
	length := utf8.RuneCountInString(tok)
	nItem := Item{
		ID:   ID(l.id),
		Type: t,
		Text: tok,
		Line: l.lineNumber(),
		StartPosition: l.start + 1,
		Length:        length,
	}
	l.Log("ID", ID(l.id)+1, t.String(), fmt.Sprintf("%q", tok), "l.start+1", l.start+1, "l.index",
		l.index, "line", l.lineNumber())
	l.items <- nItem
	l.lastItem = &nItem
	l.start = l.index
	l.Log("msg", "Position after EMIT", "l.mark", fmt.Sprintf("%q", l.mark), "l.start", l.start,
		"l.index", l.index, "line", l.lineNumber())
}
emit passes an item back to the client.
package token
import (
	"errors"
	"fmt"
	"strings"
	"unicode"
	"unicode/utf8"
	"github.com/demizer/go-rst/pkg/log"
)
type stateFn func(*Lexer) stateFn
type Lexer struct {
	Name    string    
	input   string    
	line    int       
	numLine int       
	state   stateFn   
	lines   []string  
	id    int   
	mark  rune  
	start int   
	index int   
	width int   
	items            chan Item  
	lastItem         *Item      
	lastItemPosition int
	indentLevel int     
	indentWidth string  
	logConf log.Config
	log.Logger
}
func newLexer(name string, input []byte, logConf log.Config) (l *Lexer, err error) {
	if len(input) == 0 {
		err = errors.New("no input given")
		return
	}
	conf := logConf
	conf.Name = "lexer"
	l = &Lexer{
		Name:    name,
		logConf: conf,
		Logger:  log.NewLogger(conf),
	}
	ni, err := normalize(input)
	if err != nil {
		err = fmt.Errorf("could not normalize input: %s", err)
		return
	}
	lines := strings.Split(string(ni), "\n")
	mark, width := utf8.DecodeRuneInString(lines[0][0:])
	l.Log("mark", mark, "index", 0, "line", 1)
	l.input = string(ni)  
	l.lines = lines
	l.items = make(chan Item)
	l.index = 0
	l.mark = mark
	l.width = width
	return
}
func Lex(name string, input []byte, logConf log.Config) (l *Lexer, err error) {
	l, err = newLexer(name, input, logConf)
	if err != nil {
		return
	}
	go l.run()
	return
}
func (l *Lexer) run() {
	for l.state = lexStart; l.state != nil; {
		l.state = l.state(l)
	}
}