- 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,40 +786,31 @@ 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 ());
Nibbler n (t->attribute ("raw"));
std::string pattern;
if (n.getQuoted ('/', pattern) &&
n.depleted () &&
pattern.length () > 0)
{ {
// Parser override operator. t->unTag ("?");
if ((*i)->attribute ("raw") == "--") t->removeAllBranches ();
break; t->tag ("PATTERN");
// Skip known args. Tree* branch = t->addBranch (new Tree ("argPat"));
if (! (*i)->hasTag ("?")) branch->attribute ("raw", "description");
continue;
Nibbler n ((*i)->attribute ("raw")); branch = t->addBranch (new Tree ("argPat"));
std::string pattern; branch->attribute ("raw", "~");
if (n.getQuoted ('/', pattern) && branch->tag ("OP");
n.depleted () &&
pattern.length () > 0)
{
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("PATTERN");
Tree* branch = (*i)->addBranch (new Tree ("argPat")); branch = t->addBranch (new Tree ("argPat"));
branch->attribute ("raw", "description"); branch->attribute ("raw", pattern);
branch->tag ("STRING");
branch = (*i)->addBranch (new Tree ("argPat"));
branch->attribute ("raw", "~");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argPat"));
branch->attribute ("raw", pattern);
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*);