From 3c612a85513f9093b354aeabce52fc9d19d2fd64 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 17 Aug 2014 00:41:11 -0400 Subject: [PATCH] Parser - Converted ::findTerminator to use the recursive scanner. --- src/Parser.cpp | 40 +++++++++++++++++++--------------------- src/Parser.h | 2 +- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index 80482434b..15b2d9d90 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -170,13 +170,12 @@ Tree* Parser::tree () Tree* Parser::parse () { findBinary (); - findTerminator (); + scan (&Parser::findTerminator); resolveAliases (); findOverrides (); applyOverrides (); - findSubstitution (); findPattern (); findTag (); @@ -331,27 +330,26 @@ void Parser::findBinary () //////////////////////////////////////////////////////////////////////////////// // The parser override operator terminates all subsequent cleverness, leaving // all args in the raw state. -void Parser::findTerminator () +void Parser::findTerminator (Tree* t) { - bool found = false; - std::vector ::iterator i; - for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i) + // Mark the terminator. + static bool found = false; + if (! found && + t->attribute ("raw") == "--") { - if (!found && - (*i)->attribute ("raw") == "--") - { - (*i)->unTag ("?"); - (*i)->removeAllBranches (); - (*i)->tag ("TERMINATOR"); - found = true; - } - else if (found) - { - (*i)->unTag ("?"); - (*i)->removeAllBranches (); - (*i)->tag ("WORD"); - (*i)->tag ("TERMINATED"); - } + t->unTag ("?"); + t->removeAllBranches (); + t->tag ("TERMINATOR"); + found = true; + } + + // Mark subsequent nodes. + else if (found) + { + t->unTag ("?"); + t->removeAllBranches (); + t->tag ("WORD"); + t->tag ("TERMINATED"); } } diff --git a/src/Parser.h b/src/Parser.h index cd03809c0..e61e9876a 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -68,8 +68,8 @@ public: std::string getCommand () const; private: - void findTerminator (); void scan (void (Parser::*callback)(Tree*), Tree* tree = NULL); + void findTerminator (Tree*); void findPattern (); void findSubstitution (); void findTag ();