- Converted ::findSubstitution to use recursive scan.
This commit is contained in:
Paul Beckingham 2014-08-17 01:17:05 -04:00
parent 0e86233a0a
commit c681017961
2 changed files with 25 additions and 34 deletions

View file

@ -178,7 +178,7 @@ Tree* Parser::parse ()
findOverrides (); findOverrides ();
applyOverrides (); applyOverrides ();
findSubstitution (); scan (&Parser::findSubstitution);
scan (&Parser::findPattern); scan (&Parser::findPattern);
findTag (); findTag ();
scan (&Parser::findAttribute); scan (&Parser::findAttribute);
@ -816,20 +816,12 @@ void Parser::findPattern (Tree* t)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// /from/to/[g] // /from/to/[g]
void Parser::findSubstitution () void Parser::findSubstitution (Tree* t)
{ {
std::vector <Tree*>::iterator i; context.debug ("findSubstitution");
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. std::string raw = t->attribute ("raw");
if (! (*i)->hasTag ("?"))
continue;
std::string raw = (*i)->attribute ("raw");
Nibbler n (raw); Nibbler n (raw);
std::string from; std::string from;
@ -845,13 +837,12 @@ void Parser::findSubstitution ()
if (n.depleted () && if (n.depleted () &&
!Directory (raw).exists ()) !Directory (raw).exists ())
{ {
(*i)->unTag ("?"); t->unTag ("?");
(*i)->removeAllBranches (); t->removeAllBranches ();
(*i)->tag ("SUBSTITUTION"); t->tag ("SUBSTITUTION");
(*i)->attribute ("from", from); t->attribute ("from", from);
(*i)->attribute ("to", to); t->attribute ("to", to);
(*i)->attribute ("global", global ? 1 : 0); t->attribute ("global", global ? 1 : 0);
}
} }
} }
} }

View file

@ -71,7 +71,7 @@ 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 (Tree*); void findPattern (Tree*);
void findSubstitution (); void findSubstitution (Tree*);
void findTag (); void findTag ();
void findAttribute (Tree*); void findAttribute (Tree*);
void findAttributeModifier (Tree*); void findAttributeModifier (Tree*);