From 8afb39dea680768dde9caa0bc79993b5c13767d6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 15 Oct 2014 07:34:29 -0400 Subject: [PATCH] CLI - Implemented ::unsweetenAtts to resolve syntactic sugar to an expression. --- src/CLI.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/CLI.h | 1 + 2 files changed, 88 insertions(+) diff --git a/src/CLI.cpp b/src/CLI.cpp index f7c40b877..308f497da 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -291,6 +291,7 @@ const std::string CLI::getFilter () { // Remove all the syntactic sugar. unsweetenTags (); + unsweetenAtts (); // TODO all the other types: att, attmod, pattern, id, uuid ... std::string filter = ""; @@ -542,6 +543,92 @@ void CLI::unsweetenTags () _args = reconstructed; } +//////////////////////////////////////////////////////////////////////////////// +// :['"][]['"] --> name = value +void CLI::unsweetenAtts () +{ + std::vector reconstructed; + std::vector ::iterator a; + for (a = _args.begin (); a != _args.end (); ++a) + { + // Look for a valid attribute name. + bool found = false; + Nibbler n (a->attribute ("raw")); + std::string name; + if (n.getName (name) && + name.length ()) + { + if (n.skip (':')) + { + std::string value; + if (n.getQuoted ('"', value) || + n.getQuoted ('\'', value) || + n.getUntilEOS (value) || + n.depleted ()) + { + if (value == "") + value = "''"; + + std::string canonical; + if (canonicalize (canonical, "uda", name)) + { + A left ("argUDA", name); + left.attribute ("canonical", canonical); + left.tag ("UDA"); + left.tag ("MODIFIABLE"); + left.tag ("FILTER"); + reconstructed.push_back (left); + found = true; + } + + else if (canonicalize (canonical, "pseudo", name)) + { + A left ("argUDA", name); + left.attribute ("canonical", canonical); + left.tag ("PSEUDO"); + left.tag ("FILTER"); + reconstructed.push_back (left); + found = true; + } + + else if (canonicalize (canonical, "attribute", name)) + { + A lhs ("argAtt", name); + lhs.attribute ("canonical", canonical); + lhs.tag ("ATTRIBUTE"); + lhs.tag ("FILTER"); + + std::map ::const_iterator col; + col = context.columns.find (canonical); + if (col != context.columns.end () && + col->second->modifiable ()) + { + lhs.tag ("MODIFIABLE"); + } + + A op ("argAtt", "="); + op.tag ("OP"); + op.tag ("FILTER"); + + A rhs ("argAtt", value); + rhs.tag ("FILTER"); + + reconstructed.push_back (lhs); + reconstructed.push_back (op); + reconstructed.push_back (rhs); + found = true; + } + } + } + } + + if (!found) + reconstructed.push_back (*a); + } + + _args = reconstructed; +} + //////////////////////////////////////////////////////////////////////////////// void CLI::dump (const std::string& label) const { diff --git a/src/CLI.h b/src/CLI.h index 402390948..0d8bebcca 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -77,6 +77,7 @@ private: bool exactMatch (const std::string&, const std::string&) const; bool canonicalize (std::string&, const std::string&, const std::string&) const; void unsweetenTags (); + void unsweetenAtts (); void dump (const std::string&) const; public: