#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>
ec_node_free(in2);
*result = out;
} else if (!strcmp(ec_strvec_val(vec, 0), ",")) {
- out = EC_NODE_SUBSET(NULL, ec_node_clone(in1), ec_node_clone(in2));
- if (out == NULL)
- return -EINVAL;
- ec_node_free(in1);
- ec_node_free(in2);
- *result = out;
+ if (!strcmp(in2->type->name, "subset")) {
+ if (ec_node_subset_add(in2, ec_node_clone(in1)) < 0)
+ return -EINVAL;
+ ec_node_free(in1);
+ *result = in2;
+ } else {
+ out = EC_NODE_SUBSET(NULL, ec_node_clone(in1),
+ ec_node_clone(in2));
+ if (out == NULL)
+ return -EINVAL;
+ ec_node_free(in1);
+ ec_node_free(in2);
+ *result = out;
+ }
} else {
return -EINVAL;
}
+ printf("eval bin_op out %p\n", *result);
+
return 0;
}
.eval_free = ec_node_cmd_eval_free,
};
-static struct ec_parsed *ec_node_cmd_parse(const struct ec_node *gen_node,
- const struct ec_strvec *strvec)
+static int
+ec_node_cmd_parse(const struct ec_node *gen_node, struct ec_parsed *state,
+ const struct ec_strvec *strvec)
{
struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
- return ec_node_parse_strvec(node->cmd, strvec);
+ return ec_node_parse_child(node->cmd, state, strvec);
}
-static struct ec_completed *ec_node_cmd_complete(const struct ec_node *gen_node,
- const struct ec_strvec *strvec)
+static int
+ec_node_cmd_complete(const struct ec_node *gen_node,
+ struct ec_completed *completed,
+ struct ec_parsed *parsed,
+ const struct ec_strvec *strvec)
{
struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
- return ec_node_complete_strvec(node->cmd, strvec);
+ return ec_node_complete_child(node->cmd, completed, parsed, strvec);
}
static void ec_node_cmd_free_priv(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("expr", "expr");
goto fail;
}
ec_parsed_free(p);
+ p = NULL;
ec_node_dump(stdout, cmd);
ec_node_free(node->expr);
return 0;
fail:
+ ec_parsed_free(p);
ec_node_free(expr);
ec_node_free(lex);
ec_node_free(cmd);
return NULL;
}
+/* LCOV_EXCL_START */
static int ec_node_cmd_testcase(void)
{
struct ec_node *node;
int ret = 0;
node = EC_NODE_CMD(NULL,
- "command [option] (subset1, subset2) x | y",
+ "command [option] (subset1, subset2, subset3) x|y",
ec_node_int("x", 0, 10, 10),
ec_node_int("y", 20, 30, 10)
);
ret |= EC_TEST_CHECK_PARSE(node, -1, "foo");
ec_node_free(node);
- // XXX completion
+ node = EC_NODE_CMD(NULL, "good morning [count] bob|bobby|michael",
+ 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", "1", "bob");
+
+ ret |= EC_TEST_CHECK_COMPLETE(node,
+ "", EC_NODE_ENDLIST,
+ "good", EC_NODE_ENDLIST,
+ "good");
+ ret |= EC_TEST_CHECK_COMPLETE(node,
+ "g", EC_NODE_ENDLIST,
+ "ood", EC_NODE_ENDLIST,
+ "ood");
+ ret |= EC_TEST_CHECK_COMPLETE(node,
+ "good", "morning", "", EC_NODE_ENDLIST,
+ "bob", "bobby", "michael", EC_NODE_ENDLIST,
+ "");
+
+ ec_node_free(node);
return ret;
}
+/* LCOV_EXCL_STOP */
static struct ec_test ec_node_cmd_test = {
.name = "node_cmd",