- Modified ::findPattern to use collect.
This commit is contained in:
Paul Beckingham 2014-08-17 12:22:03 -04:00
parent a4f558ee1c
commit 6dd359e900
2 changed files with 32 additions and 22 deletions

View file

@ -179,8 +179,8 @@ Tree* Parser::parse ()
applyOverrides (); applyOverrides ();
findSubstitution (); findSubstitution ();
findPattern ();
// GOOD ^^^ // GOOD ^^^
scan (&Parser::findPattern);
scan (&Parser::findTag); scan (&Parser::findTag);
scan (&Parser::findAttribute); scan (&Parser::findAttribute);
scan (&Parser::findAttributeModifier); scan (&Parser::findAttributeModifier);
@ -830,39 +830,49 @@ std::string Parser::getCommand () const
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// /pattern/ --> description ~ pattern // /pattern/ --> description ~ pattern
void Parser::findPattern (Tree* t) void Parser::findPattern ()
{ {
context.debug ("findPattern"); context.debug ("Parser::findPattern");
context.debug (t->dump ()); bool action = false;
Nibbler n (t->attribute ("raw")); std::vector <Tree*> nodes;
std::string pattern; collect (nodes, false);
if (n.getQuoted ('/', pattern) && std::vector <Tree*>::iterator i;
n.depleted () && for (i = nodes.begin (); i != nodes.end (); ++i)
pattern.length () > 0)
{ {
t->unTag ("?"); Nibbler n ((*i)->attribute ("raw"));
t->removeAllBranches (); std::string pattern;
t->tag ("PATTERN"); if (n.getQuoted ('/', pattern) &&
n.depleted () &&
pattern.length () > 0)
{
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("PATTERN");
Tree* branch = t->addBranch (new Tree ("argPat")); Tree* branch = (*i)->addBranch (new Tree ("argPat"));
branch->attribute ("raw", "description"); branch->attribute ("raw", "description");
branch = t->addBranch (new Tree ("argPat")); branch = (*i)->addBranch (new Tree ("argPat"));
branch->attribute ("raw", "~"); branch->attribute ("raw", "~");
branch->tag ("OP"); branch->tag ("OP");
branch = t->addBranch (new Tree ("argPat")); branch = (*i)->addBranch (new Tree ("argPat"));
branch->attribute ("raw", pattern); branch->attribute ("raw", pattern);
branch->tag ("STRING"); branch->tag ("STRING");
action = true;
}
} }
if (action)
context.debug (_tree->dump ());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// /from/to/[g] // /from/to/[g]
void Parser::findSubstitution () void Parser::findSubstitution ()
{ {
context.debug ("Parse::findSubstitution"); context.debug ("Parser::findSubstitution");
bool action = false; bool action = false;
std::vector <Tree*> nodes; std::vector <Tree*> nodes;

View file

@ -72,7 +72,7 @@ public:
private: private:
void scan (void (Parser::*callback)(Tree*), Tree* tree = NULL); void scan (void (Parser::*callback)(Tree*), Tree* tree = NULL);
void findTerminator (); void findTerminator ();
void findPattern (Tree*); void findPattern ();
void findSubstitution (); void findSubstitution ();
void findTag (Tree*); void findTag (Tree*);
void findAttribute (Tree*); void findAttribute (Tree*);