From 5ee1aa8c9c1f81815e6edec65f1bcef1b1851ea5 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 4 Jun 2016 10:33:32 -0400 Subject: [PATCH] CLI: Added ::identifyIds --- src/CLI.cpp | 37 ++++++++++++++++++++++++++++++------- src/CLI.h | 1 + 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index df044793..0ce9a430 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -113,13 +114,14 @@ std::string A2::dump () const std::string tags; for (auto& tag : _tags) { - if (tag == "BINARY") tags += "\033[1;37;44m" + tag + "\033[0m "; - 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 if (tag == "CONFIG") tags += "\033[1;37;101m" + tag + "\033[0m "; - else tags += "\033[32m" + tag + "\033[0m "; + if (tag == "BINARY") tags += "\033[1;37;44m" + tag + "\033[0m "; + 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 if (tag == "CONFIG") tags += "\033[1;37;101m" + tag + "\033[0m "; + else if (tag == "ID") tags += "\033[38;5;7m\033[48;5;34m" + tag + "\033[0m "; + else tags += "\033[32m" + tag + "\033[0m "; } return output + " " + atts + tags; @@ -387,6 +389,27 @@ void CLI::identifyOverrides () } } +//////////////////////////////////////////////////////////////////////////////// +// Scan all arguments and identify instances of '@'. +void CLI::identifyIds () +{ + for (auto& a : _args) + { + if (a._lextype == Lexer::Type::word) + { + Pig pig (a.attribute ("raw")); + int digits; + if (pig.skipLiteral ("@") && + pig.getDigits (digits) && + pig.eos ()) + { + a.tag ("ID"); + a.attribute ("value", digits); + } + } + } +} + //////////////////////////////////////////////////////////////////////////////// // Scan all arguments and canonicalize names that need it. void CLI::canonicalizeNames () diff --git a/src/CLI.h b/src/CLI.h index ab4625f5..96e39d32 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -70,6 +70,7 @@ private: void handleArg0 (); void lexArguments (); void identifyOverrides (); + void identifyIds (); void canonicalizeNames (); void identifyFilter (); bool exactMatch (const std::string&, const std::string&) const;