Parse the operator + value tail shared by every condition subject * (var[.prop] and multi-arg functions like coalesce(...)): IS [NOT] NULL, * IN [...], or a comparison operator with a literal value. */
| 1085 | * (var[.prop] and multi-arg functions like coalesce(...)): IS [NOT] NULL, |
| 1086 | * IN [...], or a comparison operator with a literal value. */ |
| 1087 | static cbm_expr_t *parse_condition_op(parser_t *p, cbm_condition_t *c) { |
| 1088 | /* IS NULL / IS NOT NULL */ |
| 1089 | if (check(p, TOK_IS)) { |
| 1090 | advance(p); |
| 1091 | if (match(p, TOK_NOT)) { |
| 1092 | c->op = heap_strdup("IS NOT NULL"); |
| 1093 | expect(p, TOK_NULL_KW); |
| 1094 | } else { |
| 1095 | expect(p, TOK_NULL_KW); |
| 1096 | c->op = heap_strdup("IS NULL"); |
| 1097 | } |
| 1098 | return expr_leaf(*c); |
| 1099 | } |
| 1100 | |
| 1101 | /* IN [...] */ |
| 1102 | if (check(p, TOK_IN)) { |
| 1103 | cbm_expr_t *e = parse_in_list(p, c); |
| 1104 | if (!e) { |
| 1105 | cond_func_fields_free(c); |
| 1106 | } |
| 1107 | return e; |
| 1108 | } |
| 1109 | |
| 1110 | /* Standard operators */ |
| 1111 | c->op = parse_comparison_op(p); |
| 1112 | if (!c->op) { |
| 1113 | snprintf(p->error, sizeof(p->error), "unexpected operator at pos %d", peek(p)->pos); |
| 1114 | cond_func_fields_free(c); |
| 1115 | safe_str_free(&c->variable); |
| 1116 | safe_str_free(&c->property); |
| 1117 | safe_str_free(&c->coalesce_default); |
| 1118 | return NULL; |
| 1119 | } |
| 1120 | |
| 1121 | /* Value */ |
| 1122 | if (check(p, TOK_STRING) || check(p, TOK_NUMBER)) { |
| 1123 | c->value = heap_strdup(advance(p)->text); |
| 1124 | } else if (check(p, TOK_TRUE)) { |
| 1125 | advance(p); |
| 1126 | c->value = heap_strdup("true"); |
| 1127 | } else if (check(p, TOK_FALSE)) { |
| 1128 | advance(p); |
| 1129 | c->value = heap_strdup("false"); |
| 1130 | } else { |
| 1131 | snprintf(p->error, sizeof(p->error), "expected value at pos %d", peek(p)->pos); |
| 1132 | cond_func_fields_free(c); |
| 1133 | safe_str_free(&c->variable); |
| 1134 | safe_str_free(&c->property); |
| 1135 | safe_str_free(&c->op); |
| 1136 | safe_str_free(&c->coalesce_default); |
| 1137 | return NULL; |
| 1138 | } |
| 1139 | |
| 1140 | return expr_leaf(*c); |
| 1141 | } |
| 1142 | |
| 1143 | /* parse_condition_lhs result: the label-test form is a complete condition. */ |
| 1144 | enum { COND_LHS_COMPLETE = 1 }; |
no test coverage detected