struct ec_tk *ec_tk_new(const char *id, const struct ec_tk_type *type,
size_t priv_size);
+
void ec_tk_free(struct ec_tk *tk);
/* XXX add more accessors */
#include <ecoli_tk_expr.h>
#include <ecoli_tk_str.h>
#include <ecoli_tk_or.h>
+#include <ecoli_tk_subset.h>
#include <ecoli_tk_int.h>
#include <ecoli_tk_many.h>
#include <ecoli_tk_seq.h>
ec_tk_free(in2);
*result = out;
} else if (!strcmp(ec_strvec_val(vec, 0), ",")) {
+ out = EC_TK_SUBSET(NULL, ec_tk_clone(in1), ec_tk_clone(in2));
+ if (out == NULL)
+ return -EINVAL;
ec_tk_free(in1);
ec_tk_free(in2);
- *result = NULL; //XXX
+ *result = out;
} else {
return -EINVAL;
}
if (out == NULL)
return -EINVAL;
ec_tk_free(in);
+ } else if (!strcmp(ec_strvec_val(vec, 0), "(")) {
+ out = in;
} else {
return -EINVAL;
}
int ret = 0;
tk = EC_TK_CMD(NULL,
- "add [toto] x | y",
+ "command [option] (subset1, subset2) x | y",
ec_tk_int("x", 0, 10, 10),
ec_tk_int("y", 20, 30, 10)
);
ec_log(EC_LOG_ERR, "cannot create tk\n");
return -1;
}
- ret |= EC_TEST_CHECK_TK_PARSE(tk, 2, "add", "1");
- ret |= EC_TEST_CHECK_TK_PARSE(tk, 2, "add", "23");
- ret |= EC_TEST_CHECK_TK_PARSE(tk, 3, "add", "toto", "23");
- ret |= EC_TEST_CHECK_TK_PARSE(tk, -1, "add", "15");
+ ret |= EC_TEST_CHECK_TK_PARSE(tk, 2, "command", "1");
+ ret |= EC_TEST_CHECK_TK_PARSE(tk, 2, "command", "23");
+ ret |= EC_TEST_CHECK_TK_PARSE(tk, 3, "command", "option", "23");
+ ret |= EC_TEST_CHECK_TK_PARSE(tk, -1, "command", "15");
ret |= EC_TEST_CHECK_TK_PARSE(tk, -1, "foo");
ec_tk_free(tk);
EC_TK_TYPE_REGISTER(ec_tk_empty_type);
-struct ec_tk *ec_tk_empty_new(const char *id)
+struct ec_tk *ec_tk_empty(const char *id)
{
return ec_tk_new(id, &ec_tk_empty_type,
sizeof(struct ec_tk_empty));
struct ec_tk *tk;
int ret = 0;
- tk = ec_tk_empty_new(NULL);
+ tk = ec_tk_empty(NULL);
if (tk == NULL) {
ec_log(EC_LOG_ERR, "cannot create tk\n");
return -1;
ec_tk_free(tk);
/* never completes */
- tk = ec_tk_empty_new(NULL);
+ tk = ec_tk_empty(NULL);
if (tk == NULL) {
ec_log(EC_LOG_ERR, "cannot create tk\n");
return -1;
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/**
+ * This token always matches an empty string vector
+ */
+
#ifndef ECOLI_TK_EMPTY_
#define ECOLI_TK_EMPTY_
-struct ec_tk *ec_tk_empty_new(const char *id);
+struct ec_tk *ec_tk_empty(const char *id);
#endif
if (ret < 0)
goto fail;
+ /* if no child tk matches, return a matching empty strvec */
if (result.parsed_table_len == 0) {
ec_free(result.parsed_table);
+ match_strvec = ec_strvec_new();
+ if (match_strvec == NULL)
+ goto fail;
+ ec_parsed_tk_set_match(parsed_tk, gen_tk, match_strvec);
return parsed_tk;
}
ec_log(EC_LOG_ERR, "cannot create tk\n");
return -1;
}
+ ret |= EC_TEST_CHECK_TK_PARSE(tk, 0);
ret |= EC_TEST_CHECK_TK_PARSE(tk, 1, "foo");
ret |= EC_TEST_CHECK_TK_PARSE(tk, 1, "bar");
ret |= EC_TEST_CHECK_TK_PARSE(tk, 2, "foo", "bar", "titi");
ret |= EC_TEST_CHECK_TK_PARSE(tk, 1, "foo", "foo");
ret |= EC_TEST_CHECK_TK_PARSE(tk, 2, "bar", "bar");
ret |= EC_TEST_CHECK_TK_PARSE(tk, 2, "bar", "foo");
- ret |= EC_TEST_CHECK_TK_PARSE(tk, -1, " ");
- ret |= EC_TEST_CHECK_TK_PARSE(tk, -1, "foox");
- ret |= EC_TEST_CHECK_TK_PARSE(tk, -1, "titi");
- ret |= EC_TEST_CHECK_TK_PARSE(tk, -1, "");
+ ret |= EC_TEST_CHECK_TK_PARSE(tk, 0, " ");
+ ret |= EC_TEST_CHECK_TK_PARSE(tk, 0, "foox");
ec_tk_free(tk);
/* test completion */
X evaluate expression tree in ec_tk_expr
- cmd token
- example
-- tk_re
+X tk_re
cleanup
=======