- Implemented ::scan, which iterates over parse tree nodes and calls back.
  This method skips parent nodes, terminated nodes, and nodes without the '?'
  tag.
This commit is contained in:
Paul Beckingham 2014-08-16 23:53:22 -04:00
parent 1a17aac77b
commit 314ac28a0f
2 changed files with 40 additions and 0 deletions

View file

@ -269,6 +269,45 @@ bool Parser::canonicalize (
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Experimental method to iterate over nodes, and callback, which is essentially
// a co-routine implementation.
void Parser::scan (void (Parser::*callback) (Tree*))
{
std::vector <Tree*>::iterator i;
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
{
if ((*i)->_branches.size ())
{
std::vector <Tree*>::iterator b;
for (b = (*i)->_branches.begin (); b != (*i)->_branches.end (); ++b)
{
// Parser override operator.
if ((*b)->attribute ("raw") == "--")
break;
// Skip known args.
if (! (*b)->hasTag ("?"))
continue;
(this->*callback) (*b);
}
}
else
{
// Parser override operator.
if ((*i)->attribute ("raw") == "--")
break;
// Skip known args.
if (! (*i)->hasTag ("?"))
continue;
(this->*callback) (*i);
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Locate and tag the binary.
void Parser::findBinary ()