diff options
| -rw-r--r-- | walk/read.go | 19 | 
1 files changed, 10 insertions, 9 deletions
| diff --git a/walk/read.go b/walk/read.go index f123369..e46ae58 100644 --- a/walk/read.go +++ b/walk/read.go @@ -19,8 +19,7 @@ const (  type JSONInStructure int  const ( -	JSONInRoot JSONInStructure = iota -	JSONInMap +	JSONInMap JSONInStructure = iota  	JSONInArray  ) @@ -49,7 +48,7 @@ func NewJSONIn(reader *bufio.Reader) JSONIn {  	return JSONIn {  		path: make([]Atom, 0, 256),  		reader: reader, -		structure: []JSONInStructure{JSONInRoot}, +		structure: []JSONInStructure{},  		state: JSONInValueStart,  		readBuffer: make([]Atom, 0, 256),  		readIndex: 0, @@ -227,7 +226,7 @@ func (in *JSONIn) Read() (WalkItem, error) {  }  func (in *JSONIn) AssertDone() { -	if len(in.structure) != 1 || in.structure[0] != JSONInRoot { +	if len(in.structure) != 0 || in.state != JSONInValueEnd || in.readIndex < len(in.readBuffer) {  		panic("Input ended on incomplete JSON root")  	}  } @@ -259,14 +258,15 @@ func (in *JSONIn) fillReadBuffer() error {  			panic("Invalid JSONInState")  	}  	valueStart: { +		if len(in.structure) == 0 { +			goto value +		}  		innermost := in.structure[len(in.structure) - 1]  		switch innermost {  			case JSONInMap:  				goto mapValue  			case JSONInArray:  				goto arrayValue -			case JSONInRoot: -				goto value  			default:  				panic("Invalid JSONInStructure")  		} @@ -430,10 +430,11 @@ func (in *JSONIn) fillReadBuffer() error {  			in.state = JSONInValueEnd  			return err  		} -		innermost := in.structure[len(in.structure) - 1] -		if innermost == JSONInRoot { +		if len(in.structure) == 0 {  			panic("More input after root JSON object ends") -		} else if innermost == JSONInMap && r == '}' { +		} +		innermost := in.structure[len(in.structure) - 1] +		if innermost == JSONInMap && r == '}' {  			in.structure = in.structure[:len(in.structure) - 1]  			in.pushActionBuffer(ActionPopPath)  			in.pushActionBuffer(ActionReadValue) | 
