save
[protos/libecoli.git] / lib / ecoli_node_expr.c
index 8d2f698..cbc9441 100644 (file)
@@ -39,6 +39,8 @@
 #include <ecoli_test.h>
 #include <ecoli_strvec.h>
 #include <ecoli_node.h>
+#include <ecoli_parsed.h>
+#include <ecoli_completed.h>
 #include <ecoli_node_seq.h>
 #include <ecoli_node_many.h>
 #include <ecoli_node_or.h>
@@ -64,20 +66,22 @@ struct ec_node_expr {
        unsigned int paren_len;
 };
 
-static struct ec_parsed *ec_node_expr_parse(const struct ec_node *gen_node,
-       const struct ec_strvec *strvec)
+static int ec_node_expr_parse(const struct ec_node *gen_node,
+                       struct ec_parsed *state,
+                       const struct ec_strvec *strvec)
 {
        struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
 
-       return ec_node_parse_strvec(node->child, strvec);
+       return ec_node_parse_child(node->child, state, strvec);
 }
 
 static struct ec_completed *ec_node_expr_complete(const struct ec_node *gen_node,
-       const struct ec_strvec *strvec)
+                                               struct ec_parsed *state,
+                                               const struct ec_strvec *strvec)
 {
        struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
 
-       return ec_node_complete_strvec(node->child, strvec);
+       return ec_node_complete_child(node->child, state, strvec);
 }
 
 static void ec_node_expr_free_priv(struct ec_node *gen_node)
@@ -205,6 +209,7 @@ static int ec_node_expr_build(struct ec_node *gen_node)
        weak = NULL;
 
        node->child = expr;
+       ec_node_dump(stdout, node->child); //XXX
 
        return 0;
 
@@ -463,12 +468,15 @@ static int merge_results(void *userctx,
                return 0;
        }
 
-       if (x->has_val && x->op == NULL && y->has_val && y->op != NULL) {
-               ret = ops->eval_bin_op(&x->val, userctx, x->val, y->op, y->val);
-               if (ret < 0)
-                       return ret;
+       if (x->has_val && y->has_val && y->op != NULL) {
+               if (y->op_type == BIN_OP) {
+                       ret = ops->eval_bin_op(&x->val, userctx, x->val,
+                                       y->op, y->val);
+                       if (ret < 0)
+                               return ret;
 
-               return 0;
+                       return 0;
+               }
        }
 
        if (x->has_val == 0 && x->op != NULL && y->has_val && y->op == NULL) {
@@ -495,7 +503,7 @@ static int merge_results(void *userctx,
                return 0;
        }
 
-       assert(true); /* we should not get here */
+       assert(false); /* we should not get here */
        return -EINVAL;
 }