save
[protos/libecoli.git] / lib / ecoli_node_re.c
index d5c9b49..5bcc407 100644 (file)
@@ -36,6 +36,8 @@
 #include <ecoli_test.h>
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
+#include <ecoli_parsed.h>
+#include <ecoli_completed.h>
 #include <ecoli_node_re.h>
 
 struct ec_node_re {
@@ -44,39 +46,33 @@ struct ec_node_re {
        regex_t re;
 };
 
-static struct ec_parsed *ec_node_re_parse(const struct ec_node *gen_node,
-       const struct ec_strvec *strvec)
+static int
+ec_node_re_parse(const struct ec_node *gen_node,
+               struct ec_parsed *state,
+               const struct ec_strvec *strvec)
 {
        struct ec_node_re *node = (struct ec_node_re *)gen_node;
-       struct ec_strvec *match_strvec;
-       struct ec_parsed *parsed = NULL;
        const char *str;
        regmatch_t pos;
 
-       parsed = ec_parsed_new();
-       if (parsed == NULL)
-               goto fail;
+       (void)state;
 
        if (ec_strvec_len(strvec) == 0)
-               return parsed;
+               return EC_PARSED_NOMATCH;
 
        str = ec_strvec_val(strvec, 0);
        if (regexec(&node->re, str, 1, &pos, 0) != 0)
-               return parsed;
+               return EC_PARSED_NOMATCH;
        if (pos.rm_so != 0 || pos.rm_eo != (int)strlen(str))
-               return parsed;
-
-       match_strvec = ec_strvec_ndup(strvec, 0, 1);
-       if (match_strvec == NULL)
-               goto fail;
-
-       ec_parsed_set_match(parsed, gen_node, match_strvec);
+               return EC_PARSED_NOMATCH;
 
-       return parsed;
+       return 1;
+}
 
- fail:
-       ec_parsed_free(parsed);
-       return NULL;
+static size_t ec_node_re_get_max_parse_len(const struct ec_node *gen_node)
+{
+       (void)gen_node;
+       return 1;
 }
 
 static void ec_node_re_free_priv(struct ec_node *gen_node)
@@ -91,6 +87,7 @@ static struct ec_node_type ec_node_re_type = {
        .name = "re",
        .parse = ec_node_re_parse,
        .complete = ec_node_default_complete,
+       .get_max_parse_len = ec_node_re_get_max_parse_len,
        .size = sizeof(struct ec_node_re),
        .free_priv = ec_node_re_free_priv,
 };
@@ -127,7 +124,7 @@ struct ec_node *ec_node_re(const char *id, const char *re_str)
 {
        struct ec_node *gen_node = NULL;
 
-       gen_node = __ec_node_new(&ec_node_re_type, id);
+       gen_node = __ec_node(&ec_node_re_type, id);
        if (gen_node == NULL)
                goto fail;
 
@@ -141,6 +138,7 @@ fail:
        return NULL;
 }
 
+/* LCOV_EXCL_START */
 static int ec_node_re_testcase(void)
 {
        struct ec_node *node;
@@ -161,6 +159,7 @@ static int ec_node_re_testcase(void)
 
        return ret;
 }
+/* LCOV_EXCL_STOP */
 
 static struct ec_test ec_node_re_test = {
        .name = "node_re",