class Cmark::EventIterator
- Cmark::EventIterator
- Reference
- Object
Overview
An iterator that walks through a tree of nodes, starting from a root node, returning an Event
with one node at a time,
together with information about whether the node is being entered or exited, and if it is modifiable.
The iterator will first descend to a child node (returning an ENTER Event
),
if there is one.
When there is no child, the iterator will go to the next sibling.
When there is no next sibling, the iterator will return to the parent (but returning an EXIT Event
).
The iterator will stop after it reaches the root node again on exit.
One natural application is an HTML renderer, where an ENTER event outputs an open tag and an EXIT event outputs a close tag. An iterator might also be used to transform an AST in some systematic way, for example, turning all level-3 headings into regular paragraphs.
NOTE Nodes can be modified only after an EXIT event or an ENTER event for leaf nodes. The convenience
method Event#modifiable?
checks that these conditions are met.
Included Modules
- Iterator(Cmark::Event)
Defined in:
cmark/event_iterator.crConstructors
Instance Method Summary
-
#modifiable_node_iterator : Iterator(Node)
Returns an iterator with all the nodes in the order in which can be modified.
-
#next
Returns the next node event in this iterator, or
Iterator::Stop::INSTANCE
if there are no more events. -
#rewind
Rewinds the iterator to its original state.
Constructor Detail
Instance Method Detail
Returns an iterator with all the nodes in the order in which can be modified.
Returns the next node event in this iterator, or Iterator::Stop::INSTANCE
if there are no more events.