| 340 | } |
| 341 | |
| 342 | JSONValue json_parse_value2(const char **pp) |
| 343 | { |
| 344 | char buf[128]; |
| 345 | const char *p; |
| 346 | JSONValue val, val1, tag; |
| 347 | |
| 348 | p = *pp; |
| 349 | skip_spaces(&p); |
| 350 | if (*p == '\0') { |
| 351 | return json_error_new("unexpected end of file"); |
| 352 | } |
| 353 | if (isdigit(*p)) { |
| 354 | val = json_int32_new(strtol(p, (char **)&p, 0)); |
| 355 | } else if (*p == '"') { |
| 356 | val = parse_string(&p); |
| 357 | } else if (*p == '{') { |
| 358 | p++; |
| 359 | val = json_object_new(); |
| 360 | for(;;) { |
| 361 | skip_spaces(&p); |
| 362 | if (*p == '}') { |
| 363 | p++; |
| 364 | break; |
| 365 | } |
| 366 | if (*p == '"') { |
| 367 | tag = parse_string(&p); |
| 368 | if (json_is_error(tag)) |
| 369 | return tag; |
| 370 | } else if (is_ident_first(*p)) { |
| 371 | if (parse_ident(buf, sizeof(buf), &p) < 0) |
| 372 | goto invalid_prop; |
| 373 | tag = json_string_new(buf); |
| 374 | } else { |
| 375 | goto invalid_prop; |
| 376 | } |
| 377 | // printf("property: %s\n", json_get_str(tag)); |
| 378 | if (tag.u.str->len == 0) { |
| 379 | invalid_prop: |
| 380 | return json_error_new("Invalid property name"); |
| 381 | } |
| 382 | skip_spaces(&p); |
| 383 | if (*p != ':') { |
| 384 | return json_error_new("':' expected"); |
| 385 | } |
| 386 | p++; |
| 387 | |
| 388 | val1 = json_parse_value2(&p); |
| 389 | json_object_set(val, tag.u.str->data, val1); |
| 390 | |
| 391 | skip_spaces(&p); |
| 392 | if (*p == ',') { |
| 393 | p++; |
| 394 | } else if (*p != '}') { |
| 395 | return json_error_new("expecting ',' or '}'"); |
| 396 | } |
| 397 | } |
| 398 | } else if (*p == '[') { |
| 399 | int idx; |
no test coverage detected