func (x *jsonLex) lexString(yylval *jsonSymType) int {
	var b bytes.Buffer
	for {
		c := x.next()
		if c == lexEOF {
			break
		}
		if c == '"' {
			break
		}
		if c == '\\' {
			n := x.next()
			switch n {
			case '"':
				c = n
			case 'n':
				c = '\n'
			case '\\':
				c = n
			default:
				x.backup()
			}
		}
		if _, err := b.WriteRune(c); err != nil {
			return lexEOF
		}
	}
	yylval.str = b.String()
	return STRING
}
lexString extracts a string from the input
package json
import (
	"bytes"
	"fmt"
	"strconv"
	"unicode"
	"unicode/utf8"
)
const lexEOF = 0
type jsonLex struct {
	Input string
	pos       int
	width     int
	col, line int
	err       error
}
func (x *jsonLex) Lex(yylval *jsonSymType) int {
	for {
		c := x.next()
		if c == lexEOF {
			return lexEOF
		}
		if unicode.IsSpace(c) {
			continue
		}
		if c >= '0' && c <= '9' {
			x.backup()
			return x.lexNumber(yylval)
		}
		switch c {
		case 'e':
			fallthrough
		case 'E':
			switch x.next() {
			case '+':
				return EPLUS
			case '-':
				return EMINUS
			default:
				x.backup()
				return EPLUS
			}
		case '.':
			return PERIOD
		case '-':
			return MINUS
		case ':':
			return COLON
		case ',':
			return COMMA
		case '[':
			return LEFTBRACKET
		case ']':
			return RIGHTBRACKET
		case '{':
			return LEFTBRACE
		case '}':
			return RIGHTBRACE
		case '"':
			return x.lexString(yylval)
		default:
			x.backup()
			return x.lexId(yylval)
		}
	}
}
func (x *jsonLex) lexId(yylval *jsonSymType) int {
	var b bytes.Buffer
	first := true
	for {
		c := x.next()
		if c == lexEOF {
			break
		}
		if !unicode.IsDigit(c) && !unicode.IsLetter(c) && c != '_' && c != '-' {
			x.backup()
			if first {
				x.createErr("Invalid identifier")
				return lexEOF
			}
			break
		}
		first = false
		if _, err := b.WriteRune(c); err != nil {
			return lexEOF
		}
	}
	switch v := b.String(); v {
	case "true":
		return TRUE
	case "false":
		return FALSE
	case "null":
		return NULL
	default:
		x.createErr(fmt.Sprintf("Invalid identifier: %s", v))
		return lexEOF
	}
}
func (x *jsonLex) lexNumber(yylval *jsonSymType) int {
	var b bytes.Buffer
	gotPeriod := false
	for {
		c := x.next()
		if c == lexEOF {
			break
		}
		if c == '.' {
			if gotPeriod {
				x.backup()
				break
			}
			gotPeriod = true
		} else if c < '0' || c > '9' {
			x.backup()
			break
		}
		if _, err := b.WriteRune(c); err != nil {
			x.createErr(fmt.Sprintf("Internal error: %s", err))
			return lexEOF
		}
	}
	if !gotPeriod {
		v, err := strconv.ParseInt(b.String(), 0, 0)
		if err != nil {
			x.createErr(fmt.Sprintf("Expected number: %s", err))
			return lexEOF
		}
		yylval.num = int(v)
		return NUMBER
	}
	f, err := strconv.ParseFloat(b.String(), 64)
	if err != nil {
		x.createErr(fmt.Sprintf("Expected float: %s", err))
		return lexEOF
	}
	yylval.f = float64(f)
	return FLOAT
}