| 1 |
package decoder |
| 2 |
|
| 3 |
// The tokens of a stream are read as encoding/json reads them: the stream keeps where it is in the objects and |
| 4 |
// the arrays which Token opened, so that a delimiter is checked by the grammar, and a value which Decode reads |
| 5 |
// between the tokens follows the comma or the colon before it. |
| 6 |
|
| 7 |
// tokenState is where the stream is between the tokens of the objects and the arrays which Token opened. |
| 8 |
type tokenState uint8 |
| 9 |
|
| 10 |
const ( |
| 11 |
// tokenTopValue is out of any: the values of the stream follow each other. |
| 12 |
tokenTopValue tokenState = iota |
| 13 |
tokenArrayStart |
| 14 |
tokenArrayValue |
| 15 |
tokenArrayComma |
| 16 |
tokenObjectStart |
| 17 |
tokenObjectKey |
| 18 |
tokenObjectColon |
| 19 |
tokenObjectValue |
| 20 |
tokenObjectComma |
| 21 |
// tokenFailed is after a read which failed: every read returns its error. |
| 22 |
tokenFailed |
| 23 |
) |
| 24 |
|
| 25 |
// tokenValueEnd moves the state after a value, which is the key of an object where one is waited for, as |
| 26 |
// encoding/json of Go 1.27 reads it. |
| 27 |
func (s *Stream) tokenValueEnd() { |
| 28 |
switch s.tokenState { |
| 29 |
case tokenArrayStart, tokenArrayValue: |
| 30 |
s.tokenState = tokenArrayComma |
| 31 |
case tokenObjectValue: |
| 32 |
s.tokenState = tokenObjectComma |
| 33 |
case tokenObjectStart, tokenObjectKey: |
| 34 |
s.tokenState = tokenObjectColon |
| 35 |
} |
| 36 |
} |