- Locates mis-parsed SUBSTITUTIONS in FILTER, and downgrades to PATTERN.
This commit is contained in:
Paul Beckingham 2014-10-11 11:24:07 -04:00
parent 963e79696b
commit 03a3b41254
2 changed files with 53 additions and 0 deletions

View file

@ -201,6 +201,7 @@ Tree* Parser::parse ()
findStrayModifications ();
findPlainArgs ();
findFilterSubst ();
findMissingOperators ();
validate ();
@ -1670,6 +1671,57 @@ void Parser::findPlainArgs ()
}
}
////////////////////////////////////////////////////////////////////////////////
// Look for FILTER and downgrate SUBSTITUTION --> PATTERN.
void Parser::findFilterSubst ()
{
bool action = true;
do
{
action = false;
std::vector <Tree*> nodes;
collect (nodes, collectTerminated);
std::vector <Tree*>::iterator i;
for (i = nodes.begin (); i != nodes.end (); ++i)
{
if ((*i)->hasTag ("FILTER") &&
(*i)->hasTag ("SUBSTITUTION"))
{
std::string raw = (*i)->attribute ("raw");
if (raw[0] == '/' && raw[raw.length () - 1] == '/')
{
std::string pattern = raw.substr (1, raw.length () - 2);
(*i)->unTag ("SUBSTITUTION");
(*i)->removeAttribute ("from");
(*i)->removeAttribute ("to");
(*i)->removeAttribute ("global");
(*i)->removeAllBranches ();
Tree* branch = (*i)->addBranch (new Tree ("argPat"));
branch->attribute ("raw", "description");
branch = (*i)->addBranch (new Tree ("argPat"));
branch->attribute ("raw", "~");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argPat"));
branch->attribute ("raw", pattern);
branch->tag ("STRING");
(*i)->tag ("PATTERN");
action = true;
break;
}
}
}
}
while (action);
}
////////////////////////////////////////////////////////////////////////////////
void Parser::findMissingOperators ()
{

View file

@ -84,6 +84,7 @@ private:
void findModifications ();
void findStrayModifications ();
void findPlainArgs ();
void findFilterSubst ();
void findMissingOperators ();
bool insertOr ();
bool insertAnd ();