From 314ac28a0f8e7ce8669bbcfd27f1efb29fa30e0e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 16 Aug 2014 23:53:22 -0400 Subject: [PATCH] Parser - Implemented ::scan, which iterates over parse tree nodes and calls back. This method skips parent nodes, terminated nodes, and nodes without the '?' tag. --- src/Parser.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/Parser.h | 1 + 2 files changed, 40 insertions(+) diff --git a/src/Parser.cpp b/src/Parser.cpp index 327821af3..446c5008b 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -269,6 +269,45 @@ bool Parser::canonicalize ( return false; } +//////////////////////////////////////////////////////////////////////////////// +// Experimental method to iterate over nodes, and callback, which is essentially +// a co-routine implementation. +void Parser::scan (void (Parser::*callback) (Tree*)) +{ + std::vector ::iterator 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); + } + } + else + { + // Parser override operator. + if ((*i)->attribute ("raw") == "--") + break; + + // Skip known args. + if (! (*i)->hasTag ("?")) + continue; + + (this->*callback) (*i); + } + } +} + //////////////////////////////////////////////////////////////////////////////// // Locate and tag the binary. void Parser::findBinary () diff --git a/src/Parser.h b/src/Parser.h index 27491b0cf..6232f6379 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -69,6 +69,7 @@ public: private: void findTerminator (); + void scan (void (Parser::*callback)(Tree*)); void findPattern (); void findSubstitution (); void findTag ();