Parser
- Converted all remaining methods to use collect. Now there is full recursion everywhere, which means the parse tree can be arbitrarily deep.
This commit is contained in:
@@ -193,7 +193,6 @@ Tree* Parser::parse ()
|
|||||||
findStrayModifications ();
|
findStrayModifications ();
|
||||||
|
|
||||||
findPlainArgs ();
|
findPlainArgs ();
|
||||||
// GOOD ^^^
|
|
||||||
findMissingOperators ();
|
findMissingOperators ();
|
||||||
|
|
||||||
validate ();
|
validate ();
|
||||||
@@ -276,7 +275,7 @@ bool Parser::canonicalize (
|
|||||||
// Recursively scan all nodes, depth first, and create a linear list of node
|
// Recursively scan all nodes, depth first, and create a linear list of node
|
||||||
// pointers, for simple iteration. This eliminates the need for recursion in
|
// pointers, for simple iteration. This eliminates the need for recursion in
|
||||||
// each ::find* method.
|
// each ::find* method.
|
||||||
void Parser::collect (std::vector <Tree*>& nodes, bool all, Tree* tree /* = NULL */)
|
void Parser::collect (std::vector <Tree*>& nodes, bool all, Tree* tree /* = NULL */) const
|
||||||
{
|
{
|
||||||
if (tree == NULL)
|
if (tree == NULL)
|
||||||
tree = _tree;
|
tree = _tree;
|
||||||
@@ -505,8 +504,10 @@ void Parser::getOverrides (
|
|||||||
std::string& home,
|
std::string& home,
|
||||||
File& rc)
|
File& rc)
|
||||||
{
|
{
|
||||||
|
std::vector <Tree*> nodes;
|
||||||
|
collect (nodes, false);
|
||||||
std::vector <Tree*>::iterator i;
|
std::vector <Tree*>::iterator i;
|
||||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
{
|
{
|
||||||
if ((*i)->hasTag ("RC"))
|
if ((*i)->hasTag ("RC"))
|
||||||
{
|
{
|
||||||
@@ -535,8 +536,10 @@ void Parser::getDataLocation (Path& data)
|
|||||||
if (location != "")
|
if (location != "")
|
||||||
data = location;
|
data = location;
|
||||||
|
|
||||||
|
std::vector <Tree*> nodes;
|
||||||
|
collect (nodes, false);
|
||||||
std::vector <Tree*>::iterator i;
|
std::vector <Tree*>::iterator i;
|
||||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
{
|
{
|
||||||
if ((*i)->hasTag ("CONFIG") &&
|
if ((*i)->hasTag ("CONFIG") &&
|
||||||
(*i)->attribute ("name") == "data.location")
|
(*i)->attribute ("name") == "data.location")
|
||||||
@@ -580,8 +583,11 @@ void Parser::injectDefaults ()
|
|||||||
bool found_command = false;
|
bool found_command = false;
|
||||||
bool found_sequence = false;
|
bool found_sequence = false;
|
||||||
bool found_other = false;
|
bool found_other = false;
|
||||||
|
|
||||||
|
std::vector <Tree*> nodes;
|
||||||
|
collect (nodes, true);
|
||||||
std::vector <Tree*>::iterator i;
|
std::vector <Tree*>::iterator i;
|
||||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
{
|
{
|
||||||
if ((*i)->hasTag ("BINARY"))
|
if ((*i)->hasTag ("BINARY"))
|
||||||
;
|
;
|
||||||
@@ -625,8 +631,10 @@ void Parser::injectDefaults ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string combined;
|
std::string combined;
|
||||||
|
std::vector <Tree*> nodes;
|
||||||
|
collect (nodes, false);
|
||||||
std::vector <Tree*>::iterator i;
|
std::vector <Tree*>::iterator i;
|
||||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
{
|
{
|
||||||
if (combined.length ())
|
if (combined.length ())
|
||||||
combined += ' ';
|
combined += ' ';
|
||||||
@@ -701,8 +709,10 @@ const std::string Parser::getFilterExpression ()
|
|||||||
{
|
{
|
||||||
// Construct an efficient ID/UUID clause.
|
// Construct an efficient ID/UUID clause.
|
||||||
std::string sequence = "";
|
std::string sequence = "";
|
||||||
|
std::vector <Tree*> nodes;
|
||||||
|
collect (nodes, true);
|
||||||
std::vector <Tree*>::iterator i;
|
std::vector <Tree*>::iterator i;
|
||||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
{
|
{
|
||||||
if ((*i)->hasTag ("FILTER") && ! (*i)->hasTag ("PSEUDO"))
|
if ((*i)->hasTag ("FILTER") && ! (*i)->hasTag ("PSEUDO"))
|
||||||
{
|
{
|
||||||
@@ -746,8 +756,10 @@ const std::string Parser::getFilterExpression ()
|
|||||||
const std::vector <std::string> Parser::getWords () const
|
const std::vector <std::string> Parser::getWords () const
|
||||||
{
|
{
|
||||||
std::vector <std::string> words;
|
std::vector <std::string> words;
|
||||||
std::vector <Tree*>::const_iterator i;
|
std::vector <Tree*> nodes;
|
||||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
collect (nodes, true);
|
||||||
|
std::vector <Tree*>::iterator i;
|
||||||
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
{
|
{
|
||||||
if (! (*i)->hasTag ("BINARY") &&
|
if (! (*i)->hasTag ("BINARY") &&
|
||||||
! (*i)->hasTag ("RC") &&
|
! (*i)->hasTag ("RC") &&
|
||||||
@@ -764,8 +776,10 @@ const std::vector <std::string> Parser::getWords () const
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string Parser::getLimit () const
|
std::string Parser::getLimit () const
|
||||||
{
|
{
|
||||||
std::vector <Tree*>::const_iterator i;
|
std::vector <Tree*> nodes;
|
||||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
collect (nodes, false);
|
||||||
|
std::vector <Tree*>::iterator i;
|
||||||
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
{
|
{
|
||||||
// Parser override operator.
|
// Parser override operator.
|
||||||
if ((*i)->attribute ("raw") == "--")
|
if ((*i)->attribute ("raw") == "--")
|
||||||
@@ -784,16 +798,12 @@ std::string Parser::getLimit () const
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string Parser::getCommand () const
|
std::string Parser::getCommand () const
|
||||||
{
|
{
|
||||||
std::vector <Tree*>::const_iterator i;
|
std::vector <Tree*> nodes;
|
||||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
collect (nodes, false);
|
||||||
{
|
std::vector <Tree*>::iterator i;
|
||||||
// Parser override operator.
|
for (i = nodes.begin (); i != nodes.end (); ++i)
|
||||||
if ((*i)->attribute ("raw") == "--")
|
|
||||||
break;
|
|
||||||
|
|
||||||
if ((*i)->hasTag ("CMD"))
|
if ((*i)->hasTag ("CMD"))
|
||||||
return (*i)->attribute ("canonical");
|
return (*i)->attribute ("canonical");
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
bool exactMatch (const std::string&, const std::string&) const;
|
bool exactMatch (const std::string&, const std::string&) const;
|
||||||
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
bool canonicalize (std::string&, const std::string&, const std::string&) const;
|
||||||
|
|
||||||
void collect (std::vector <Tree*>&, bool, Tree* tree = NULL);
|
void collect (std::vector <Tree*>&, bool, Tree* tree = NULL) const;
|
||||||
|
|
||||||
void findBinary ();
|
void findBinary ();
|
||||||
void resolveAliases ();
|
void resolveAliases ();
|
||||||
|
|||||||
Reference in New Issue
Block a user