save
[protos/libecoli.git] / lib / ecoli_node_cmd.c
index d1d2c7d..9a6c4eb 100644 (file)
@@ -38,6 +38,9 @@
 #include <ecoli_log.h>
 #include <ecoli_test.h>
 #include <ecoli_strvec.h>
+#include <ecoli_node.h>
+#include <ecoli_parsed.h>
+#include <ecoli_completed.h>
 #include <ecoli_node_expr.h>
 #include <ecoli_node_str.h>
 #include <ecoli_node_or.h>
@@ -271,9 +274,11 @@ static int ec_node_cmd_build(struct ec_node *gen_node)
        void *result;
        int ret;
 
+       /* XXX the expr parser can be moved in the node init */
+
        /* build the expression parser */
        ret = -ENOMEM;
-       expr = ec_node_new("expr", "expr");
+       expr = ec_node("expr", "expr");
        if (expr == NULL)
                goto fail;
        ret = ec_node_expr_set_val_node(expr, ec_node_re(NULL, "[a-zA-Z0-9]+"));
@@ -338,7 +343,7 @@ static int ec_node_cmd_build(struct ec_node *gen_node)
                goto fail;
 
        ret = -ENOMEM;
-       cmd = ec_node_new("seq", NULL);
+       cmd = ec_node("seq", NULL);
        if (cmd == NULL)
                goto fail;
 
@@ -352,6 +357,7 @@ static int ec_node_cmd_build(struct ec_node *gen_node)
                        goto fail;
        }
        ec_parsed_free(p);
+       p = NULL;
        ec_node_dump(stdout, cmd);
 
        ec_node_free(node->expr);
@@ -364,6 +370,7 @@ static int ec_node_cmd_build(struct ec_node *gen_node)
        return 0;
 
 fail:
+       ec_parsed_free(p);
        ec_node_free(expr);
        ec_node_free(lex);
        ec_node_free(cmd);
@@ -417,7 +424,7 @@ struct ec_node *ec_node_cmd(const char *id, const char *cmd_str)
        struct ec_node *gen_node = NULL;
        struct ec_node_cmd *node = NULL;
 
-       gen_node = __ec_node_new(&ec_node_cmd_type, id);
+       gen_node = __ec_node(&ec_node_cmd_type, id);
        if (gen_node == NULL)
                goto fail;
 
@@ -493,6 +500,15 @@ static int ec_node_cmd_testcase(void)
        ret |= EC_TEST_CHECK_PARSE(node, -1, "foo");
        ec_node_free(node);
 
+       node = EC_NODE_CMD(NULL, "good morning bob|bobby|michael [count]",
+                       ec_node_int("count", 0, 10, 10));
+       if (node == NULL) {
+               ec_log(EC_LOG_ERR, "cannot create node\n");
+               return -1;
+       }
+       ret |= EC_TEST_CHECK_PARSE(node, 4, "good", "morning", "bob", "1");
+       ec_node_free(node);
+
        // XXX completion
 
        return ret;