- Converted ::findTerminator to use collect.
This commit is contained in:
Paul Beckingham 2014-08-17 11:56:34 -04:00
parent b84736a05f
commit d1e38a7843
2 changed files with 34 additions and 19 deletions

View file

@ -172,7 +172,8 @@ Tree* Parser::tree ()
Tree* Parser::parse () Tree* Parser::parse ()
{ {
findBinary (); findBinary ();
scan (&Parser::findTerminator); findTerminator ();
// GOOD ^^^
resolveAliases (); resolveAliases ();
findOverrides (); findOverrides ();
@ -368,29 +369,43 @@ void Parser::findBinary ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// The parser override operator terminates all subsequent cleverness, leaving // The parser override operator terminates all subsequent cleverness, leaving
// all args in the raw state. // all args in the raw state.
void Parser::findTerminator (Tree* t) void Parser::findTerminator ()
{
context.debug ("Parser::findTerminator");
bool found = false;
bool action = false;
std::vector <Tree*> nodes;
collect (nodes, false);
std::vector <Tree*>::iterator i;
for (i = nodes.begin (); i != nodes.end (); ++i)
{ {
// Mark the terminator. // Mark the terminator.
static bool found = false;
if (! found && if (! found &&
t->attribute ("raw") == "--") (*i)->attribute ("raw") == "--")
{ {
t->unTag ("?"); (*i)->unTag ("?");
t->removeAllBranches (); (*i)->removeAllBranches ();
t->tag ("TERMINATOR"); (*i)->tag ("TERMINATOR");
found = true; found = true;
action = true;
} }
// Mark subsequent nodes. // Mark subsequent nodes.
else if (found) else if (found)
{ {
t->unTag ("?"); (*i)->unTag ("?");
t->removeAllBranches (); (*i)->removeAllBranches ();
t->tag ("WORD"); (*i)->tag ("WORD");
t->tag ("TERMINATED"); (*i)->tag ("TERMINATED");
action = true;
} }
} }
if (action)
context.debug (_tree->dump ());
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TODO This is not recusive, and needs to be. // TODO This is not recusive, and needs to be.
void Parser::resolveAliases () void Parser::resolveAliases ()

View file

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