X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=include%2Fecoli_parse.h;h=a64c0ae43e8f76eb3860415f8f726b8e0b5af9dd;hb=376f5016e3979247bf0db515e47df49ba1eb82ac;hp=a431ba2d385c942d2dd473edf7b38af94b1d0bb9;hpb=18d03456d96f7a086a2ccc82ce97fcf056848d90;p=protos%2Flibecoli.git diff --git a/include/ecoli_parse.h b/include/ecoli_parse.h index a431ba2..a64c0ae 100644 --- a/include/ecoli_parse.h +++ b/include/ecoli_parse.h @@ -3,11 +3,18 @@ */ /** + * @defgroup parse Parse + * @{ + * + * @brief Create parse tree from string input and grammar tree + * * Node parse API. * * The parse operation is to check if an input (a string or vector of * strings) matches the node tree. On success, the result is stored in a * tree that describes which part of the input matches which node. + * + * @} */ #ifndef ECOLI_PARSE_ @@ -159,7 +166,7 @@ struct ec_parse *ec_parse_get_last_child(const struct ec_parse *parse); * * */ -struct ec_parse *ec_parse_get_next(const struct ec_parse *parse); +struct ec_parse *ec_parse_next(const struct ec_parse *parse); /** * @@ -168,8 +175,8 @@ struct ec_parse *ec_parse_get_next(const struct ec_parse *parse); */ #define EC_PARSE_FOREACH_CHILD(child, parse) \ for (child = ec_parse_get_first_child(parse); \ - child != NULL; \ - child = ec_parse_get_next(child)) \ + child != NULL; \ + child = ec_parse_next(child)) \ /** * @@ -197,7 +204,7 @@ void ec_parse_del_last_child(struct ec_parse *parse); * * */ -struct ec_keyval *ec_parse_get_attrs(struct ec_parse *parse); +struct ec_dict *ec_parse_get_attrs(struct ec_parse *parse); /** * @@ -211,16 +218,36 @@ void ec_parse_dump(FILE *out, const struct ec_parse *parse); * * */ -struct ec_parse *ec_parse_find_first(struct ec_parse *parse, +struct ec_parse *ec_parse_find(struct ec_parse *parse, const char *id); +/** + * + * + * + */ +struct ec_parse *ec_parse_find_next(struct ec_parse *root, + struct ec_parse *start, + const char *id, bool iter_children); + /** * Iterate among parse tree * * Use it with: - * for (iter = state; iter != NULL; iter = ec_parse_iter_next(iter)) + * for (iter = state; iter != NULL; iter = EC_PARSE_ITER_NEXT(state, iter, 1)) */ -struct ec_parse *ec_parse_iter_next(struct ec_parse *parse); +struct ec_parse *__ec_parse_iter_next(const struct ec_parse *root, + struct ec_parse *parse, bool iter_children); + +/* keep the const if any */ +#define EC_PARSE_ITER_NEXT(root, parse, iter_children) ({ \ + const struct ec_parse *p_ = parse; /* check type */ \ + struct ec_parse *parse_ = (struct ec_parse *)parse; \ + typeof(parse) res_; \ + (void)p_; \ + res_ = __ec_parse_iter_next(root, parse_, iter_children); \ + res_; \ +}) /** *