- Modified ::findTag to use collect.
This commit is contained in:
Paul Beckingham 2014-08-17 12:25:08 -04:00
parent 6dd359e900
commit ed07e47135
2 changed files with 36 additions and 26 deletions

View file

@ -180,8 +180,8 @@ Tree* Parser::parse ()
findSubstitution (); findSubstitution ();
findPattern (); findPattern ();
findTag ();
// GOOD ^^^ // GOOD ^^^
scan (&Parser::findTag);
scan (&Parser::findAttribute); scan (&Parser::findAttribute);
scan (&Parser::findAttributeModifier); scan (&Parser::findAttributeModifier);
scan (&Parser::findOperator); scan (&Parser::findOperator);
@ -913,37 +913,47 @@ void Parser::findSubstitution ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// +tag // +tag
void Parser::findTag (Tree* t) void Parser::findTag ()
{ {
context.debug ("findTag"); context.debug ("Parser::findTag");
context.debug (t->dump ()); bool action = false;
std::string raw = t->attribute ("raw"); std::vector <Tree*> nodes;
Nibbler n (raw); collect (nodes, false);
std::vector <Tree*>::iterator i;
std::string tag; for (i = nodes.begin (); i != nodes.end (); ++i)
std::string sign;
if (n.getN (1, sign) &&
(sign == "+" || sign == "-") &&
n.getUntilEOS (tag) &&
tag.find (' ') == std::string::npos)
{ {
t->unTag ("?"); std::string raw = (*i)->attribute ("raw");
t->removeAllBranches (); Nibbler n (raw);
t->tag ("TAG");
t->attribute ("sign", sign);
t->attribute ("tag", tag);
Tree* branch = t->addBranch (new Tree ("argTag")); std::string tag;
branch->attribute ("raw", "tags"); 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")); Tree* branch = (*i)->addBranch (new Tree ("argTag"));
branch->attribute ("raw", (sign == "+" ? "_hastag_" : "_notag_")); branch->attribute ("raw", "tags");
branch->tag ("OP");
branch = t->addBranch (new Tree ("argTag")); branch = (*i)->addBranch (new Tree ("argTag"));
branch->attribute ("raw", tag); 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 ());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -74,7 +74,7 @@ private:
void findTerminator (); void findTerminator ();
void findPattern (); void findPattern ();
void findSubstitution (); void findSubstitution ();
void findTag (Tree*); void findTag ();
void findAttribute (Tree*); void findAttribute (Tree*);
void findAttributeModifier (Tree*); void findAttributeModifier (Tree*);
void findOperator (Tree*); void findOperator (Tree*);