- Converted ::findPattern to use recursive scan.
This commit is contained in:
Paul Beckingham 2014-08-17 01:13:01 -04:00
parent 4b47229e8f
commit 0e86233a0a
2 changed files with 22 additions and 31 deletions

View file

@ -179,7 +179,7 @@ Tree* Parser::parse ()
applyOverrides (); applyOverrides ();
findSubstitution (); findSubstitution ();
findPattern (); scan (&Parser::findPattern);
findTag (); findTag ();
scan (&Parser::findAttribute); scan (&Parser::findAttribute);
scan (&Parser::findAttributeModifier); scan (&Parser::findAttributeModifier);
@ -786,41 +786,32 @@ std::string Parser::getCommand () const
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// /pattern/ --> description ~ pattern // /pattern/ --> description ~ pattern
void Parser::findPattern () void Parser::findPattern (Tree* t)
{ {
std::vector <Tree*>::iterator i; context.debug ("findPattern");
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i) context.debug (t->dump ());
{
// Parser override operator.
if ((*i)->attribute ("raw") == "--")
break;
// Skip known args. Nibbler n (t->attribute ("raw"));
if (! (*i)->hasTag ("?"))
continue;
Nibbler n ((*i)->attribute ("raw"));
std::string pattern; std::string pattern;
if (n.getQuoted ('/', pattern) && if (n.getQuoted ('/', pattern) &&
n.depleted () && n.depleted () &&
pattern.length () > 0) pattern.length () > 0)
{ {
(*i)->unTag ("?"); t->unTag ("?");
(*i)->removeAllBranches (); t->removeAllBranches ();
(*i)->tag ("PATTERN"); t->tag ("PATTERN");
Tree* branch = (*i)->addBranch (new Tree ("argPat")); Tree* branch = t->addBranch (new Tree ("argPat"));
branch->attribute ("raw", "description"); branch->attribute ("raw", "description");
branch = (*i)->addBranch (new Tree ("argPat")); branch = t->addBranch (new Tree ("argPat"));
branch->attribute ("raw", "~"); branch->attribute ("raw", "~");
branch->tag ("OP"); branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argPat")); branch = t->addBranch (new Tree ("argPat"));
branch->attribute ("raw", pattern); branch->attribute ("raw", pattern);
branch->tag ("STRING"); branch->tag ("STRING");
} }
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

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