- Modified ::scan to be recursive, which will now allow arbitrary parse tree
  depth.
This commit is contained in:
Paul Beckingham 2014-08-17 00:26:41 -04:00
parent 3145134953
commit 7848b9284d
2 changed files with 10 additions and 19 deletions

View file

@ -270,33 +270,24 @@ bool Parser::canonicalize (
}
////////////////////////////////////////////////////////////////////////////////
// Experimental method to iterate over nodes, and callback, which is essentially
// a co-routine implementation.
void Parser::scan (void (Parser::*callback) (Tree*))
// Recursively scan all nodes, depth first, skipping terminated nodes, and known
// nodes, and cal the callback function for each node.
void Parser::scan (void (Parser::*callback) (Tree*), Tree* tree /* = NULL */)
{
if (tree == NULL)
tree = _tree;
std::vector <Tree*>::iterator i;
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
for (i = tree->_branches.begin (); i != tree->_branches.end (); ++i)
{
if ((*i)->_branches.size ())
{
std::vector <Tree*>::iterator b;
for (b = (*i)->_branches.begin (); b != (*i)->_branches.end (); ++b)
{
// Parser override operator.
if ((*b)->attribute ("raw") == "--")
break;
// Skip known args.
if (! (*b)->hasTag ("?"))
continue;
(this->*callback) (*b);
}
scan (callback, *i);
}
else
{
// Parser override operator.
if ((*i)->attribute ("raw") == "--")
if ((*i)->hasTag ("TERMINATOR"))
break;
// Skip known args.

View file

@ -69,7 +69,7 @@ public:
private:
void findTerminator ();
void scan (void (Parser::*callback)(Tree*));
void scan (void (Parser::*callback)(Tree*), Tree* tree = NULL);
void findPattern ();
void findSubstitution ();
void findTag ();