- Added ::clear method.
- Handles ::captureFirst with an empty tree.
This commit is contained in:
Paul Beckingham 2014-04-25 22:31:52 -07:00
parent 74cfc972fc
commit b5bd3e44c8
2 changed files with 14 additions and 2 deletions

View file

@ -76,6 +76,16 @@ void A3t::initialize (int argc, const char** argv)
}
}
////////////////////////////////////////////////////////////////////////////////
void A3t::clear ()
{
delete _tree;
_tree = new Tree ("root");
if (! _tree)
throw std::string ("Failed to allocate memory for parse tree.");
}
////////////////////////////////////////////////////////////////////////////////
// Add an arg for every word from std::cin.
//
@ -514,11 +524,12 @@ Tree* A3t::captureFirst (const std::string& arg)
t->_trunk = _tree;
std::vector <Tree*>::iterator i = _tree->_branches.begin ();
i++; // Walk past the binary.
if (i != _tree->_branches.end ())
i++; // Walk past the binary.
_tree->_branches.insert (i, t);
findCommand ();
findCommand ();
return t;
}

View file

@ -38,6 +38,7 @@ public:
A3t ();
~A3t ();
void initialize (int, const char**);
void clear ();
void appendStdin ();
Tree* tree ();
Tree* parse ();