func lexStatement(l *lexer) lexFn {
	r := l.peek()
	switch {
	case r == '.' || validFirstRune(r):
		return lexBareWord
	case r == '[':
		return lexBraces
	case r == ' ', r == '=':
		return lexValue
	case r == '-':
		return lexIgnore
	case r == utf8.RuneError:
		return nil
	default:
		l.emit(typError)
		return nil
	}
}
lexStatement is the highest level lexFn. Its only job
is to determine which more specific lexFn to use
package main
import (
	"encoding/json"
	"fmt"
	"strconv"
	"strings"
	"unicode"
	"unicode/utf8"
	"github.com/pkg/errors"
)
type errRecoverable struct {
	msg string
}
func (e errRecoverable) Error() string {
	return e.msg
}
type lexer struct {
	text       string   
	pos        int      
	width      int      
	cur        rune     
	prev       rune     
	tokens     []token  
	tokenStart int      
}
func newLexer(text string) *lexer {
	return &lexer{
		text:       text,
		pos:        0,
		tokenStart: 0,
		tokens:     make([]token, 0),
	}
}
func (l *lexer) lex() statement {
	for lexfn := lexStatement; lexfn != nil; {
		lexfn = lexfn(l)
	}
	return l.tokens
}
func (l *lexer) next() rune {
	r, w := utf8.DecodeRuneInString(l.text[l.pos:])
	l.pos += w
	l.width = w
	l.prev = l.cur
	l.cur = r
	return r
}
func (l *lexer) backup() {
	l.pos -= l.width
}
func (l *lexer) peek() rune {
	r := l.next()
	l.backup()
	return r
}
func (l *lexer) ignore() {
	l.tokenStart = l.pos
}
func (l *lexer) emit(typ tokenTyp) {
	t := token{
		text: l.text[l.tokenStart:l.pos],
		typ:  typ,
	}
	l.tokenStart = l.pos
	l.tokens = append(l.tokens, t)
}
func (l *lexer) accept(valid string) bool {
	if strings.ContainsRune(valid, l.next()) {
		return true
	}
	l.backup()
	return false
}
func (l *lexer) acceptRun(valid string) {
	for strings.ContainsRune(valid, l.next()) {
	}
	l.backup()
}
type runeCheck func(rune) bool
func (l *lexer) acceptFunc(fn runeCheck) bool {
	if fn(l.next()) {
		return true
	}
	l.backup()
	return false
}
func (l *lexer) acceptRunFunc(fn runeCheck) {
	for fn(l.next()) {
	}
	l.backup()
}
func (l *lexer) acceptUntil(delims string) {
	for !strings.ContainsRune(delims, l.next()) {
		if l.cur == utf8.RuneError {
			return
		}
	}
	l.backup()
}
func (l *lexer) acceptUntilUnescaped(delims string) {
	inEscape := false
	for {
		r := l.next()
		if r == '\\' && !inEscape {
			inEscape = true
			continue
		}
		if strings.ContainsRune(delims, r) && !inEscape {
			l.backup()
			return
		}
		if l.cur == utf8.RuneError {
			return
		}
		inEscape = false
	}
}
type lexFn func(*lexer) lexFn