From 195fa20a480d944f433ba7dbcd5f3abc16288105 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 20 May 2014 23:49:41 -0400 Subject: [PATCH] A3t - Implemented the stubbed outline of ::findMissingOperators, for injecting 'and' or 'or' into filter expressions, where needed. --- src/A3t.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/A3t.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/A3t.cpp b/src/A3t.cpp index d8806b93c..6d2bc9d8c 100644 --- a/src/A3t.cpp +++ b/src/A3t.cpp @@ -149,6 +149,7 @@ Tree* A3t::parse () findModifications (); findPlainArgs (); + findMissingOperators (); validate (); @@ -1361,6 +1362,41 @@ void A3t::findPlainArgs () } } +//////////////////////////////////////////////////////////////////////////////// +void A3t::findMissingOperators () +{ + std::vector ::iterator prev = _tree->_branches.begin (); + std::vector ::iterator i; + for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i) + { + if ((*i)->hasTag ("FILTER") && ! (*i)->hasTag ("PSEUDO")) + { + // Two consecutive FILTER, non-OP arguments that are not "(" or ")" need + // an "and" operator inserted between them. + // + // ) --> ) and + // ( --> ( + // ) ( --> ) and ( + // --> and + // + if (i != prev && + (((*prev)->hasTag ("FILTER") && ! (*prev)->hasTag ("OP")) || (*prev)->attribute ("raw") == ")") && + (! (*i)->hasTag ("OP") || (*i)->attribute ("raw") == "(")) + { + std::cout << "# missingOperator '" + << (*prev)->attribute ("raw") + << " " + << (*i)->attribute ("raw") + << "' --> '" + << (*prev)->attribute ("raw") + << " and " + << (*i)->attribute ("raw") + << "'\n"; + } + } + } +} + //////////////////////////////////////////////////////////////////////////////// // Validate the parse tree. void A3t::validate () diff --git a/src/A3t.h b/src/A3t.h index 4f2b3795a..fee0f5538 100644 --- a/src/A3t.h +++ b/src/A3t.h @@ -72,6 +72,7 @@ private: void findFilter (); void findModifications (); void findPlainArgs (); + void findMissingOperators (); void validate (); private: