- 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 // Recursively scan all nodes, depth first, skipping terminated nodes, and known
// a co-routine implementation. // nodes, and cal the callback function for each node.
void Parser::scan (void (Parser::*callback) (Tree*)) void Parser::scan (void (Parser::*callback) (Tree*), Tree* tree /* = NULL */)
{ {
if (tree == NULL)
tree = _tree;
std::vector <Tree*>::iterator i; 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 ()) if ((*i)->_branches.size ())
{ {
std::vector <Tree*>::iterator b; scan (callback, *i);
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);
}
} }
else else
{ {
// Parser override operator. // Parser override operator.
if ((*i)->attribute ("raw") == "--") if ((*i)->hasTag ("TERMINATOR"))
break; break;
// Skip known args. // Skip known args.

View file

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