#include <ecoli_log.h>
#include <ecoli_strvec.h>
#include <ecoli_node.h>
+#include <ecoli_parsed.h>
+#include <ecoli_completed.h>
#include <ecoli_node_or.h>
#include <ecoli_node_str.h>
#include <ecoli_test.h>
unsigned int len;
};
-static struct ec_parsed *ec_node_or_parse(const struct ec_node *gen_node,
- const struct ec_strvec *strvec)
+static int
+ec_node_or_parse(const struct ec_node *gen_node,
+ struct ec_parsed *state,
+ const struct ec_strvec *strvec)
{
struct ec_node_or *node = (struct ec_node_or *)gen_node;
- struct ec_parsed *parsed, *child_parsed = NULL;
- struct ec_strvec *match_strvec;
unsigned int i;
-
- parsed = ec_parsed_new();
- if (parsed == NULL)
- goto fail;
+ int ret;
for (i = 0; i < node->len; i++) {
- child_parsed = ec_node_parse_strvec(node->table[i], strvec);
- if (child_parsed == NULL)
- goto fail;
- if (ec_parsed_matches(child_parsed))
- break;
- ec_parsed_free(child_parsed);
- child_parsed = NULL;
+ ret = ec_node_parse_child(node->table[i], state, strvec);
+ if (ret == EC_PARSED_NOMATCH)
+ continue;
+ return ret;
}
- /* no match */
- if (i == node->len)
- return parsed;
-
- match_strvec = ec_strvec_dup(child_parsed->strvec);
- if (match_strvec == NULL)
- goto fail;
-
- ec_parsed_set_match(parsed, gen_node, match_strvec);
- ec_parsed_add_child(parsed, child_parsed);
-
- return parsed;
-
- fail:
- ec_parsed_free(child_parsed);
- ec_parsed_free(parsed);
- return NULL;
+ return EC_PARSED_NOMATCH;
}
-static struct ec_completed *ec_node_or_complete(const struct ec_node *gen_node,
- const struct ec_strvec *strvec)
+static int
+ec_node_or_complete(const struct ec_node *gen_node,
+ struct ec_completed *completed,
+ struct ec_parsed *parsed,
+ const struct ec_strvec *strvec)
{
struct ec_node_or *node = (struct ec_node_or *)gen_node;
- struct ec_completed *completed, *child_completed;
+ int ret;
size_t n;
- completed = ec_completed_new();
- if (completed == NULL)
- return NULL;
-
for (n = 0; n < node->len; n++) {
- child_completed = ec_node_complete_strvec(node->table[n],
- strvec);
+ ret = ec_node_complete_child(node->table[n],
+ completed, parsed, strvec);
+ if (ret < 0)
+ return ret;
+ }
- if (child_completed == NULL) // XXX fail instead?
- continue;
+ return 0;
+}
- ec_completed_merge(completed, child_completed);
+static size_t ec_node_or_get_max_parse_len(const struct ec_node *gen_node)
+{
+ struct ec_node_or *node = (struct ec_node_or *)gen_node;
+ size_t i, ret = 0, len;
+
+ for (i = 0; i < node->len; i++) {
+ len = ec_node_get_max_parse_len(node->table[i]);
+ if (len > ret)
+ ret = len;
}
- return completed;
+ return ret;
}
static void ec_node_or_free_priv(struct ec_node *gen_node)
.name = "or",
.parse = ec_node_or_parse,
.complete = ec_node_or_complete,
+ .get_max_parse_len = ec_node_or_get_max_parse_len,
.size = sizeof(struct ec_node_or),
.free_priv = ec_node_or_free_priv,
};
va_start(ap, id);
- gen_node = __ec_node_new(&ec_node_or_type, id);
+ gen_node = __ec_node(&ec_node_or_type, id);
node = (struct ec_node_or *)gen_node;
if (node == NULL)
fail = 1;;
return NULL;
}
+/* LCOV_EXCL_START */
static int ec_node_or_testcase(void)
{
struct ec_node *node;
return ret;
}
+/* LCOV_EXCL_STOP */
static struct ec_test ec_node_or_test = {
.name = "node_or",