- 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,35 +860,45 @@ 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;
Nibbler n (raw); collect (nodes, false);
std::vector <Tree*>::iterator i;
std::string from; for (i = nodes.begin (); i != nodes.end (); ++i)
std::string to;
bool global = false;
if (n.getQuoted ('/', from) &&
n.backN () &&
n.getQuoted ('/', to))
{ {
if (n.skip ('g')) std::string raw = (*i)->attribute ("raw");
global = true; Nibbler n (raw);
if (n.depleted () && std::string from;
!Directory (raw).exists ()) std::string to;
bool global = false;
if (n.getQuoted ('/', from) &&
n.backN () &&
n.getQuoted ('/', to))
{ {
t->unTag ("?"); if (n.skip ('g'))
t->removeAllBranches (); global = true;
t->tag ("SUBSTITUTION");
t->attribute ("from", from); if (n.depleted () &&
t->attribute ("to", to); !Directory (raw).exists ())
t->attribute ("global", global ? 1 : 0); {
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("SUBSTITUTION");
(*i)->attribute ("from", from);
(*i)->attribute ("to", to);
(*i)->attribute ("global", global ? 1 : 0);
action = true;
}
} }
} }
if (action)
context.debug (_tree->dump ());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

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*);