#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
if (child == NULL)
return -ENOMEM;
+ child->node = node;
ec_parsed_add_child(state, child);
ret = node->type->parse(node, child, strvec);
if (ret == EC_PARSED_NOMATCH) {
if (match_strvec == NULL)
return -ENOMEM;
- child->node = node;
child->strvec = match_strvec;
return ret;
fprintf(out, "|");
}
- fprintf(out, "node_type=%s id=%s vec=[", typename, id);
+ fprintf(out, "node_type=%s id=%s vec=", typename, id);
vec = ec_parsed_strvec(parsed);
- for (i = 0; i < ec_strvec_len(vec); i++)
- fprintf(out, "%s<%s>",
- i == 0 ? "" : ",",
- ec_strvec_val(vec, i));
- // XXX
- if (!strcmp(typename, "int") || !strcmp(typename, "str"))
- fprintf(out, "] <<<<<\n");
- else
- fprintf(out, "]\n");
+ ec_strvec_dump(out, vec);
TAILQ_FOREACH(child, &parsed->children, next)
__ec_parsed_dump(out, child, indent + 2);
child->parent = parsed;
}
-void ec_parsed_del_child(struct ec_parsed *parsed,
+void ec_parsed_del_child(struct ec_parsed *parsed, // XXX rename del in unlink?
struct ec_parsed *child)
{
TAILQ_REMOVE(&parsed->children, child, next);
return TAILQ_LAST(&parsed->children, ec_parsed_list);
}
+void ec_parsed_del_last_child(struct ec_parsed *parsed) // rename in free
+{
+ struct ec_parsed *child;
+
+ child = ec_parsed_get_last_child(parsed);
+ ec_parsed_del_child(parsed, child);
+ ec_parsed_free(child);
+}
+
struct ec_parsed *ec_parsed_get_root(struct ec_parsed *parsed)
{
if (parsed == NULL)
return parsed;
}
+struct ec_parsed *ec_parsed_get_parent(struct ec_parsed *parsed)
+{
+ if (parsed == NULL)
+ return NULL;
+
+ return parsed->parent;
+}
+
struct ec_parsed *ec_parsed_find_first(struct ec_parsed *parsed,
const char *id)
{