I'm trying to improve this document parser and there is one main loop that goes over all of the main elements (let's call them Node
s). Each step (Step
) can either Consume
or Ignore
the Node
that it is passed. A Step
can also be greedy and consume more than the single Node
than was passed to it. A Step
could restrict its transition to other states like a state machine. I can't remove Node
from the list of nodes as that would get me into collection modified while enumerating problems and it would be difficult to accelerate the main loop
What design would work well for this?
Here is something I have been considering to implement.
class Node { ... }
class Step
{
void Handle(NodeContext);
...
}
class NodeContext
{
Node Node { get; }
void Ignore();
void Consume();
}