* 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.
*
/**
* 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
* 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);
/**
* 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);
/**
* 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);
*
*
*/
-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.
* 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.
*
*
*/
-const struct ec_parse *
+const struct ec_pnode *
ec_comp_group_get_state(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);
*
*
*/
-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