From 6dd359e90003ab38941f4500aa5850138a480ace Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 17 Aug 2014 12:22:03 -0400 Subject: [PATCH] Parser - Modified ::findPattern to use collect. --- src/Parser.cpp | 52 ++++++++++++++++++++++++++++++-------------------- src/Parser.h | 2 +- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index 5f182e1ab..a4a77db8f 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -179,8 +179,8 @@ Tree* Parser::parse () applyOverrides (); findSubstitution (); + findPattern (); // GOOD ^^^ - scan (&Parser::findPattern); scan (&Parser::findTag); scan (&Parser::findAttribute); scan (&Parser::findAttributeModifier); @@ -830,39 +830,49 @@ std::string Parser::getCommand () const //////////////////////////////////////////////////////////////////////////////// // /pattern/ --> description ~ pattern -void Parser::findPattern (Tree* t) +void Parser::findPattern () { - context.debug ("findPattern"); - context.debug (t->dump ()); + context.debug ("Parser::findPattern"); + bool action = false; - Nibbler n (t->attribute ("raw")); - std::string pattern; - if (n.getQuoted ('/', pattern) && - n.depleted () && - pattern.length () > 0) + std::vector nodes; + collect (nodes, false); + std::vector ::iterator i; + for (i = nodes.begin (); i != nodes.end (); ++i) { - t->unTag ("?"); - t->removeAllBranches (); - t->tag ("PATTERN"); + Nibbler n ((*i)->attribute ("raw")); + std::string pattern; + if (n.getQuoted ('/', pattern) && + n.depleted () && + pattern.length () > 0) + { + (*i)->unTag ("?"); + (*i)->removeAllBranches (); + (*i)->tag ("PATTERN"); - Tree* branch = t->addBranch (new Tree ("argPat")); - branch->attribute ("raw", "description"); + Tree* branch = (*i)->addBranch (new Tree ("argPat")); + branch->attribute ("raw", "description"); - branch = t->addBranch (new Tree ("argPat")); - branch->attribute ("raw", "~"); - branch->tag ("OP"); + branch = (*i)->addBranch (new Tree ("argPat")); + branch->attribute ("raw", "~"); + branch->tag ("OP"); - branch = t->addBranch (new Tree ("argPat")); - branch->attribute ("raw", pattern); - branch->tag ("STRING"); + branch = (*i)->addBranch (new Tree ("argPat")); + branch->attribute ("raw", pattern); + branch->tag ("STRING"); + action = true; + } } + + if (action) + context.debug (_tree->dump ()); } //////////////////////////////////////////////////////////////////////////////// // /from/to/[g] void Parser::findSubstitution () { - context.debug ("Parse::findSubstitution"); + context.debug ("Parser::findSubstitution"); bool action = false; std::vector nodes; diff --git a/src/Parser.h b/src/Parser.h index 23f7c5d3c..62f2a565c 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -72,7 +72,7 @@ public: private: void scan (void (Parser::*callback)(Tree*), Tree* tree = NULL); void findTerminator (); - void findPattern (Tree*); + void findPattern (); void findSubstitution (); void findTag (Tree*); void findAttribute (Tree*);