func (s *scanner) eof() int {
	if s.err != nil {
		return scanError
	}
	if s.endTop {
		return scanEnd
	}
	s.step(s, ' ')
	if s.endTop {
		return scanEnd
	}
	if s.err == nil {
		s.err = &SyntaxError{"unexpected end of JSON input", s.bytes}
	}
	return scanError
}
eof tells the scanner that the end of input has been reached.
It returns a scan status just as s.step does.
package json
import "strconv"
func checkValid(data []byte, scan *scanner) error {
	scan.reset()
	for _, c := range data {
		scan.bytes++
		if scan.step(scan, c) == scanError {
			return scan.err
		}
	}
	if scan.eof() == scanError {
		return scan.err
	}
	return nil
}
func nextValue(data []byte, scan *scanner) (value, rest []byte, err error) {
	scan.reset()
	for i, c := range data {
		v := scan.step(scan, c)
		if v >= scanEndObject {
			switch v {
			case scanEndObject, scanEndArray, scanEndParams:
				if scan.step(scan, ' ') == scanEnd {
					return data[:i+1], data[i+1:], nil
				}
			case scanError:
				return nil, nil, scan.err
			case scanEnd:
				return data[:i], data[i:], nil
			}
		}
	}
	if scan.eof() == scanError {
		return nil, nil, scan.err
	}
	return data, nil, nil
}
type SyntaxError struct {
	msg    string  
	Offset int64   
}
func (e *SyntaxError) Error() string { return e.msg }
type scanner struct {
	step func(*scanner, byte) int
	endTop bool
	parseState []int
	err error
	redo      bool
	redoCode  int
	redoState func(*scanner, byte) int
	bytes int64
}
const (
	scanContinue     = iota  
	scanBeginLiteral         
	scanBeginObject          
	scanObjectKey            
	scanObjectValue          
	scanEndObject            
	scanBeginArray           
	scanArrayValue           
	scanEndArray             
	scanBeginName            
	scanParam                
	scanEndParams            
	scanSkipSpace            
	scanEnd    
	scanError  
)
const (
	parseObjectKey   = iota  
	parseObjectValue         
	parseArrayValue          
	parseName                
	parseParam               
)
func (s *scanner) reset() {
	s.step = stateBeginValue
	s.parseState = s.parseState[0:0]
	s.err = nil
	s.redo = false
	s.endTop = false
}