From d1e38a784371301a5cd59c8ccb5ead02ca33e4f0 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 17 Aug 2014 11:56:34 -0400 Subject: [PATCH] Parser - Converted ::findTerminator to use collect. --- src/Parser.cpp | 51 ++++++++++++++++++++++++++++++++------------------ src/Parser.h | 2 +- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index c5f52477d..77e12e099 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -172,7 +172,8 @@ Tree* Parser::tree () Tree* Parser::parse () { findBinary (); - scan (&Parser::findTerminator); + findTerminator (); + // GOOD ^^^ resolveAliases (); findOverrides (); @@ -368,27 +369,41 @@ void Parser::findBinary () //////////////////////////////////////////////////////////////////////////////// // The parser override operator terminates all subsequent cleverness, leaving // all args in the raw state. -void Parser::findTerminator (Tree* t) +void Parser::findTerminator () { - // Mark the terminator. - static bool found = false; - if (! found && - t->attribute ("raw") == "--") + context.debug ("Parser::findTerminator"); + bool found = false; + bool action = false; + + std::vector nodes; + collect (nodes, false); + std::vector ::iterator i; + for (i = nodes.begin (); i != nodes.end (); ++i) { - t->unTag ("?"); - t->removeAllBranches (); - t->tag ("TERMINATOR"); - found = true; + // Mark the terminator. + if (! found && + (*i)->attribute ("raw") == "--") + { + (*i)->unTag ("?"); + (*i)->removeAllBranches (); + (*i)->tag ("TERMINATOR"); + found = true; + action = true; + } + + // Mark subsequent nodes. + else if (found) + { + (*i)->unTag ("?"); + (*i)->removeAllBranches (); + (*i)->tag ("WORD"); + (*i)->tag ("TERMINATED"); + action = true; + } } - // Mark subsequent nodes. - else if (found) - { - t->unTag ("?"); - t->removeAllBranches (); - t->tag ("WORD"); - t->tag ("TERMINATED"); - } + if (action) + context.debug (_tree->dump ()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Parser.h b/src/Parser.h index e8a9349be..b7edf408e 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -71,7 +71,7 @@ public: private: void scan (void (Parser::*callback)(Tree*), Tree* tree = NULL); - void findTerminator (Tree*); + void findTerminator (); void findPattern (Tree*); void findSubstitution (Tree*); void findTag (Tree*);