rework completion iterators
[protos/libecoli.git] / include / ecoli_complete.h
index b2df5e1..c36019a 100644 (file)
@@ -11,9 +11,9 @@
  * This file provide helpers to list and manipulate the possible
  * completions for a given input.
  *
- * Use @ec_node_complete_strvec() to complete a vector of strings when
+ * Use @ec_complete_strvec() to complete a vector of strings when
  * the input is already split into several tokens. You can use
- * @ec_node_complete() if you know that the size of the vector is
+ * @ec_complete() if you know that the size of the vector is
  * 1. This is common if you grammar tree has a lexer that will tokenize
  * the input.
  *
@@ -50,7 +50,7 @@ enum ec_comp_type {
 /**
  * Get the list of completions from a string input.
  *
- * It is equivalent that calling @ec_node_complete_strvec() with a
+ * It is equivalent that calling @ec_complete_strvec() with a
  * vector that only contains 1 element, the input string. Using this
  * function is often more convenient if you get your input from a
  * buffer, because you won't have to create a vector. Usually, it means
@@ -66,7 +66,7 @@ enum ec_comp_type {
  *   A pointer to the completion list on success, or NULL
  *   on error (errno is set).
  */
-struct ec_comp *ec_node_complete(const struct ec_node *node,
+struct ec_comp *ec_complete(const struct ec_node *node,
        const char *str);
 
 /**
@@ -93,7 +93,7 @@ struct ec_comp *ec_node_complete(const struct ec_node *node,
  *   A pointer to the completion list on success, or NULL
  *   on error (errno is set).
  */
-struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
+struct ec_comp *ec_complete_strvec(const struct ec_node *node,
        const struct ec_strvec *strvec);
 
 /**
@@ -102,7 +102,7 @@ struct ec_comp *ec_node_complete_strvec(const struct ec_node *node,
  * This function is to be used by ecoli nodes.
  *
  */
-int ec_node_complete_child(const struct ec_node *node,
+int ec_complete_child(const struct ec_node *node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec);
 
@@ -111,7 +111,7 @@ int ec_node_complete_child(const struct ec_node *node,
  *
  *
  */
-struct ec_comp *ec_comp(struct ec_parse *state);
+struct ec_comp *ec_comp(struct ec_pnode *state);
 
 /**
  * Free a completion object and all its items.
@@ -140,7 +140,7 @@ int ec_comp_merge(struct ec_comp *to,
  * Get current completion state.
  *
  */
-struct ec_parse *ec_comp_get_state(const struct ec_comp *comp);
+struct ec_pnode *ec_comp_get_state(const struct ec_comp *comp);
 
 /**
  * Get current completion group.
@@ -244,7 +244,7 @@ ec_comp_group_get_node(const struct ec_comp_group *grp);
  *
  *
  */
-const struct ec_parse *
+const struct ec_pnode *
 ec_comp_group_get_state(const struct ec_comp_group *grp);
 
 /**
@@ -262,7 +262,7 @@ ec_comp_group_get_attrs(const struct ec_comp_group *grp);
  *
  */
 int
-ec_node_complete_unknown(const struct ec_node *gen_node,
+ec_complete_unknown(const struct ec_node *gen_node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec);
 
@@ -280,36 +280,53 @@ unsigned int ec_comp_count(
  *
  *
  */
-struct ec_comp_iter {
-       enum ec_comp_type type;
-       const struct ec_comp *comp;
-       struct ec_comp_group *cur_node;
-       struct ec_comp_item *cur_match;
-};
 
 /**
+ * Get the first completion item matching the type.
  *
+ * Also see EC_COMP_FOREACH().
  *
- *
+ * @param comp
+ *   The completion list.
+ * @param type
+ *   A logical OR of flags among EC_COMP_UNKNOWN, EC_COMP_PARTIAL and
+ *   EC_COMP_FULL, to select the type to iterate.
+ * @return
+ *   A completion item.
  */
-struct ec_comp_iter *
-ec_comp_iter(const struct ec_comp *comp,
-       enum ec_comp_type type);
+struct ec_comp_item *
+ec_comp_iter_first(const struct ec_comp *comp, enum ec_comp_type type);
 
 /**
+ * Get the first completion item matching the type.
  *
+ * Also see EC_COMP_FOREACH().
  *
- *
+ * @param comp
+ *   The completion list.
+ * @param type
+ *   A logical OR of flags among EC_COMP_UNKNOWN, EC_COMP_PARTIAL and
+ *   EC_COMP_FULL, to select the type to iterate.
+ * @return
+ *   A completion item.
  */
-struct ec_comp_item *ec_comp_iter_next(
-       struct ec_comp_iter *iter);
+struct ec_comp_item *
+ec_comp_iter_next(struct ec_comp_item *item, enum ec_comp_type type);
 
 /**
- *
- *
- *
+ * Iterate items matching a given type.
+ *
+ * @param item
+ *   The item that will be set at each iteration.
+ * @param comp
+ *   The completion list.
+ * @param type
+ *   A logical OR of flags among EC_COMP_UNKNOWN, EC_COMP_PARTIAL and
+ *   EC_COMP_FULL, to select the type to iterate.
  */
-void ec_comp_iter_free(struct ec_comp_iter *iter);
-
+#define EC_COMP_FOREACH(item, comp, type)              \
+       for (item = ec_comp_iter_first(comp, type);     \
+            item != NULL;                              \
+            item = ec_comp_iter_next(item, type))
 
 #endif