14enum bool_tuple_state {
27static const char *parse_bool_tuple(
const char *input,
enum bool_tuple_state *state)
86static int ec_node_bool_tuple_parse(
92 enum bool_tuple_state state;
102 parse_bool_tuple(input, &state);
110static int ec_node_bool_tuple_complete(
116 struct ec_comp_item *item = NULL;
117 const char *false_str =
"false";
118 const char *true_str =
"true";
119 enum bool_tuple_state state;
120 char *comp_str = NULL;
121 char *disp_str = NULL;
122 const char *incomplete;
130 incomplete = parse_bool_tuple(input, &state);
134 if (asprintf(&comp_str,
"%s(", input) < 0)
136 if (asprintf(&disp_str,
"(") < 0)
145 if (incomplete[0] ==
'\0') {
146 if (asprintf(&comp_str,
"%s)", input) < 0)
148 if (asprintf(&disp_str,
")") < 0)
162 if (incomplete[0] ==
't' || incomplete[0] ==
'\0') {
163 if (asprintf(&comp_str,
"%s%s", input, &true_str[strlen(incomplete)]) < 0)
165 if (asprintf(&disp_str,
"true") < 0)
177 if (incomplete[0] ==
'f' || incomplete[0] ==
'\0') {
178 if (asprintf(&comp_str,
"%s%s", input, &false_str[strlen(incomplete)]) < 0)
180 if (asprintf(&disp_str,
"false") < 0)
194 if (asprintf(&comp_str,
"%s,", input) < 0)
196 if (asprintf(&disp_str,
",") < 0)
203 if (asprintf(&comp_str,
"%s)", input) < 0)
205 if (asprintf(&disp_str,
")") < 0)
235 .name =
"bool_tuple",
236 .parse = ec_node_bool_tuple_parse,
237 .complete = ec_node_bool_tuple_complete,
int ec_comp_item_set_display(struct ec_comp_item *item, const char *display)
Set the display value of an item.
struct ec_comp * ec_comp(void)
Create an empty completion object (list of completion items).
struct ec_comp_item * ec_comp_add_item(struct ec_comp *comp, const struct ec_node *node, enum ec_comp_type type, const char *current, const char *full)
Add an item in completion list.
@ EC_COMP_FULL
The item is fully completed.
@ EC_COMP_PARTIAL
The item is partially completed.
#define EC_LOG_TYPE_REGISTER(name)
Register a log type.
struct ec_node * ec_node(const char *typename, const char *id)
Create a new node from its type name.
#define EC_NODE_TYPE_REGISTER(t)
Register a node type at library load.
#define EC_PARSE_NOMATCH
Return value of ec_parse_child() when input does not match grammar.
struct ec_pnode * ec_pnode(const struct ec_node *node)
Create an empty parsing tree.
int ec_str_startswith(const char *s, const char *beginning)
Return 1 if the string starts with the given prefix.
const char * ec_strvec_val(const struct ec_strvec *strvec, size_t idx)
Get a string element from a vector.
struct ec_strvec * ec_strvec(void)
Allocate a new empty string vector.
size_t ec_strvec_len(const struct ec_strvec *strvec)
Get the length of a string vector.
A structure describing a grammar node type.