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

Function report_parse_error

src/common/jsonapi.c:1015–1052  ·  view source on GitHub ↗

* Report a parse error. * * lex->token_start and lex->token_terminator must identify the current token. */

Source from the content-addressed store, hash-verified

1013 * lex->token_start and lex->token_terminator must identify the current token.
1014 */
1015static JsonParseErrorType
1016report_parse_error(JsonParseContext ctx, JsonLexContext *lex)
1017{
1018 /* Handle case where the input ended prematurely. */
1019 if (lex->token_start == NULL || lex->token_type == JSON_TOKEN_END)
1020 return JSON_EXPECTED_MORE;
1021
1022 /* Otherwise choose the error type based on the parsing context. */
1023 switch (ctx)
1024 {
1025 case JSON_PARSE_END:
1026 return JSON_EXPECTED_END;
1027 case JSON_PARSE_VALUE:
1028 return JSON_EXPECTED_JSON;
1029 case JSON_PARSE_STRING:
1030 return JSON_EXPECTED_STRING;
1031 case JSON_PARSE_ARRAY_START:
1032 return JSON_EXPECTED_ARRAY_FIRST;
1033 case JSON_PARSE_ARRAY_NEXT:
1034 return JSON_EXPECTED_ARRAY_NEXT;
1035 case JSON_PARSE_OBJECT_START:
1036 return JSON_EXPECTED_OBJECT_FIRST;
1037 case JSON_PARSE_OBJECT_LABEL:
1038 return JSON_EXPECTED_COLON;
1039 case JSON_PARSE_OBJECT_NEXT:
1040 return JSON_EXPECTED_OBJECT_NEXT;
1041 case JSON_PARSE_OBJECT_COMMA:
1042 return JSON_EXPECTED_STRING;
1043 }
1044
1045 /*
1046 * We don't use a default: case, so that the compiler will warn about
1047 * unhandled enum values. But this needs to be here anyway to cover the
1048 * possibility of an incorrect input.
1049 */
1050 json_log_and_abort("unexpected json parse state: %d", (int) ctx);
1051 return JSON_SUCCESS; /* silence stupider compilers */
1052}
1053
1054/*
1055 * Construct a detail message for a JSON error.

Callers 4

lex_expectFunction · 0.85
parse_scalarFunction · 0.85
parse_object_fieldFunction · 0.85
parse_objectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected