From a4d908d8b2a7b80a024a6b5541b81daf81df1c38 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 26 May 2014 14:18:26 -0400 Subject: [PATCH] Parser - Added exact match shortcut. - Changed order of command matching to reduce changes of the log/logo problem. - Corrected logic where an "else if" should have been an "if". - Removed commented-out diagnostics. --- src/Parser.cpp | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index 1beee8a12..9d10e70e8 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -180,7 +180,16 @@ bool Parser::canonicalize ( std::vector options; std::multimap ::const_iterator e; for (e = c.first; e != c.second; ++e) + { + // Shortcut: if an exact match is found, success. + if (value == e->second) + { + canonicalized = value; + return true; + } + options.push_back (e->second); + } // Match against the options, throw away results. std::vector matches; @@ -269,16 +278,14 @@ void Parser::findCommand () if (! (*i)->hasTag ("?")) continue; -/* - if (canonicalize (command, "report", (*i)->attribute ("raw"))) + if (canonicalize (command, "writecmd", (*i)->attribute ("raw"))) { (*i)->unTag ("?"); (*i)->tag ("CMD"); - (*i)->tag ("REPORT"); + (*i)->tag ("WRITECMD"); (*i)->attribute ("canonical", command); break; } -*/ else if (canonicalize (command, "readcmd", (*i)->attribute ("raw"))) { @@ -289,15 +296,6 @@ void Parser::findCommand () break; } - else if (canonicalize (command, "writecmd", (*i)->attribute ("raw"))) - { - (*i)->unTag ("?"); - (*i)->tag ("CMD"); - (*i)->tag ("WRITECMD"); - (*i)->attribute ("canonical", command); - break; - } - else if (canonicalize (command, "helper", (*i)->attribute ("raw"))) { (*i)->unTag ("?"); @@ -306,17 +304,6 @@ void Parser::findCommand () (*i)->attribute ("canonical", command); break; } - -/* - else if (canonicalize (command, "specialcmd", (*i)->attribute ("raw"))) - { - (*i)->unTag ("?"); - (*i)->tag ("CMD"); - (*i)->tag ("SPECIALCMD"); - (*i)->attribute ("canonical", command); - break; - } -*/ } } @@ -1468,8 +1455,6 @@ void Parser::validate () std::vector ::iterator i; for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i) if ((*i)->hasTag ("?")) - //throw std::string ("Unrecognized argument '") + (*i)->attribute ("raw") + "'"; - //std::cout << "Unrecognized argument '" << (*i)->attribute ("raw") << "'\n"; context.debug ("Unrecognized argument '" + (*i)->attribute ("raw") + "'"); // TODO Any RC node must have a root/+RC @file that exists.