From 2770f0388c2b6f1efd6b91155b18aeee330394de Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 26 Apr 2014 14:47:53 -0700 Subject: [PATCH] A3t - Stubbed ::patchInfix to insert missing and implied logical operators. --- src/A3t.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- src/A3t.h | 3 ++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/A3t.cpp b/src/A3t.cpp index ffb7d2519..16367780c 100644 --- a/src/A3t.cpp +++ b/src/A3t.cpp @@ -517,18 +517,16 @@ Tree* A3t::captureFirst (const std::string& arg) } //////////////////////////////////////////////////////////////////////////////// -const std::string A3t::getFilterExpression () const +const std::string A3t::getFilterExpression () { - // Locate and extract the filter elements. - std::string filter = ""; - std::vector ::iterator i; - for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i) - { - // TODO Insert implicit "and", "(" and ")" operators. - } + // Insert implicit "and", "(" and ")" operators. + patchInfix (); // TODO Construct an efficient ID/UUID clause. + // Locate and extract the filter elements. + std::string filter = ""; + std::vector ::iterator i; for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i) { if ((*i)->hasTag ("FILTER") && ! (*i)->hasTag ("PSEUDO")) @@ -1080,6 +1078,45 @@ void A3t::findModifications () } } +//////////////////////////////////////////////////////////////////////////////// +// Insert 'and' operators between adjacent non-operators. +// +// ) --> ) and +// ( --> ( +// ) ( --> ) and ( +// --> and +// +void A3t::patchInfix () +{ +/* + if (input.size () == 1) + return input; + + Arg previous ("?", Arg::cat_op); + + A3 modified; + modified._limit = input._limit; + + std::vector ::const_iterator arg; + for (arg = input.begin (); arg != input.end (); ++arg) + { + // Old-style filters need 'and' conjunctions. + if ((previous._category != Arg::cat_op || previous._raw == ")") && + (arg->_category != Arg::cat_op || arg->_raw == "(")) + { + modified.push_back (Arg ("and", Arg::cat_op)); + } + + // Now insert the adjacent non-operator. + modified.push_back (*arg); + previous = *arg; + } + + modified.dump ("A3::infix"); + return modified; +*/ +} + //////////////////////////////////////////////////////////////////////////////// // Validate the parse tree. void A3t::validate () diff --git a/src/A3t.h b/src/A3t.h index 8a050890b..ef314dbc9 100644 --- a/src/A3t.h +++ b/src/A3t.h @@ -57,7 +57,7 @@ public: void injectDefaults (); Tree* captureFirst (const std::string&); - const std::string getFilterExpression () const; + const std::string getFilterExpression (); const std::vector getWords () const; // TODO Extract modifications @@ -71,6 +71,7 @@ private: void findOperator (); void findFilter (); void findModifications (); + void patchInfix (); void validate (); private: