* pg_parse_json * * Publicly visible entry point for the JSON parser. * * lex is a lexing context, set up for the json to be processed by calling * makeJsonLexContext(). sem is a structure of function pointers to semantic * action routines to be called at appropriate spots during parsing, and a * pointer to a state object to be passed to those routines. */
| 176 | * pointer to a state object to be passed to those routines. |
| 177 | */ |
| 178 | JsonParseErrorType |
| 179 | pg_parse_json(JsonLexContext *lex, JsonSemAction *sem) |
| 180 | { |
| 181 | JsonTokenType tok; |
| 182 | JsonParseErrorType result; |
| 183 | |
| 184 | /* get the initial token */ |
| 185 | result = json_lex(lex); |
| 186 | if (result != JSON_SUCCESS) |
| 187 | return result; |
| 188 | |
| 189 | tok = lex_peek(lex); |
| 190 | |
| 191 | /* parse by recursive descent */ |
| 192 | switch (tok) |
| 193 | { |
| 194 | case JSON_TOKEN_OBJECT_START: |
| 195 | result = parse_object(lex, sem); |
| 196 | break; |
| 197 | case JSON_TOKEN_ARRAY_START: |
| 198 | result = parse_array(lex, sem); |
| 199 | break; |
| 200 | default: |
| 201 | result = parse_scalar(lex, sem); /* json can be a bare scalar */ |
| 202 | } |
| 203 | |
| 204 | if (result == JSON_SUCCESS) |
| 205 | result = lex_expect(JSON_PARSE_END, lex, JSON_TOKEN_END); |
| 206 | |
| 207 | return result; |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * json_count_array_elements |
no test coverage detected