static struct buffer parse_argument(struct buffer buff, struct argument *arg, const char **error) { buff = chomp(buff); if ( isalpha((int)buff.data[buff.offset]) && !( peek(buff, "nil") || peek(buff, "true") || peek(buff, "false") || peek(buff, "b\"") || peek(buff, "b'") /* bin string prefix*/ ) ) { arg->type = AT_FUNCTION; buff = parse_method_call(buff, &arg->a.invocation, error); } else if (peek(buff, "{")) { arg->type = AT_FUNCTION; buff = parse_table(buff, &arg->a.invocation, error); } else { arg->type = AT_VALUE; buff = parse_value(buff, &arg->a.value, error); } return buff; }
void *libretrodb_query_compile(libretrodb_t *db, const char *query, size_t buff_len, const char **error) { struct buffer buff; struct query *q = (struct query*)malloc(sizeof(struct query)); if (!q) goto clean; memset(q, 0, sizeof(struct query)); q->ref_count = 1; buff.data = query; buff.len = buff_len; buff.offset = 0; *error = NULL; buff = chomp(buff); if (peek(buff, "{")) { buff = parse_table(buff, &q->root, error); if (*error) goto clean; } else if (isalpha(buff.data[buff.offset])) buff = parse_method_call(buff, &q->root, error); buff = expect_eof(buff, error); if (*error) goto clean; if (!q->root.func) { raise_unexpected_eof(buff.offset, error); return NULL; } goto success; clean: if (q) libretrodb_query_free(q); success: return q; }