From 9ea8f9dd8d8671cd5deedc6b15cc3e793bb67787 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 15 Apr 2016 19:31:58 -0400 Subject: [PATCH] CLI: Added ::identifyFilter --- src/CLI.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/CLI.h | 1 + 2 files changed, 41 insertions(+) diff --git a/src/CLI.cpp b/src/CLI.cpp index 6d55beb9..b9ddcae3 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -109,6 +109,7 @@ std::string A2::dump () const else if (tag == "CMD") tags += "\033[1;37;46m" + tag + "\033[0m "; else if (tag == "EXT") tags += "\033[1;37;42m" + tag + "\033[0m "; else if (tag == "HINT") tags += "\033[1;37;43m" + tag + "\033[0m "; + else if (tag == "FILTER") tags += "\033[1;37;45m" + tag + "\033[0m "; else tags += "\033[32m" + tag + "\033[0m "; } @@ -227,6 +228,7 @@ void CLI::analyze () handleArg0 (); lexArguments (); canonicalizeNames (); + identifyFilter (); } //////////////////////////////////////////////////////////////////////////////// @@ -369,6 +371,44 @@ void CLI::canonicalizeNames () } } +//////////////////////////////////////////////////////////////////////////////// +// Locate arguments that are part of a filter. +void CLI::identifyFilter () +{ + for (auto& a : _args) + { + auto raw = a.attribute ("raw"); + + if (a.hasTag ("HINT")) + a.tag ("FILTER"); + + else if (a._lextype == Lexer::Type::date || + a._lextype == Lexer::Type::duration) + { + a.tag ("FILTER"); + } + + else if (raw == "from" || + raw == "since" || + raw == "to" || + raw == "until" || + raw == "-" || + raw == "for") + { + a.tag ("FILTER"); + a.tag ("KEYWORD"); + } + + else if (! a.hasTag ("CMD") && + ! a.hasTag ("EXT") && + ! a.hasTag ("BINARY")) + { + a.tag ("FILTER"); + a.tag ("TAG"); + } + } +} + //////////////////////////////////////////////////////////////////////////////// // Search for exact 'value' in _entities category. bool CLI::exactMatch ( diff --git a/src/CLI.h b/src/CLI.h index 2e5c674c..a974fd4b 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -69,6 +69,7 @@ private: void handleArg0 (); void lexArguments (); void canonicalizeNames (); + void identifyFilter (); bool exactMatch (const std::string&, const std::string&) const; public: