020b692014-10-23Arne Goedeke /* vim:syntax=ragel */
a9deeb2010-06-10Arne Goedeke  %%{ machine JSON_array; alphtype int; include JSOND "json_defaults.rl";
a9e2ef2010-06-10Arne Goedeke  getkey ((int)INDEX_PCHARP(str, fpc));
a9deeb2010-06-10Arne Goedeke  action parse_value {
b56cb92010-06-10Arne Goedeke  state->level++; p = _parse_JSON(str, fpc, pe, state); state->level--;
a9deeb2010-06-10Arne Goedeke 
b56cb92010-06-10Arne Goedeke  if (state->flags&JSON_ERROR) {
020b692014-10-23Arne Goedeke  if (validate) {
b56cb92010-06-10Arne Goedeke  pop_stack(); } return p;
020b692014-10-23Arne Goedeke  } if (validate) {
b56cb92010-06-10Arne Goedeke  Pike_sp[-2].u.array = a = array_insert(a, &(Pike_sp[-1]), c); pop_stack(); } c++; fexec p;
a9deeb2010-06-10Arne Goedeke  } main := ('[' . myspace* . ( start: ( ']' -> final | value_start >parse_value . myspace* -> more ), more: ( ']' -> final | ',' . myspace* -> start ) ) %*{ fpc--; fbreak; }) ; }%%
a9e2ef2010-06-10Arne Goedeke static ptrdiff_t _parse_JSON_array(PCHARP str, ptrdiff_t p, ptrdiff_t pe, struct parser_state *state) {
25ebad2014-10-23Arne Goedeke  /* GCC complains about a being used uninitialized. This is clearly wrong, so * lets silence this warning */ struct array *a = a;
a9deeb2010-06-10Arne Goedeke  int cs; int c = 0;
020b692014-10-23Arne Goedeke  const int validate = !(state->flags&JSON_VALIDATE);
a9deeb2010-06-10Arne Goedeke  %% write data;
b56cb92010-06-10Arne Goedeke  /* Check stacks since we have uncontrolled recursion here. */ check_stack (10); check_c_stack (1024);
020b692014-10-23Arne Goedeke  if (validate) {
a9deeb2010-06-10Arne Goedeke  a = low_allocate_array(0,5);
b56cb92010-06-10Arne Goedeke  push_array(a);
a9deeb2010-06-10Arne Goedeke  } %% write init; %% write exec; if (cs >= JSON_array_first_final) { return p; }
a9e2ef2010-06-10Arne Goedeke  state->flags |= JSON_ERROR;
020b692014-10-23Arne Goedeke  if (validate) {
b56cb92010-06-10Arne Goedeke  pop_stack();
a9deeb2010-06-10Arne Goedeke  }
a9e2ef2010-06-10Arne Goedeke  return p;
a9deeb2010-06-10Arne Goedeke }