#include <ecoli_log.h>
#include <ecoli_strvec.h>
#include <ecoli_node.h>
-#include <ecoli_parsed.h>
-#include <ecoli_completed.h>
+#include <ecoli_parse.h>
+#include <ecoli_complete.h>
#include <ecoli_node_or.h>
#include <ecoli_node_str.h>
#include <ecoli_test.h>
static int
ec_node_or_parse(const struct ec_node *gen_node,
- struct ec_parsed *state,
+ struct ec_parse *state,
const struct ec_strvec *strvec)
{
struct ec_node_or *node = (struct ec_node_or *)gen_node;
for (i = 0; i < node->len; i++) {
ret = ec_node_parse_child(node->table[i], state, strvec);
- if (ret == EC_PARSED_NOMATCH)
+ if (ret == EC_PARSE_NOMATCH)
continue;
return ret;
}
- return EC_PARSED_NOMATCH;
+ return EC_PARSE_NOMATCH;
}
static int
ec_node_or_complete(const struct ec_node *gen_node,
- struct ec_completed *completed,
+ struct ec_comp *comp,
const struct ec_strvec *strvec)
{
struct ec_node_or *node = (struct ec_node_or *)gen_node;
for (n = 0; n < node->len; n++) {
ret = ec_node_complete_child(node->table[n],
- completed, strvec);
+ comp, strvec);
if (ret < 0)
return ret;
}
static void ec_node_or_free_priv(struct ec_node *gen_node)
{
struct ec_node_or *node = (struct ec_node_or *)gen_node;
- unsigned int i;
+ size_t i;
for (i = 0; i < node->len; i++)
ec_node_free(node->table[i]);
ec_free(node->table);
}
+static size_t
+ec_node_or_get_children_count(const struct ec_node *gen_node)
+{
+ struct ec_node_or *node = (struct ec_node_or *)gen_node;
+ return node->len;
+}
+
+static int
+ec_node_or_get_child(const struct ec_node *gen_node, size_t i,
+ struct ec_node **child, unsigned int *refs)
+{
+ struct ec_node_or *node = (struct ec_node_or *)gen_node;
+
+ if (i >= node->len)
+ return -1;
+
+ *child = node->table[i];
+ *refs = 1;
+ return 0;
+}
+
static struct ec_node_type ec_node_or_type = {
.name = "or",
.parse = ec_node_or_parse,
.complete = ec_node_or_complete,
.size = sizeof(struct ec_node_or),
.free_priv = ec_node_or_free_priv,
+ .get_children_count = ec_node_or_get_children_count,
+ .get_child = ec_node_or_get_child,
};
EC_NODE_TYPE_REGISTER(ec_node_or_type);
goto fail;
node->table = table;
-
- if (ec_node_add_child(gen_node, child) < 0)
- goto fail;
-
table[node->len] = child;
node->len++;