diff --git a/src/Parser.cpp b/src/Parser.cpp index a5d526d56..51433aed4 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -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 nodes; + collect (nodes, collectTerminated); + std::vector ::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 () { diff --git a/src/Parser.h b/src/Parser.h index 1069288fb..9573e15af 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -84,6 +84,7 @@ private: void findModifications (); void findStrayModifications (); void findPlainArgs (); + void findFilterSubst (); void findMissingOperators (); bool insertOr (); bool insertAnd ();