max parse len
[protos/libecoli.git] / lib / ecoli_node_or.c
index a4df91f..dcd811b 100644 (file)
@@ -48,49 +48,29 @@ struct ec_node_or {
        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();
-       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 struct ec_completed *
+ec_node_or_complete(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_completed *completed, *child_completed;
@@ -101,8 +81,8 @@ static struct ec_completed *ec_node_or_complete(const struct ec_node *gen_node,
                return NULL;
 
        for (n = 0; n < node->len; n++) {
-               child_completed = ec_node_complete_strvec(node->table[n],
-                       strvec);
+               child_completed = ec_node_complete_child(node->table[n],
+                       state, strvec);
 
                if (child_completed == NULL) // XXX fail instead?
                        continue;
@@ -113,6 +93,20 @@ static struct ec_completed *ec_node_or_complete(const struct ec_node *gen_node,
        return 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 ret;
+}
+
 static void ec_node_or_free_priv(struct ec_node *gen_node)
 {
        struct ec_node_or *node = (struct ec_node_or *)gen_node;
@@ -155,6 +149,7 @@ static struct ec_node_type ec_node_or_type = {
        .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,
 };
@@ -200,6 +195,7 @@ fail:
        return NULL;
 }
 
+/* LCOV_EXCL_START */
 static int ec_node_or_testcase(void)
 {
        struct ec_node *node;
@@ -266,6 +262,7 @@ static int ec_node_or_testcase(void)
 
        return ret;
 }
+/* LCOV_EXCL_STOP */
 
 static struct ec_test ec_node_or_test = {
        .name = "node_or",