remove smallest start from completed struct
[protos/libecoli.git] / lib / ecoli_completed.h
index 5e5690b..d801c3e 100644 (file)
 struct ec_node;
 
 enum ec_completed_type {
-       EC_NO_MATCH = 1,
-       EC_MATCH = 2,
-       EC_PARTIAL = 4,
+       EC_NO_MATCH,
+       EC_MATCH,
+       EC_PARTIAL_MATCH,
 };
 
-struct ec_completed_item {
-       TAILQ_ENTRY(ec_completed_item) next;
+struct ec_completed_match {
+       TAILQ_ENTRY(ec_completed_match) next;
        enum ec_completed_type type;
        const struct ec_node *node;
        char *add;
 
-       /* reverse order: [0] = last parsed, [len-1] = root */
+       /* reverse order: [0] = last, [len-1] = root */
        const struct ec_node **path;
        size_t pathlen;
 };
 
-TAILQ_HEAD(ec_completed_item_list, ec_completed_item);
+TAILQ_HEAD(ec_completed_match_list, ec_completed_match);
+
+struct ec_completed_node {
+       TAILQ_ENTRY(ec_completed_node) next;
+       const struct ec_node *node;
+       struct ec_completed_match_list matches;
+};
+
+TAILQ_HEAD(ec_completed_node_list, ec_completed_node);
 
 struct ec_completed {
-       struct ec_completed_item_list items;
        unsigned count;
        unsigned count_match;
-       char *smallest_start;
+       struct ec_completed_node_list nodes;
 };
 
 /*
@@ -70,9 +77,10 @@ struct ec_completed *ec_node_complete_strvec(struct ec_node *node,
        const struct ec_strvec *strvec);
 
 /* internal: used by nodes */
-struct ec_completed *ec_node_complete_child(struct ec_node *node,
-                                       struct ec_parsed *state,
-                                       const struct ec_strvec *strvec);
+int ec_node_complete_child(struct ec_node *node,
+                       struct ec_completed *completed,
+                       struct ec_parsed *parsed_state,
+                       const struct ec_strvec *strvec);
 
 struct ec_completed *ec_completed(void);
 
@@ -80,21 +88,27 @@ int ec_completed_add_match(struct ec_completed *completed,
                        struct ec_parsed *state,
                        const struct ec_node *node, const char *add);
 int ec_completed_add_no_match(struct ec_completed *completed,
-                       struct ec_parsed *state, const struct ec_node *node);
+                       struct ec_parsed *parsed_state,
+                       const struct ec_node *node);
+int ec_completed_add_partial_match(struct ec_completed *completed,
+                       struct ec_parsed *state, const struct ec_node *node,
+                       const char *add);
 
-void ec_completed_item_free(struct ec_completed_item *item);
-void ec_completed_merge(struct ec_completed *completed1,
-       struct ec_completed *completed2);
+int ec_completed_add_node(struct ec_completed *completed,
+                       const struct ec_node *node);
+
+void ec_completed_match_free(struct ec_completed_match *item);
 void ec_completed_free(struct ec_completed *completed);
 void ec_completed_dump(FILE *out,
        const struct ec_completed *completed);
-struct ec_completed *ec_node_default_complete(const struct ec_node *gen_node,
-                                       struct ec_parsed *state,
-                                       const struct ec_strvec *strvec);
+int
+ec_node_default_complete(const struct ec_node *gen_node,
+                       struct ec_completed *completed,
+                       struct ec_parsed *state,
+                       const struct ec_strvec *strvec);
 
-/* cannot return NULL */
-const char *ec_completed_smallest_start(
-       const struct ec_completed *completed);
+/* return the smallest string start, or NULL on error */
+char *ec_completed_smallest_start(const struct ec_completed *completed);
 
 unsigned int ec_completed_count(
        const struct ec_completed *completed,
@@ -103,14 +117,15 @@ unsigned int ec_completed_count(
 struct ec_completed_iter {
        enum ec_completed_type type;
        const struct ec_completed *completed;
-       const struct ec_completed_item *cur;
+       const struct ec_completed_node *cur_node;
+       const struct ec_completed_match *cur_match;
 };
 
 struct ec_completed_iter *
 ec_completed_iter(struct ec_completed *completed,
        enum ec_completed_type type);
 
-const struct ec_completed_item *ec_completed_iter_next(
+const struct ec_completed_match *ec_completed_iter_next(
        struct ec_completed_iter *iter);
 
 void ec_completed_iter_free(struct ec_completed_iter *iter);