func (err FFErr) ToError() error {
	switch err {
	case FFErr_e_ok:
		return nil
	case FFErr_io:
		return errors.New("ffjson: IO error")
	case FFErr_string_invalid_utf8:
		return errors.New("ffjson: string with invalid UTF-8 sequence")
	case FFErr_string_invalid_escaped_char:
		return errors.New("ffjson: string with invalid escaped character")
	case FFErr_string_invalid_json_char:
		return errors.New("ffjson: string with invalid JSON character")
	case FFErr_string_invalid_hex_char:
		return errors.New("ffjson: string with invalid hex character")
	case FFErr_invalid_char:
		return errors.New("ffjson: invalid character")
	case FFErr_invalid_string:
		return errors.New("ffjson: invalid string")
	case FFErr_missing_integer_after_decimal:
		return errors.New("ffjson: missing integer after decimal")
	case FFErr_missing_integer_after_exponent:
		return errors.New("ffjson: missing integer after exponent")
	case FFErr_missing_integer_after_minus:
		return errors.New("ffjson: missing integer after minus")
	case FFErr_unallowed_comment:
		return errors.New("ffjson: unallowed comment")
	case FFErr_incomplete_comment:
		return errors.New("ffjson: incomplete comment")
	case FFErr_unexpected_token_type:
		return errors.New("ffjson: unexpected token sequence")
	}
	panic(fmt.Sprintf("unknown error type: %v ", err))
}
TODO(pquerna): return line number and offset.
package v1
import (
	"errors"
	"fmt"
	"io"
)
type FFParseState int
const (
	FFParse_map_start FFParseState = iota
	FFParse_want_key
	FFParse_want_colon
	FFParse_want_value
	FFParse_after_value
)
type FFTok int
const (
	FFTok_init          FFTok = iota
	FFTok_bool          FFTok = iota
	FFTok_colon         FFTok = iota
	FFTok_comma         FFTok = iota
	FFTok_eof           FFTok = iota
	FFTok_error         FFTok = iota
	FFTok_left_brace    FFTok = iota
	FFTok_left_bracket  FFTok = iota
	FFTok_null          FFTok = iota
	FFTok_right_brace   FFTok = iota
	FFTok_right_bracket FFTok = iota
	FFTok_integer FFTok = iota
	FFTok_double  FFTok = iota
	FFTok_string FFTok = iota
	FFTok_comment FFTok = iota
)
type FFErr int
const (
	FFErr_e_ok                           FFErr = iota
	FFErr_io                             FFErr = iota
	FFErr_string_invalid_utf8            FFErr = iota
	FFErr_string_invalid_escaped_char    FFErr = iota
	FFErr_string_invalid_json_char       FFErr = iota
	FFErr_string_invalid_hex_char        FFErr = iota
	FFErr_invalid_char                   FFErr = iota
	FFErr_invalid_string                 FFErr = iota
	FFErr_missing_integer_after_decimal  FFErr = iota
	FFErr_missing_integer_after_exponent FFErr = iota
	FFErr_missing_integer_after_minus    FFErr = iota
	FFErr_unallowed_comment              FFErr = iota
	FFErr_incomplete_comment             FFErr = iota
	FFErr_unexpected_token_type          FFErr = iota  
)
type FFLexer struct {
	reader   *ffReader
	Output   DecodingBuffer
	Token    FFTok
	Error    FFErr
	BigError error
	lastCurrentChar int
	captureAll      bool
	buf             Buffer
}
func NewFFLexer(input []byte) *FFLexer {
	fl := &FFLexer{
		Token:  FFTok_init,
		Error:  FFErr_e_ok,
		reader: newffReader(input),
		Output: &Buffer{},
	}
	return fl
}
type LexerError struct {
	offset int
	line   int
	char   int
	err    error
}
func (ffl *FFLexer) Reset(input []byte) {
	ffl.Token = FFTok_init
	ffl.Error = FFErr_e_ok
	ffl.BigError = nil
	ffl.reader.Reset(input)
	ffl.lastCurrentChar = 0
	ffl.Output.Reset()
}
func (le *LexerError) Error() string {
	return fmt.Sprintf(`ffjson error: (%T)%s offset=%d line=%d char=%d`,
		le.err, le.err.Error(),
		le.offset, le.line, le.char)
}
func (ffl *FFLexer) WrapErr(err error) error {
	line, char := ffl.reader.PosWithLine()
	return &LexerError{
		offset: ffl.reader.Pos(),
		line:   line,
		char:   char,
		err:    err,
	}
}
func (ffl *FFLexer) scanReadByte() (byte, error) {
	var c byte
	var err error
	if ffl.captureAll {
		c, err = ffl.reader.ReadByte()
	} else {
		c, err = ffl.reader.ReadByteNoWS()
	}
	if err != nil {
		ffl.Error = FFErr_io
		ffl.BigError = err
		return 0, err
	}
	return c, nil
}
func (ffl *FFLexer) readByte() (byte, error) {
	c, err := ffl.reader.ReadByte()
	if err != nil {
		ffl.Error = FFErr_io
		ffl.BigError = err
		return 0, err
	}
	return c, nil
}
func (ffl *FFLexer) unreadByte() {
	ffl.reader.UnreadByte()
}
func (ffl *FFLexer) wantBytes(want []byte, iftrue FFTok) FFTok {
	startPos := ffl.reader.Pos()
	for _, b := range want {
		c, err := ffl.readByte()
		if err != nil {
			return FFTok_error
		}
		if c != b {
			ffl.unreadByte()
			ffl.Error = FFErr_invalid_string
			return FFTok_error
		}
	}
	endPos := ffl.reader.Pos()
	ffl.Output.Write(ffl.reader.Slice(startPos, endPos))
	return iftrue
}
func (ffl *FFLexer) lexComment() FFTok {
	c, err := ffl.readByte()
	if err != nil {
		return FFTok_error
	}
	if c == '/' {
		for {
			c, err := ffl.readByte()
			if err != nil {
				return FFTok_error
			}
			if c == '\n' {
				return FFTok_comment
			}
		}
	} else if c == '*' {
		for {
			c, err := ffl.readByte()
			if err != nil {
				return FFTok_error
			}
			if c == '*' {
				c, err := ffl.readByte()
				if err != nil {
					return FFTok_error
				}
				if c == '/' {
					return FFTok_comment
				}
				ffl.Error = FFErr_incomplete_comment
				return FFTok_error
			}
		}
	} else {
		ffl.Error = FFErr_incomplete_comment
		return FFTok_error
	}
}
func (ffl *FFLexer) lexString() FFTok {
	if ffl.captureAll {
		ffl.buf.Reset()
		err := ffl.reader.SliceString(&ffl.buf)
		if err != nil {
			ffl.BigError = err
			return FFTok_error
		}
		WriteJson(ffl.Output, ffl.buf.Bytes())
		return FFTok_string
	} else {
		err := ffl.reader.SliceString(ffl.Output)
		if err != nil {
			ffl.BigError = err
			return FFTok_error
		}
		return FFTok_string
	}
}
func (ffl *FFLexer) lexNumber() FFTok {
	var numRead int = 0
	tok := FFTok_integer
	startPos := ffl.reader.Pos()
	c, err := ffl.readByte()
	if err != nil {
		return FFTok_error
	}
	if c == '-' {
		c, err = ffl.readByte()
		if err != nil {
			return FFTok_error
		}
	}
	if c == '0' {
		c, err = ffl.readByte()
		if err != nil {
			return FFTok_error
		}
	} else if c >= '1' && c <= '9' {
		for c >= '0' && c <= '9' {
			c, err = ffl.readByte()
			if err != nil {
				return FFTok_error
			}
		}
	} else {
		ffl.unreadByte()
		ffl.Error = FFErr_missing_integer_after_minus
		return FFTok_error
	}
	if c == '.' {
		numRead = 0
		c, err = ffl.readByte()
		if err != nil {
			return FFTok_error
		}
		for c >= '0' && c <= '9' {
			numRead++
			c, err = ffl.readByte()
			if err != nil {
				return FFTok_error
			}
		}
		if numRead == 0 {
			ffl.unreadByte()
			ffl.Error = FFErr_missing_integer_after_decimal
			return FFTok_error
		}
		tok = FFTok_double
	}
	if c == 'e' || c == 'E' {
		numRead = 0
		c, err = ffl.readByte()
		if err != nil {
			return FFTok_error
		}
		if c == '+' || c == '-' {
			c, err = ffl.readByte()
			if err != nil {
				return FFTok_error
			}
		}
		for c >= '0' && c <= '9' {
			numRead++
			c, err = ffl.readByte()
			if err != nil {
				return FFTok_error
			}
		}
		if numRead == 0 {
			ffl.Error = FFErr_missing_integer_after_exponent
			return FFTok_error
		}
		tok = FFTok_double
	}
	ffl.unreadByte()
	endPos := ffl.reader.Pos()
	ffl.Output.Write(ffl.reader.Slice(startPos, endPos))
	return tok
}
var true_bytes = []byte{'r', 'u', 'e'}
var false_bytes = []byte{'a', 'l', 's', 'e'}
var null_bytes = []byte{'u', 'l', 'l'}
func (ffl *FFLexer) Scan() FFTok {
	tok := FFTok_error
	if ffl.captureAll == false {
		ffl.Output.Reset()
	}
	ffl.Token = FFTok_init
	for {
		c, err := ffl.scanReadByte()
		if err != nil {
			if err == io.EOF {
				return FFTok_eof
			} else {
				return FFTok_error
			}
		}
		switch c {
		case '{':
			tok = FFTok_left_bracket
			if ffl.captureAll {
				ffl.Output.WriteByte('{')
			}
			goto lexed
		case '}':
			tok = FFTok_right_bracket
			if ffl.captureAll {
				ffl.Output.WriteByte('}')
			}
			goto lexed
		case '[':
			tok = FFTok_left_brace
			if ffl.captureAll {
				ffl.Output.WriteByte('[')
			}
			goto lexed
		case ']':
			tok = FFTok_right_brace
			if ffl.captureAll {
				ffl.Output.WriteByte(']')
			}
			goto lexed
		case ',':
			tok = FFTok_comma
			if ffl.captureAll {
				ffl.Output.WriteByte(',')
			}
			goto lexed
		case ':':
			tok = FFTok_colon
			if ffl.captureAll {
				ffl.Output.WriteByte(':')
			}
			goto lexed
		case '\t', '\n', '\v', '\f', '\r', ' ':
			if ffl.captureAll {
				ffl.Output.WriteByte(c)
			}
			break
		case 't':
			ffl.Output.WriteByte('t')
			tok = ffl.wantBytes(true_bytes, FFTok_bool)
			goto lexed
		case 'f':
			ffl.Output.WriteByte('f')
			tok = ffl.wantBytes(false_bytes, FFTok_bool)
			goto lexed
		case 'n':
			ffl.Output.WriteByte('n')
			tok = ffl.wantBytes(null_bytes, FFTok_null)
			goto lexed
		case '"':
			tok = ffl.lexString()
			goto lexed
		case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			ffl.unreadByte()
			tok = ffl.lexNumber()
			goto lexed
		case '/':
			tok = ffl.lexComment()
			goto lexed
		default:
			tok = FFTok_error
			ffl.Error = FFErr_invalid_char
		}
	}
lexed:
	ffl.Token = tok
	return tok
}
func (ffl *FFLexer) scanField(start FFTok, capture bool) ([]byte, error) {
	switch start {
	case FFTok_left_brace,
		FFTok_left_bracket:
		{
			end := FFTok_right_brace
			if start == FFTok_left_bracket {
				end = FFTok_right_bracket
				if capture {
					ffl.Output.WriteByte('{')
				}
			} else {
				if capture {
					ffl.Output.WriteByte('[')
				}
			}
			depth := 1
			if capture {
				ffl.captureAll = true
			}
		scanloop:
			for {
				tok := ffl.Scan()
				switch tok {
				case FFTok_eof:
					return nil, errors.New("ffjson: unexpected EOF")
				case FFTok_error:
					if ffl.BigError != nil {
						return nil, ffl.BigError
					}
					return nil, ffl.Error.ToError()
				case end:
					depth--
					if depth == 0 {
						break scanloop
					}
				case start:
					depth++
				}
			}
			if capture {
				ffl.captureAll = false
			}
			if capture {
				return ffl.Output.Bytes(), nil
			} else {
				return nil, nil
			}
		}
	case FFTok_bool,
		FFTok_integer,
		FFTok_null,
		FFTok_double:
		if capture {
			return ffl.Output.Bytes(), nil
		} else {
			return nil, nil
		}
	case FFTok_string:
		if capture {
			ffl.buf.Reset()
			WriteJson(&ffl.buf, ffl.Output.Bytes())
			return ffl.buf.Bytes(), nil
		} else {
			return nil, nil
		}
	default:
		return nil, fmt.Errorf("ffjson: invalid capture type: %v", start)
	}
	panic("not reached")
}
func (ffl *FFLexer) CaptureField(start FFTok) ([]byte, error) {
	return ffl.scanField(start, true)
}
func (ffl *FFLexer) SkipField(start FFTok) error {
	_, err := ffl.scanField(start, false)
	return err
}