From a82927cb54f0995f2de21627d35c47a7f7efc062 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 4 Sep 2015 10:47:44 -0400 Subject: [PATCH] CLI2: Refactored some of ::prepareFilter into ::categorizeArgs --- src/CLI2.cpp | 126 +++++++++++++++++++++++++++------------------------ src/CLI2.h | 1 + 2 files changed, 67 insertions(+), 60 deletions(-) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index 1993ef304..a5a9bf31f 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -620,66 +620,8 @@ void CLI2::prepareFilter () _id_ranges.clear (); _uuid_list.clear (); - // Context is only applied for commands that request it. - std::string command = getCommand (); - Command* cmd = context.commands[command]; - if (cmd && cmd->uses_context ()) - addContextFilter (); - - // Classify FILTER, MODIFICATION and MISCELLANEOUS args, based on CMD DNA. - bool changes = false; - bool afterCommand = false; - - for (auto& a : _args) - { - if (a._lextype == Lexer::Type::separator) - continue; - - if (a.hasTag ("CMD")) - { - afterCommand = true; - } - else if (a.hasTag ("BINARY") || - a.hasTag ("RC") || - a.hasTag ("CONFIG")) - { - // NOP. - } - - // All MODIFICATION args appear after the command. - else if (cmd && - cmd->accepts_modifications () && - ! cmd->accepts_miscellaneous () && - afterCommand) - { - a.tag ("MODIFICATION"); - changes = true; - } - - else if (cmd && - cmd->accepts_miscellaneous () && - ! cmd->accepts_modifications () && - (afterCommand || - ! cmd->accepts_filter ())) - { - a.tag ("MISCELLANEOUS"); - changes = true; - } - - else if (cmd && - cmd->accepts_filter () && - (! afterCommand || - (! cmd->accepts_modifications () && - ! cmd->accepts_miscellaneous ()))) - { - a.tag ("FILTER"); - changes = true; - } - } - - if (changes && - context.config.getInteger ("debug.parser") >= 3) - context.debug (dump ("CLI2::prepareFilter")); + // Determine arg types: FILTER, MODIFICATION, MISCELLANEOUS. + categorizeArgs (); // Remove all the syntactic sugar for FILTERs. lexFilterArgs (); @@ -964,6 +906,70 @@ void CLI2::canonicalizeNames () context.debug (dump ("CLI2::analyze canonicalizeNames")); } +//////////////////////////////////////////////////////////////////////////////// +// Categorize FILTER, MODIFICATION and MISCELLANEOUS args, based on CMD DNA. +void CLI2::categorizeArgs () +{ + // Context is only applied for commands that request it. + std::string command = getCommand (); + Command* cmd = context.commands[command]; + if (cmd && cmd->uses_context ()) + addContextFilter (); + + bool changes = false; + bool afterCommand = false; + for (auto& a : _args) + { + if (a._lextype == Lexer::Type::separator) + continue; + + if (a.hasTag ("CMD")) + { + afterCommand = true; + } + else if (a.hasTag ("BINARY") || + a.hasTag ("RC") || + a.hasTag ("CONFIG")) + { + // NOP. + } + + // All MODIFICATION args appear after the command. + else if (cmd && + cmd->accepts_modifications () && + ! cmd->accepts_miscellaneous () && + afterCommand) + { + a.tag ("MODIFICATION"); + changes = true; + } + + else if (cmd && + cmd->accepts_miscellaneous () && + ! cmd->accepts_modifications () && + (afterCommand || + ! cmd->accepts_filter ())) + { + a.tag ("MISCELLANEOUS"); + changes = true; + } + + else if (cmd && + cmd->accepts_filter () && + (! afterCommand || + (! cmd->accepts_modifications () && + ! cmd->accepts_miscellaneous ()))) + { + a.tag ("FILTER"); + changes = true; + } + } + + if (changes && + context.config.getInteger ("debug.parser") >= 3) + context.debug (dump ("CLI2::analyze categorizeArgs")); +} + //////////////////////////////////////////////////////////////////////////////// // Scan all arguments and if any are an exact match for a command name, then // tag as CMD. If an argument is an exact match for an attribute, despite being diff --git a/src/CLI2.h b/src/CLI2.h index f4890ff0b..fc0a441a6 100644 --- a/src/CLI2.h +++ b/src/CLI2.h @@ -90,6 +90,7 @@ private: void demotion (); void aliasExpansion (); void canonicalizeNames (); + void categorizeArgs (); bool findCommand (); bool exactMatch (const std::string&, const std::string&) const; void desugarFilterTags ();