- 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. // Add an arg for every word from std::cin.
// //
@@ -514,11 +524,12 @@ Tree* A3t::captureFirst (const std::string& arg)
t->_trunk = _tree; t->_trunk = _tree;
std::vector <Tree*>::iterator i = _tree->_branches.begin (); 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); _tree->_branches.insert (i, t);
findCommand ();
findCommand ();
return t; return t;
} }

View File

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