diff --git a/src/Parser.cpp b/src/Parser.cpp index 78e384eed..a2099b9ff 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -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 ::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 ::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. diff --git a/src/Parser.h b/src/Parser.h index 6232f6379..cd03809c0 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -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 ();