#include <ecoli_node_int.h>
#include <ecoli_node_re_lex.h>
+EC_LOG_TYPE_REGISTER(node_re_lex);
+
struct regexp_pattern {
char *pattern;
regex_t r;
c = dup[pos.rm_eo + off];
dup[pos.rm_eo + off] = '\0';
- ec_log(EC_LOG_DEBUG, "re_lex match <%s>\n", &dup[off]);
+ EC_LOG(EC_LOG_DEBUG, "re_lex match <%s>\n", &dup[off]);
if (ec_strvec_add(strvec, &dup[off]) < 0)
goto fail;
}
ret = ec_node_parse_child(node->child, state, new_vec);
- if (ret >= 0) {
- if ((unsigned)ret == ec_strvec_len(new_vec)) {
- ret = 1;
- } else {
- child_parsed = ec_parsed_get_last_child(state);
- ec_parsed_del_child(state, child_parsed);
- ec_parsed_free(child_parsed);
- ret = EC_PARSED_NOMATCH;
- }
+ if (ret < 0)
+ goto fail;
+
+ if ((unsigned)ret == ec_strvec_len(new_vec)) {
+ ret = 1;
+ } else if (ret != EC_PARSED_NOMATCH) {
+ child_parsed = ec_parsed_get_last_child(state);
+ ec_parsed_del_child(state, child_parsed);
+ ec_parsed_free(child_parsed);
+ ret = EC_PARSED_NOMATCH;
}
ec_strvec_free(new_vec);
ret = regcomp(&table[node->len].r, pattern, REG_EXTENDED);
if (ret != 0) {
- ec_log(EC_LOG_ERR,
+ EC_LOG(EC_LOG_ERR,
"Regular expression <%s> compilation failed: %d\n",
pattern, ret);
if (ret == REG_ESPACE)
return &node->gen;
}
-
+/* LCOV_EXCL_START */
static int ec_node_re_lex_testcase(void)
{
struct ec_node *node;
int ret = 0;
- node = ec_node_re_lex(NULL,
- ec_node_many(NULL,
- EC_NODE_OR(NULL,
- ec_node_str(NULL, "foo"),
- ec_node_str(NULL, "bar"),
- ec_node_int(NULL, 0, 1000, 0)
+ node = ec_node_re_lex(EC_NO_ID,
+ ec_node_many(EC_NO_ID,
+ EC_NODE_OR(EC_NO_ID,
+ ec_node_str(EC_NO_ID, "foo"),
+ ec_node_str(EC_NO_ID, "bar"),
+ ec_node_int(EC_NO_ID, 0, 1000, 0)
), 0, 0
)
);
if (node == NULL) {
- ec_log(EC_LOG_ERR, "cannot create node\n");
+ EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
ret |= ec_node_re_lex_add(node, "\\+", 1);
ret |= ec_node_re_lex_add(node, "[ ]+", 0);
if (ret != 0) {
- ec_log(EC_LOG_ERR, "cannot add regexp to node\n");
+ EC_LOG(EC_LOG_ERR, "cannot add regexp to node\n");
ec_node_free(node);
return -1;
}
return ret;
}
+/* LCOV_EXCL_STOP */
static struct ec_test ec_node_re_lex_test = {
.name = "node_re_lex",