| 207 | } |
| 208 | |
| 209 | func (d *Decoder) stateArrayValue() ([]byte, error) { |
| 210 | tok := d.scanner.Next() |
| 211 | if len(tok) < 1 { |
| 212 | return nil, io.ErrUnexpectedEOF |
| 213 | } |
| 214 | switch tok[0] { |
| 215 | case '{': |
| 216 | d.state = (*Decoder).stateObjectString |
| 217 | d.push(true) |
| 218 | return tok, nil |
| 219 | case '[': |
| 220 | d.state = (*Decoder).stateArrayValue |
| 221 | d.push(false) |
| 222 | return tok, nil |
| 223 | case ']': |
| 224 | if d.mustHaveValue { |
| 225 | d.scanner.offset -= len(tok) + 1 // Rewind to point to comma. |
| 226 | return nil, fmt.Errorf("stateArrayValue: unexpected comma") |
| 227 | } |
| 228 | inObj := d.pop() |
| 229 | switch { |
| 230 | case d.len() == 0: |
| 231 | d.state = (*Decoder).stateEnd |
| 232 | case inObj: |
| 233 | d.state = (*Decoder).stateObjectComma |
| 234 | case !inObj: |
| 235 | d.state = (*Decoder).stateArrayComma |
| 236 | } |
| 237 | return tok, nil |
| 238 | case Comma: |
| 239 | return nil, fmt.Errorf("stateArrayValue: unexpected comma") |
| 240 | default: |
| 241 | d.state = (*Decoder).stateArrayComma |
| 242 | return tok, nil |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | func (d *Decoder) stateArrayComma() (_ []byte, err error) { |
| 247 | tok := d.scanner.Next() |