EC_NODE_ITER(3)

πŸ“¦
version 0.11.7 Β· 3 versions
, in fedora 44

πŸ’– EC_NODE_ITER(3) πŸ’–

okay bestie, sit down, hydrate, and let me tell you about ec_node_iter β€” it's the cutie from the Libecoli Programmer's Manual that builds you an iterator on a grammar tree, and honestly? she's doing the most. ✨


🌸 NAME 🌸

ec_node_iter β€” Create an iterator on a grammar tree.


πŸŽ€ SYNOPSIS πŸŽ€

#include <ecoli/node.h>

struct ec_node_iter * ec_node_iter(
    struct ec_node   *node   /* The grammar graph to iterate */
);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so first thing, bestie, plot twist: a grammar tree is not actually a tree. 😭 It's an oriented graph, which means loops can exist in it. Which is iconic of her but also means you literally cannot just walk the grammar graph without storing somewhere the list of browsed nodes, because if you don't you will loop forever and that's not the vibe. πŸ’€ So yeah β€” we keep track. Loop-breaking is mandatory, no cap.

Second thing: the same node can show up several times at different places in the graph, and it can have a different parent each time. Not me showing up to three different parties with three different outfits. πŸ’… Anyway β€” this kind of node will be iterated only once. One node, one appearance in the iteration. Periodt.

The typical use is giving:

struct ec_node_iter *iter_root, *iter;

iter_root = ec_node_iter(node);
if (iter_root == NULL)
   goto fail;

for (iter = iter_root; iter != NULL;
     iter = ec_node_iter_next(iter_root, iter, true)) {
   do_something_with(ec_node_iter_get_node(iter));
}

ec_node_iter_free(iter_root);

look at that little for-loop. she ate. πŸ”₯

Technically β€” and this is the lowkey nerdy part that I'm obsessed with β€” this function builds a tree from the grammar graph. Each node of this tree references a node of the grammar graph. So the graph stays the graph, the tree is the tour guide. 🧚


⭐ RETURN VALUE ⭐

The grammar graph iterator on success β€” and you must free it using ec_node_iter_free(), do not leave her hanging bestie. πŸ™ˆ

Returns NULL on error.


πŸ‘‘ SEE ALSO πŸ‘‘

that's the whole friend group right there. go say hi. 🫢


Copyright (C) 2010-2026 Olivier Matz, Robin Jarry.


and that's the tea, bestie ✨ this whole page came straight outta libecoli, version-dated 2026-06-11, filed under EC_NODE_ITER(3) β€” love her, follow her, free your iterators. πŸ’–πŸŽ€πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from