save
[protos/libecoli.git] / lib / ecoli_parsed.h
index 83ace08..637059a 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <sys/queue.h>
 #include <sys/types.h>
+#include <limits.h>
 #include <stdio.h>
 
 struct ec_node;
@@ -42,6 +43,7 @@ TAILQ_HEAD(ec_parsed_list, ec_parsed);
 struct ec_parsed {
        TAILQ_ENTRY(ec_parsed) next;
        struct ec_parsed_list children;
+       struct ec_parsed *parent;
        const struct ec_node *node;
        struct ec_strvec *strvec;
 };
@@ -50,11 +52,7 @@ struct ec_parsed *ec_parsed(void);
 void ec_parsed_free(struct ec_parsed *parsed);
 void ec_parsed_free_children(struct ec_parsed *parsed);
 
-const struct ec_strvec *ec_parsed_strvec(
-       const struct ec_parsed *parsed);
-
-void ec_parsed_set_match(struct ec_parsed *parsed,
-       const struct ec_node *node, struct ec_strvec *strvec);
+const struct ec_strvec *ec_parsed_strvec(const struct ec_parsed *parsed);
 
 /* XXX we could use a cache to store possible completions or match: the
  * cache would be per-node, and would be reset for each call to parse()
@@ -64,22 +62,46 @@ void ec_parsed_set_match(struct ec_parsed *parsed,
 */
 struct ec_parsed *ec_node_parse(struct ec_node *node, const char *str);
 
-/* mostly internal to nodes */
-/* XXX it should not reset cache
- * ... not sure... it is used by tests */
 struct ec_parsed *ec_node_parse_strvec(struct ec_node *node,
-       const struct ec_strvec *strvec);
+                               const struct ec_strvec *strvec);
+
+#define EC_PARSED_NOMATCH INT_MIN
+/* internal: used by nodes
+ *
+ * state is the current parse tree, which is built bit by bit while
+ *   parsing the node tree: ec_node_parse_child() creates a new child in
+ *   this state parse tree, and calls the parse() method for the child
+ *   node, with state pointing to this new child. If it does not match,
+ *   the child is removed in the state, else it is kept, with its
+ *   possible descendants.
+ *
+ * return:
+ * XXX change EC_PARSED_NOMATCH to INT_MAX?
+ * EC_PARSED_NOMATCH (negative) if it does not match
+ * any other negative value (-errno) for other errors
+ * the number of matched strings in strvec
+ * XXX state is not freed on error ?
+ */
+int ec_node_parse_child(struct ec_node *node,
+                       struct ec_parsed *state,
+                       const struct ec_strvec *strvec);
 
 void ec_parsed_add_child(struct ec_parsed *parsed,
-       struct ec_parsed *child);
+                       struct ec_parsed *child);
 void ec_parsed_del_child(struct ec_parsed *parsed,
-       struct ec_parsed *child);
+                       struct ec_parsed *child);
+
+struct ec_parsed *ec_parsed_get_root(struct ec_parsed *parsed);
+struct ec_parsed *ec_parsed_get_parent(struct ec_parsed *parsed);
+struct ec_parsed *ec_parsed_get_last_child(struct ec_parsed *parsed);
+void ec_parsed_del_last_child(struct ec_parsed *parsed);
+int ec_parsed_get_path(struct ec_parsed *parsed, struct ec_node **path);
+
 void ec_parsed_dump(FILE *out, const struct ec_parsed *parsed);
 
 struct ec_parsed *ec_parsed_find_first(struct ec_parsed *parsed,
        const char *id);
 
-const char *ec_parsed_to_string(const struct ec_parsed *parsed);
 size_t ec_parsed_len(const struct ec_parsed *parsed);
 size_t ec_parsed_matches(const struct ec_parsed *parsed);