From a4f558ee1c3247e11c7a5fb3c1f6a4084be14994 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 17 Aug 2014 12:18:35 -0400 Subject: [PATCH] Parser - Converted ::findSubstitution to use collect. --- src/Parser.cpp | 58 +++++++++++++++++++++++++++++--------------------- src/Parser.h | 2 +- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index 12293190e..5f182e1ab 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -173,13 +173,13 @@ Tree* Parser::parse () { findBinary (); findTerminator (); - // GOOD ^^^ resolveAliases (); findOverrides (); applyOverrides (); - scan (&Parser::findSubstitution); + findSubstitution (); + // GOOD ^^^ scan (&Parser::findPattern); scan (&Parser::findTag); scan (&Parser::findAttribute); @@ -860,35 +860,45 @@ void Parser::findPattern (Tree* t) //////////////////////////////////////////////////////////////////////////////// // /from/to/[g] -void Parser::findSubstitution (Tree* t) +void Parser::findSubstitution () { - context.debug ("findSubstitution"); - context.debug (t->dump ()); + context.debug ("Parse::findSubstitution"); + bool action = false; - std::string raw = t->attribute ("raw"); - Nibbler n (raw); - - std::string from; - std::string to; - bool global = false; - if (n.getQuoted ('/', from) && - n.backN () && - n.getQuoted ('/', to)) + std::vector nodes; + collect (nodes, false); + std::vector ::iterator i; + for (i = nodes.begin (); i != nodes.end (); ++i) { - if (n.skip ('g')) - global = true; + std::string raw = (*i)->attribute ("raw"); + Nibbler n (raw); - if (n.depleted () && - !Directory (raw).exists ()) + std::string from; + std::string to; + bool global = false; + if (n.getQuoted ('/', from) && + n.backN () && + n.getQuoted ('/', to)) { - t->unTag ("?"); - t->removeAllBranches (); - t->tag ("SUBSTITUTION"); - t->attribute ("from", from); - t->attribute ("to", to); - t->attribute ("global", global ? 1 : 0); + if (n.skip ('g')) + global = true; + + if (n.depleted () && + !Directory (raw).exists ()) + { + (*i)->unTag ("?"); + (*i)->removeAllBranches (); + (*i)->tag ("SUBSTITUTION"); + (*i)->attribute ("from", from); + (*i)->attribute ("to", to); + (*i)->attribute ("global", global ? 1 : 0); + action = true; + } } } + + if (action) + context.debug (_tree->dump ()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Parser.h b/src/Parser.h index b7edf408e..23f7c5d3c 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -73,7 +73,7 @@ private: void scan (void (Parser::*callback)(Tree*), Tree* tree = NULL); void findTerminator (); void findPattern (Tree*); - void findSubstitution (Tree*); + void findSubstitution (); void findTag (Tree*); void findAttribute (Tree*); void findAttributeModifier (Tree*);