- Converted ::findSubstitution to use collect.
This commit is contained in:
Paul Beckingham 2014-08-17 12:18:35 -04:00
parent 50ac189693
commit a4f558ee1c
2 changed files with 35 additions and 25 deletions

View file

@ -173,13 +173,13 @@ Tree* Parser::parse ()
{ {
findBinary (); findBinary ();
findTerminator (); findTerminator ();
// GOOD ^^^
resolveAliases (); resolveAliases ();
findOverrides (); findOverrides ();
applyOverrides (); applyOverrides ();
scan (&Parser::findSubstitution); findSubstitution ();
// GOOD ^^^
scan (&Parser::findPattern); scan (&Parser::findPattern);
scan (&Parser::findTag); scan (&Parser::findTag);
scan (&Parser::findAttribute); scan (&Parser::findAttribute);
@ -860,12 +860,17 @@ void Parser::findPattern (Tree* t)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// /from/to/[g] // /from/to/[g]
void Parser::findSubstitution (Tree* t) void Parser::findSubstitution ()
{ {
context.debug ("findSubstitution"); context.debug ("Parse::findSubstitution");
context.debug (t->dump ()); bool action = false;
std::string raw = t->attribute ("raw"); std::vector <Tree*> nodes;
collect (nodes, false);
std::vector <Tree*>::iterator i;
for (i = nodes.begin (); i != nodes.end (); ++i)
{
std::string raw = (*i)->attribute ("raw");
Nibbler n (raw); Nibbler n (raw);
std::string from; std::string from;
@ -881,16 +886,21 @@ void Parser::findSubstitution (Tree* t)
if (n.depleted () && if (n.depleted () &&
!Directory (raw).exists ()) !Directory (raw).exists ())
{ {
t->unTag ("?"); (*i)->unTag ("?");
t->removeAllBranches (); (*i)->removeAllBranches ();
t->tag ("SUBSTITUTION"); (*i)->tag ("SUBSTITUTION");
t->attribute ("from", from); (*i)->attribute ("from", from);
t->attribute ("to", to); (*i)->attribute ("to", to);
t->attribute ("global", global ? 1 : 0); (*i)->attribute ("global", global ? 1 : 0);
action = true;
} }
} }
} }
if (action)
context.debug (_tree->dump ());
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// +tag // +tag
void Parser::findTag (Tree* t) void Parser::findTag (Tree* t)

View file

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