| 314 | } |
| 315 | |
| 316 | static JsonParseErrorType |
| 317 | parse_object_field(JsonLexContext *lex, JsonSemAction *sem) |
| 318 | { |
| 319 | /* |
| 320 | * An object field is "fieldname" : value where value can be a scalar, |
| 321 | * object or array. Note: in user-facing docs and error messages, we |
| 322 | * generally call a field name a "key". |
| 323 | */ |
| 324 | |
| 325 | char *fname = NULL; /* keep compiler quiet */ |
| 326 | json_ofield_action ostart = sem->object_field_start; |
| 327 | json_ofield_action oend = sem->object_field_end; |
| 328 | bool isnull; |
| 329 | JsonTokenType tok; |
| 330 | JsonParseErrorType result; |
| 331 | |
| 332 | if (lex_peek(lex) != JSON_TOKEN_STRING) |
| 333 | return report_parse_error(JSON_PARSE_STRING, lex); |
| 334 | if ((ostart != NULL || oend != NULL) && lex->strval != NULL) |
| 335 | fname = pstrdup(lex->strval->data); |
| 336 | result = json_lex(lex); |
| 337 | if (result != JSON_SUCCESS) |
| 338 | return result; |
| 339 | |
| 340 | result = lex_expect(JSON_PARSE_OBJECT_LABEL, lex, JSON_TOKEN_COLON); |
| 341 | if (result != JSON_SUCCESS) |
| 342 | return result; |
| 343 | |
| 344 | tok = lex_peek(lex); |
| 345 | isnull = tok == JSON_TOKEN_NULL; |
| 346 | |
| 347 | if (ostart != NULL) |
| 348 | (*ostart) (sem->semstate, fname, isnull); |
| 349 | |
| 350 | switch (tok) |
| 351 | { |
| 352 | case JSON_TOKEN_OBJECT_START: |
| 353 | result = parse_object(lex, sem); |
| 354 | break; |
| 355 | case JSON_TOKEN_ARRAY_START: |
| 356 | result = parse_array(lex, sem); |
| 357 | break; |
| 358 | default: |
| 359 | result = parse_scalar(lex, sem); |
| 360 | } |
| 361 | if (result != JSON_SUCCESS) |
| 362 | return result; |
| 363 | |
| 364 | if (oend != NULL) |
| 365 | (*oend) (sem->semstate, fname, isnull); |
| 366 | return JSON_SUCCESS; |
| 367 | } |
| 368 | |
| 369 | static JsonParseErrorType |
| 370 | parse_object(JsonLexContext *lex, JsonSemAction *sem) |
no test coverage detected