use EC_NO_ID instead of NULL
[protos/libecoli.git] / lib / ecoli_node_re_lex.c
index c4d5104..d543178 100644 (file)
@@ -17,6 +17,8 @@
 #include <ecoli_node_int.h>
 #include <ecoli_node_re_lex.h>
 
+EC_LOG_TYPE_REGISTER(node_re_lex);
+
 struct regexp_pattern {
        char *pattern;
        regex_t r;
@@ -65,7 +67,7 @@ tokenize(struct regexp_pattern *table, size_t table_len, const char *str)
 
                        c = dup[pos.rm_eo + off];
                        dup[pos.rm_eo + off] = '\0';
-                       ec_log(EC_LOG_DEBUG, "re_lex match <%s>\n", &dup[off]);
+                       EC_LOG(EC_LOG_DEBUG, "re_lex match <%s>\n", &dup[off]);
                        if (ec_strvec_add(strvec, &dup[off]) < 0)
                                goto fail;
 
@@ -111,15 +113,16 @@ ec_node_re_lex_parse(const struct ec_node *gen_node,
        }
 
        ret = ec_node_parse_child(node->child, state, new_vec);
-       if (ret >= 0) {
-               if ((unsigned)ret == ec_strvec_len(new_vec)) {
-                       ret = 1;
-               } else {
-                       child_parsed = ec_parsed_get_last_child(state);
-                       ec_parsed_del_child(state, child_parsed);
-                       ec_parsed_free(child_parsed);
-                       ret = EC_PARSED_NOMATCH;
-               }
+       if (ret < 0)
+               goto fail;
+
+       if ((unsigned)ret == ec_strvec_len(new_vec)) {
+               ret = 1;
+       } else if (ret != EC_PARSED_NOMATCH) {
+               child_parsed = ec_parsed_get_last_child(state);
+               ec_parsed_del_child(state, child_parsed);
+               ec_parsed_free(child_parsed);
+               ret = EC_PARSED_NOMATCH;
        }
 
        ec_strvec_free(new_vec);
@@ -175,7 +178,7 @@ int ec_node_re_lex_add(struct ec_node *gen_node, const char *pattern, int keep)
 
        ret = regcomp(&table[node->len].r, pattern, REG_EXTENDED);
        if (ret != 0) {
-               ec_log(EC_LOG_ERR,
+               EC_LOG(EC_LOG_ERR,
                        "Regular expression <%s> compilation failed: %d\n",
                        pattern, ret);
                if (ret == REG_ESPACE)
@@ -216,23 +219,23 @@ struct ec_node *ec_node_re_lex(const char *id, struct ec_node *child)
        return &node->gen;
 }
 
-
+/* LCOV_EXCL_START */
 static int ec_node_re_lex_testcase(void)
 {
        struct ec_node *node;
        int ret = 0;
 
-       node = ec_node_re_lex(NULL,
-               ec_node_many(NULL,
-                       EC_NODE_OR(NULL,
-                               ec_node_str(NULL, "foo"),
-                               ec_node_str(NULL, "bar"),
-                               ec_node_int(NULL, 0, 1000, 0)
+       node = ec_node_re_lex(EC_NO_ID,
+               ec_node_many(EC_NO_ID,
+                       EC_NODE_OR(EC_NO_ID,
+                               ec_node_str(EC_NO_ID, "foo"),
+                               ec_node_str(EC_NO_ID, "bar"),
+                               ec_node_int(EC_NO_ID, 0, 1000, 0)
                        ), 0, 0
                )
        );
        if (node == NULL) {
-               ec_log(EC_LOG_ERR, "cannot create node\n");
+               EC_LOG(EC_LOG_ERR, "cannot create node\n");
                return -1;
        }
 
@@ -244,7 +247,7 @@ static int ec_node_re_lex_testcase(void)
        ret |= ec_node_re_lex_add(node, "\\+", 1);
        ret |= ec_node_re_lex_add(node, "[      ]+", 0);
        if (ret != 0) {
-               ec_log(EC_LOG_ERR, "cannot add regexp to node\n");
+               EC_LOG(EC_LOG_ERR, "cannot add regexp to node\n");
                ec_node_free(node);
                return -1;
        }
@@ -258,6 +261,7 @@ static int ec_node_re_lex_testcase(void)
 
        return ret;
 }
+/* LCOV_EXCL_STOP */
 
 static struct ec_test ec_node_re_lex_test = {
        .name = "node_re_lex",