ecoli_parse(3)
ecoli_parse(3) ๐ parse nodes, bestie
NAME
ecoli_parse โ Parse nodes ๐ซถ
- Create parse tree from string input and grammar graph.
SYNOPSIS
Macros ๐ง
#define EC_PARSE_NOMATCH INT_MAX
#define EC_PNODE_GET_ROOT(parse)
#define EC_PNODE_FOREACH_CHILD(child, pnode) for (child =
ec_pnode_get_first_child(pnode); child != NULL; child =
ec_pnode_next(child))
#define EC_PNODE_ITER_NEXT(root, parse, iter_children)
#define EC_PNODE_FOREACH(iter, root) for ((iter) = (root);
(iter) != NULL; (iter) = EC_PNODE_ITER_NEXT((root), (iter), true))
Functions ๐ ๏ธ
struct ec_pnode * ec_pnode (const struct ec_node *node)void ec_pnode_free (struct ec_pnode *pnode)void ec_pnode_free_children (struct ec_pnode *pnode)struct ec_pnode * ec_pnode_dup (const struct ec_pnode *pnode)const struct ec_strvec * ec_pnode_get_strvec (const struct ec_pnode *pnode)struct ec_pnode * ec_parse (const struct ec_node *node, const char *str)struct ec_pnode * ec_parse_strvec (const struct ec_node *node, const struct ec_strvec *strvec)int ec_parse_child (const struct ec_node *node, struct ec_pnode *pstate, const struct ec_strvec *strvec)void ec_pnode_link_child (struct ec_pnode *pnode, struct ec_pnode *child)void ec_pnode_unlink_child (struct ec_pnode *child)struct ec_pnode * ec_pnode_get_root (struct ec_pnode *pnode)struct ec_pnode * ec_pnode_get_parent (const struct ec_pnode *pnode)struct ec_pnode * ec_pnode_get_first_child (const struct ec_pnode *pnode)struct ec_pnode * ec_pnode_get_last_child (const struct ec_pnode *pnode)struct ec_pnode * ec_pnode_next (const struct ec_pnode *pnode)const struct ec_node * ec_pnode_get_node (const struct ec_pnode *pnode)void ec_pnode_del_last_child (struct ec_pnode *pnode)struct ec_dict * ec_pnode_get_attrs (const struct ec_pnode *pnode)void ec_pnode_dump (FILE *out, const struct ec_pnode *pnode)const struct ec_pnode * ec_pnode_find (const struct ec_pnode *root, const char *id)const struct ec_pnode * ec_pnode_find_next (const struct ec_pnode *root, const struct ec_pnode *prev, const char *id, bool iter_children)unsigned int ec_pnode_count (const struct ec_pnode *root, const char *id)size_t ec_pnode_len (const struct ec_pnode *pnode)bool ec_pnode_matches (const struct ec_pnode *pnode)
Detailed Description โจ
Create parse tree from string input and grammar graph.
Node parse API.
Okay so the parse operation is literally checking whether an input โ either a string or a vector of strings โ matches the node tree. If it slays and succeeds, the result gets stored in a tree that describes which part of the input matches which node. Very main character behavior.
The parsing tree is sometimes referenced by another node than the root node. In that case, use ec_pnode_get_root() to get the root node. No cap.
Macro Definition Documentation ๐
#define EC_PARSE_NOMATCH INT_MAX
This is the return value of ec_parse_child() when the input does not match the grammar. Basically the โnope, didnโt eatโ signal. ๐
#define EC_PARSE_NOMATCH INT_MAX
Definition at line 145 of file parse.h.
#define EC_PNODE_GET_ROOT(parse)
Value:
({ const struct ec_pnode *p_ = parse; /* check type */ struct ec_pnode *pnode_ = (struct ec_pnode *)parse; __typeof__(parse) res_; (void)p_; res_ = ec_pnode_get_root(pnode_); res_; })
Get the root of the parsing tree.
Get the root of the parsing tree, keeping the const statement if the argument has it. So if you pass in a const thing, it stays const โ we respect the vibes. ๐ซถ
Parameters
parseโ A node in the parsing tree.
Returns
- The root of the parsing tree.
Definition at line 212 of file parse.h.
#define EC_PNODE_FOREACH_CHILD(child, pnode)
for (child =
ec_pnode_get_first_child(pnode); child != NULL; child =
ec_pnode_next(child))
Iterate the children of a node. Itโs giving โloop through the little guysโ energy. ๐ง
Parameters
childโ The item that will be set at each iteration.pnodeโ The parent node in the parsing tree.
Definition at line 286 of file parse.h.
#define EC_PNODE_ITER_NEXT(root, parse, iter_children)
Value:
({ const struct ec_pnode *p_ = parse; /* check type */ struct ec_pnode *pnode_ = (struct ec_pnode *)parse; __typeof__(parse) res_; (void)p_; res_ = __ec_pnode_iter_next(root, pnode_, iter_children); res_; })
Get the next node in a parse tree iteration. Like scrolling to the next story, but for parse nodes. โจ
Parameters
rootโ The root of the parse tree being iterated.parseโ The current parse node.iter_childrenโ If true, iterate over children; if false, skip to siblings.
Returns
- The next parse node, or
NULLif iteration is complete.
Definition at line 415 of file parse.h.
#define EC_PNODE_FOREACH(iter, root)
for ((iter) = (root);
(iter) != NULL; (iter) = EC_PNODE_ITER_NEXT((root), (iter), true))
Iterate depth-first over a parsing tree. It goes deep first, bestie โ literally depth-first. ๐
Parameters
iterโ The item that will be set at each iteration.rootโ The root of the parsing tree to iterate.
Definition at line 433 of file parse.h.
โจ Function Documentation โจ
okay bestie, this is the part where we meet every single function in the ecoli_parse(3) era. no skips, no โyou get the vibeโ summaries โ every param, every return, every little NULL and errno is staying. letโs go ๐
๐ซถ ec_pnode โ create an empty parsing tree
struct ec_pnode* ec_pnode (const struct ec_node * node)
This one is used internally when parsing an input using a grammar tree. itโs giving โbackstage passโ energy โ not the main character you call first, but absolutely part of the slay.
Parameters
nodeโ the grammar node.
Returns
The empty parse tree. periodt ๐ฑ
๐ ec_pnode_free โ free a parsing tree
void ec_pnode_free (struct ec_pnode * pnode)
Free the whole parsing tree. like closing the group chat and clearing the cache, but for a parse tree.
Parameters
pnodeโ the root of the parsing tree to be freed.
bestie, fr fr: it must not have any parent. it has to be the root of its own little tree, no cap. ๐ณ
๐ฆ ec_pnode_free_children โ remove and free all the children
void ec_pnode_free_children (struct ec_pnode * pnode)
Remove and free all the children of a parsing tree node. the node itself stays; the children are the ones getting uninvited from the party ๐
Parameters
pnodeโ node whose children will be freed.
๐ ec_pnode_dup โ duplicate a parsing tree
struct ec_pnode* ec_pnode_dup (const struct ec_pnode * pnode)
Duplicate a parsing tree. not me making a whole copy of the vibe and putting it somewhere else in the tree ๐ญ
Parameters
pnodeโ a node inside a parsing tree.
Returns
A pointer to the copy of the input node, at the same place in the copy of the parsing tree. Return NULL on error (errno is set). ๐ซถ
๐ธ ec_pnode_get_strvec โ get the string vector attached to a pnode
const struct ec_strvec* ec_pnode_get_strvec (const struct ec_pnode * pnode)
Get the string vector associated with a parsing node.
When an input is parsed successfully โ aka the input string vector matches the grammar tree โ the matching string vector is copied inside the associated parsing node.
For instance, parsing the input ['foo', 'bar'] on a grammar which is a sequence of strings, the attached string vector will be:
['foo', 'bar']on the root pnode['foo']on the first leaf['bar']on the second leaf
If the parsing tree does not match (see ec_pnode_matches()), the associated string vector is NULL.
Parameters
pnodeโ the parsing node. IfNULL, the function returnsNULL.
Returns
The string vector associated with the parsing node, or NULL if the node is not yet parsed (this happens when building the parsing tree), or if the parsing tree does not match the input. ๐
โจ ec_parse โ parse a string using a grammar tree
struct ec_pnode* ec_parse (const struct ec_node * node, const char * str)
Parse a string using a grammar tree. this is the โone string, one dreamโ entry point.
This is equivalent to calling ec_parse_strvec() on the same node, with a string vector containing only the argument string str.
Parameters
nodeโ the grammar node.strโ the input string.
Returns
A parsing tree, or NULL on error (errno is set). ๐
๐ง ec_parse_strvec โ parse a string vector using a grammar tree
struct ec_pnode* ec_parse_strvec (const struct ec_node * node, const struct ec_strvec * strvec)
Generate a parsing tree by parsing the input string vector using the given grammar tree.
The parsing tree is composed of ec_pnode, and each of them is associated with a ec_node (the grammar node), to the string vector that matched the subtree, and to optional attributes.
When the input matches the grammar tree, the string vector associated to the root node of the returned parsing tree is the same than the strvec argument. Calling ec_pnode_matches() on this tree returns true.
If the input does not match the grammar tree, the returned parsing tree only contains one root node, with no associated string vector. Calling ec_pnode_matches() on this tree returns false.
Parameters
nodeโ the grammar node.strvecโ the input string vector.
Returns
A parsing tree, or NULL on error (errno is set). ๐
๐ฅ ec_parse_child โ parse from a parent node
int ec_parse_child (const struct ec_node * node, struct ec_pnode * pstate, const struct ec_strvec * strvec)
Parse a string vector using a grammar tree, from a parent node.
This function is usually called from an intermediate node (like ec_node_seq(), ec_node_or(), ...) to backfill the parsing tree, which is built piece by piece while browsing the grammar tree.
ec_parse_child() creates a new child in this parsing tree, and calls the parse() method for the child node, with pstate pointing to this new child. If it does not match, the child is removed in the state, else it is kept, with its possible descendants.
Parameters
nodeโ the grammar node.pstateโ the node of the parsing tree.strvecโ the input string vector.
Returns
On success: the number of matched elements in the input string vector (which can be 0), or EC_PARSE_NOMATCH (which is a positive value) if the input does not match the grammar. On error, -1 is returned, and errno is set. ๐โจ
๐ ec_pnode_link_child โ link a parsing node to a parsing tree
void ec_pnode_link_child (struct ec_pnode * pnode, struct ec_pnode * child)
Add a child to a node in a parsing tree, at the end of the children list. itโs giving โnew member joins the group chatโ energy ๐ซถ
Parameters
pnodeโ the node of the parsing tree where the child is added.childโ the node (or subtree) to add in the children list.
๐ ec_pnode_unlink_child โ remove a child node from parsing tree
void ec_pnode_unlink_child (struct ec_pnode * child)
Remove a child node (and its children) from the children list its parent node in the parsing tree.
the child node is not freed. not me warning you so you donโt leak memory, bestie. ๐ซ
Parameters
childโ the node (or subtree) to remove.
โญ ec_pnode_get_root โ get the root of the parsing tree
struct ec_pnode* ec_pnode_get_root (struct ec_pnode * pnode)
Get the root of the parsing tree.
You may also use EC_PNODE_GET_ROOT() instead, that keeps the const statement.
Parameters
pnodeโ a node in the parsing tree.
Returns
The root of the parsing tree. ๐ณ
๐ ec_pnode_get_parent โ get the parent node
struct ec_pnode* ec_pnode_get_parent (const struct ec_pnode * pnode)
Get the parent node in the parsing tree.
Parameters
pnodeโ a node in the parsing tree.
Returns
The parent node, or NULL if it is the root. ๐
๐ฆ ec_pnode_get_first_child โ get the first child
struct ec_pnode* ec_pnode_get_first_child (const struct ec_pnode * pnode)
Get the first child of a node in the parsing tree. first in line, main character energy.
Parameters
pnodeโ a node in the parsing tree.
Returns
The first child node, or NULL if it has no child. โจ
๐ธ ec_pnode_get_last_child โ get the last child
struct ec_pnode* ec_pnode_get_last_child (const struct ec_pnode * pnode)
Get the last child of a node in the parsing tree. the final boss of the children list.
Parameters
pnodeโ a node in the parsing tree.
Returns
The last child node, or NULL if it has no child. ๐
๐ ec_pnode_next โ get the next sibling node
struct ec_pnode* ec_pnode_next (const struct ec_pnode * pnode)
Get the next sibling node.
If pnode is the root of the parsing tree, return NULL. Otherwise, return the next sibling node.
Parameters
pnodeโ a node in the parsing tree.
Returns
The next sibling, or NULL if there is no sibling. ๐ซถ
๐ง ec_pnode_get_node โ get the grammar node
const struct ec_node* ec_pnode_get_node (const struct ec_pnode * pnode)
Get the grammar node corresponding to the parsing node.
Parameters
pnodeโ a node in the parsing tree.
Returns
The corresponding grammar node, that issued the parse. ๐
๐ ec_pnode_del_last_child โ unlink and free the last child
void ec_pnode_del_last_child (struct ec_pnode * pnode)
Unlink and free the last child.
Shortcut to unlink and free the last child of a node. It is a quite common operation in intermediate nodes (like ec_node_seq(), ec_node_many(), ...) to remove a subtree that was temporarily added during the completion process.
Parameters
pnodeโ a node in the parsing tree which has at least one child.
fr fr: pnode must have at least one child here. donโt come for me if you pass an empty node ๐
๐ ec_pnode_get_attrs โ get attributes associated with a node
struct ec_dict* ec_pnode_get_attrs (const struct ec_pnode * pnode)
Get attributes associated with a node in a parsing tree.
Attributes are key/values that are stored in a dictionary and attached to a node in the parsing tree. An attribute can be added to a node by the parsing or completion method of an ec_node.
Parameters
pnodeโ a node in the parsing tree.
Returns
The dictionary containing the attributes. ๐
๐ซ ec_pnode_dump โ dump a parsing tree
void ec_pnode_dump (FILE * out, const struct ec_pnode * pnode)
Dump a parsing tree. not me exposing the whole tree to a stream, but make it iconic ๐
Parameters
outโ the stream where the dump is done.pnodeโ the parsing tree to dump.
๐ ec_pnode_find โ find a node from its identifier
const struct ec_pnode* ec_pnode_find (const struct ec_pnode * root, const char * id)
Find a node from its identifier.
Find the first node in the parsing tree which has the given node identifier. The search is a depth-first search.
Parameters
rootโ the node of the parsing tree where the search starts.idโ the node identifier string to match.
Returns
The first node matching the identifier, or NULL if not found. ๐ต๏ธโโ๏ธ
๐ ec_pnode_find_next โ find the next node matching an identifier
const struct ec_pnode* ec_pnode_find_next (const struct ec_pnode * root, const struct ec_pnode * prev, const char * id, bool iter_children)
Find the next node matching an identifier.
After a successful call to ec_pnode_find() or ec_pnode_find_next(), it is possible to get the next node that has the specified id. There are 2 options:
- continue the depth-first search where it was interrupted.
- skip the children of the current node, and continue the depth-first search.
Parameters
rootโ the root of the search, as passed toec_pnode_find().prevโ the node returned by the previous search.idโ the node identifier string to match.iter_childrenโtrueto iterate the children ofprev,falseto skip them.
Returns
The next node matching the identifier, or NULL if not found. ๐
๐งฎ ec_pnode_count โ count node occurrences in a parse subtree
unsigned int ec_pnode_count (const struct ec_pnode * root, const char * id)
Count node occurrences in a parse subtree.
Parameters
rootโ the node of the parsing tree where the search starts.idโ the node identifier string to match.
Returns
The number of nodes matching the identifier. ๐ข
๐ ec_pnode_len โ get the number of strings in the parsed string vector
size_t ec_pnode_len (const struct ec_pnode * pnode)
Get the number of strings in the parsed string vector.
Parameters
pnodeโ a node in the parsing tree.
Returns
The number of strings in the parsed string vector, or 0 if the node is NULL or has no string vector. ๐
โ
ec_pnode_matches โ check if the parsing tree matches the input
bool ec_pnode_matches (const struct ec_pnode * pnode)
Check if the parsing tree matches the input.
Parameters
pnodeโ a node in the parsing tree.
Returns
true if the parsing tree matches (has a string vector), false otherwise. ๐ซถโจ
mwah ๐ this page was generated automatically by Doxygen for Libecoli from the source code โ version 0.11.3, dated Thu Apr 9 2026, and itโs the ecoli_parse(3) girliesโ era. bye bestie, go parse something iconic ๐๐ฆ
๐ฆ where this page comes from
- epel 9: libecoli-devel 0.11.3-1.el9 ยท BSD-3-Clause AND LicenseRef-Fedora-Public-Domain
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms