static struct jx_item * jx_parse_item_list( struct jx_parser *s ) { jx_token_t t = jx_scan(s); if(t==JX_TOKEN_RBRACKET) { // empty list return 0; } jx_unscan(s,t); struct jx_item *i = jx_item(0,0); i->value = jx_parse(s); if(!i->value) { // error set by deeper layer jx_item_delete(i); return 0; } t = jx_scan(s); if(t==JX_TOKEN_COMMA) { i->next = jx_parse_item_list(s); } else if(t==JX_TOKEN_RBRACKET) { i->next = 0; } else { jx_parse_error(s,"array items missing a comma or closing brace"); jx_item_delete(i); return 0; } return i; }
static struct jx_item * jx_eval_item( struct jx_item *item, struct jx *context ) { if(!item) return 0; return jx_item( jx_eval(item->value,context), jx_eval_item(item->next,context) ); }
void jx_array_append( struct jx *array, struct jx *value ) { struct jx_item **i; for(i=&array->u.items;*i;i=&(*i)->next) { } *i = jx_item(value,0); }
void jx_array_insert( struct jx *array, struct jx *value ) { array->u.items = jx_item(value, array->u.items); }