Parse a value literal: string, number, ident[.prop], true, false. Returns heap-allocated. */
| 1369 | |
| 1370 | /* Parse a value literal: string, number, ident[.prop], true, false. Returns heap-allocated. */ |
| 1371 | static const char *parse_value_literal(parser_t *p) { |
| 1372 | if (check(p, TOK_STRING) || check(p, TOK_NUMBER)) { |
| 1373 | return heap_strdup(advance(p)->text); |
| 1374 | } |
| 1375 | if (check(p, TOK_IDENT)) { |
| 1376 | char buf[CBM_SZ_256]; |
| 1377 | const cbm_token_t *v = advance(p); |
| 1378 | if (match(p, TOK_DOT)) { |
| 1379 | const cbm_token_t *pr = expect(p, TOK_IDENT); |
| 1380 | snprintf(buf, sizeof(buf), "%s.%s", v->text, pr ? pr->text : ""); |
| 1381 | } else { |
| 1382 | snprintf(buf, sizeof(buf), "%s", v->text); |
| 1383 | } |
| 1384 | return heap_strdup(buf); |
| 1385 | } |
| 1386 | if (check(p, TOK_TRUE)) { |
| 1387 | advance(p); |
| 1388 | return heap_strdup("true"); |
| 1389 | } |
| 1390 | if (check(p, TOK_FALSE)) { |
| 1391 | advance(p); |
| 1392 | return heap_strdup("false"); |
| 1393 | } |
| 1394 | return NULL; |
| 1395 | } |
| 1396 | |
| 1397 | /* Parse CASE WHEN ... THEN ... [ELSE ...] END */ |
| 1398 | static cbm_case_expr_t *parse_case_expr(parser_t *p) { |
no test coverage detected