From 7848b9284de4d9caff8be1a996fef1dad49684a4 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 17 Aug 2014 00:26:41 -0400 Subject: [PATCH] Parser - Modified ::scan to be recursive, which will now allow arbitrary parse tree depth. --- src/Parser.cpp | 27 +++++++++------------------ src/Parser.h | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) 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 ();