From ed07e47135c49df630ff1778a9ab4dbf47e2053f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 17 Aug 2014 12:25:08 -0400 Subject: [PATCH] Parser - Modified ::findTag to use collect. --- src/Parser.cpp | 60 +++++++++++++++++++++++++++++--------------------- src/Parser.h | 2 +- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index a4a77db8f..abba288f3 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -180,8 +180,8 @@ Tree* Parser::parse () findSubstitution (); findPattern (); + findTag (); // GOOD ^^^ - scan (&Parser::findTag); scan (&Parser::findAttribute); scan (&Parser::findAttributeModifier); scan (&Parser::findOperator); @@ -913,37 +913,47 @@ void Parser::findSubstitution () //////////////////////////////////////////////////////////////////////////////// // +tag -void Parser::findTag (Tree* t) +void Parser::findTag () { - context.debug ("findTag"); - context.debug (t->dump ()); + context.debug ("Parser::findTag"); + bool action = false; - std::string raw = t->attribute ("raw"); - Nibbler n (raw); - - std::string tag; - std::string sign; - if (n.getN (1, sign) && - (sign == "+" || sign == "-") && - n.getUntilEOS (tag) && - tag.find (' ') == std::string::npos) + std::vector nodes; + collect (nodes, false); + std::vector ::iterator i; + for (i = nodes.begin (); i != nodes.end (); ++i) { - t->unTag ("?"); - t->removeAllBranches (); - t->tag ("TAG"); - t->attribute ("sign", sign); - t->attribute ("tag", tag); + std::string raw = (*i)->attribute ("raw"); + Nibbler n (raw); - Tree* branch = t->addBranch (new Tree ("argTag")); - branch->attribute ("raw", "tags"); + std::string tag; + std::string sign; + if (n.getN (1, sign) && + (sign == "+" || sign == "-") && + n.getUntilEOS (tag) && + tag.find (' ') == std::string::npos) + { + (*i)->unTag ("?"); + (*i)->removeAllBranches (); + (*i)->tag ("TAG"); + (*i)->attribute ("sign", sign); + (*i)->attribute ("tag", tag); - branch = t->addBranch (new Tree ("argTag")); - branch->attribute ("raw", (sign == "+" ? "_hastag_" : "_notag_")); - branch->tag ("OP"); + Tree* branch = (*i)->addBranch (new Tree ("argTag")); + branch->attribute ("raw", "tags"); - branch = t->addBranch (new Tree ("argTag")); - branch->attribute ("raw", tag); + branch = (*i)->addBranch (new Tree ("argTag")); + branch->attribute ("raw", (sign == "+" ? "_hastag_" : "_notag_")); + branch->tag ("OP"); + + branch = (*i)->addBranch (new Tree ("argTag")); + branch->attribute ("raw", tag); + action = true; + } } + + if (action) + context.debug (_tree->dump ()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Parser.h b/src/Parser.h index 62f2a565c..1c2870b50 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -74,7 +74,7 @@ private: void findTerminator (); void findPattern (); void findSubstitution (); - void findTag (Tree*); + void findTag (); void findAttribute (Tree*); void findAttributeModifier (Tree*); void findOperator (Tree*);