MCPcopy Create free account
hub / github.com/apache/cloudberry / parse_array

Function parse_array

src/common/jsonapi.c:470–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468}
469
470static JsonParseErrorType
471parse_array(JsonLexContext *lex, JsonSemAction *sem)
472{
473 /*
474 * an array is a possibly empty sequence of array elements, separated by
475 * commas and surrounded by square brackets.
476 */
477 json_struct_action astart = sem->array_start;
478 json_struct_action aend = sem->array_end;
479 JsonParseErrorType result;
480
481 check_stack_depth();
482
483 if (astart != NULL)
484 (*astart) (sem->semstate);
485
486 /*
487 * Data inside an array is at a higher nesting level than the array
488 * itself. Note that we increment this after we call the semantic routine
489 * for the array start and restore it before we call the routine for the
490 * array end.
491 */
492 lex->lex_level++;
493
494 result = lex_expect(JSON_PARSE_ARRAY_START, lex, JSON_TOKEN_ARRAY_START);
495 if (result == JSON_SUCCESS && lex_peek(lex) != JSON_TOKEN_ARRAY_END)
496 {
497 result = parse_array_element(lex, sem);
498
499 while (result == JSON_SUCCESS && lex_peek(lex) == JSON_TOKEN_COMMA)
500 {
501 result = json_lex(lex);
502 if (result != JSON_SUCCESS)
503 break;
504 result = parse_array_element(lex, sem);
505 }
506 }
507 if (result != JSON_SUCCESS)
508 return result;
509
510 result = lex_expect(JSON_PARSE_ARRAY_NEXT, lex, JSON_TOKEN_ARRAY_END);
511 if (result != JSON_SUCCESS)
512 return result;
513
514 lex->lex_level--;
515
516 if (aend != NULL)
517 (*aend) (sem->semstate);
518
519 return JSON_SUCCESS;
520}
521
522/*
523 * Lex one token from the input stream.

Callers 3

pg_parse_jsonFunction · 0.85
parse_object_fieldFunction · 0.85
parse_array_elementFunction · 0.85

Calls 5

check_stack_depthFunction · 0.85
lex_expectFunction · 0.85
lex_peekFunction · 0.85
parse_array_elementFunction · 0.85
json_lexFunction · 0.85

Tested by

no test coverage detected