package jx

import (
	
)

// ArrIter is decoding array iterator.
type ArrIter struct {
	d      *Decoder
	err    error
	closed bool
	comma  bool
}

// ArrIter creates new array iterator.
func ( *Decoder) () (ArrIter, error) {
	if  := .consume('[');  != nil {
		return ArrIter{}, errors.Wrap(, `"[" expected`)
	}
	if  := .incDepth();  != nil {
		return ArrIter{}, 
	}
	if ,  := .more();  != nil {
		return ArrIter{}, 
	}
	.unread()
	return ArrIter{d: }, nil
}

// Next consumes element and returns false, if there is no elements anymore.
func ( *ArrIter) () bool {
	if .closed || .err != nil {
		return false
	}

	 := .d
	,  := .more()
	if  != nil {
		.err = 
		return false
	}
	if  == ']' {
		.closed = true
		.err = .decDepth()
		return false
	}
	if .comma {
		if  != ',' {
			 := badToken(, .offset()-1)
			.err = errors.Wrap(, `"," expected`)
			return false
		}
	} else {
		.unread()
	}
	.comma = true
	return true
}

// Err returns the error, if any, that was encountered during iteration.
func ( *ArrIter) () error {
	return .err
}