From 8429df3b5c4787a2d2aeee6f5f8df1900ca79a83 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 30 Aug 2013 13:42:43 -0700 Subject: [PATCH] Command Location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Locateѕ, cnaonicalized and categorizes first command. --- doc/misc/parser/README | 22 ++++++++--------- src/parser/A3t.cpp | 54 ++++++++++++++++++++++++++++++++++++++++-- src/parser/A3t.h | 3 +++ src/parser/args.cpp | 14 ++++++++--- 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/doc/misc/parser/README b/doc/misc/parser/README index d95a2e4cf..d094ae94f 100644 --- a/doc/misc/parser/README +++ b/doc/misc/parser/README @@ -80,15 +80,15 @@ The eval needs of this command are: The parse tree should be: +- add COMMAND - +- "one" WORD - +- attr - | +- due ATTRIBUTE - | +- expr - | | + "eoy" LITERAL DATE - +- attr - +- wait ATTRIBUTE - +- expr - += "due" DOM DATE - += "-" OP - += "2wks" LITERAL DURATION + +- "one" WORD + +- attr + | +- due ATTRIBUTE + | +- expr + | | + "eoy" LITERAL DATE + +- attr + +- wait ATTRIBUTE + +- expr + += "due" DOM DATE + += "-" OP + += "2wks" LITERAL DURATION diff --git a/src/parser/A3t.cpp b/src/parser/A3t.cpp index 6ddcb7841..9c4e5353b 100644 --- a/src/parser/A3t.cpp +++ b/src/parser/A3t.cpp @@ -43,7 +43,7 @@ A3t::A3t (int argc, char** argv) { Tree* branch = _tree->addBranch (new Tree (format ("arg{1}", i))); branch->attribute ("raw", argv[i]); - branch->tag ("original"); + branch->tag ("ORIGINAL"); } } @@ -55,6 +55,8 @@ A3t::~A3t () //////////////////////////////////////////////////////////////////////////////// Tree* A3t::parse () { + findCommand (); + return _tree; } @@ -83,7 +85,55 @@ bool A3t::canonicalize ( // Match against the options, throw away results. std::vector matches; - return autoComplete (canonicalized, options, matches, minimumMatchLength) == 1 ? true : false; + if (autoComplete (value, options, matches, minimumMatchLength) == 1) + { +// for (auto& i: matches) +// std::cout << "match: " << i << "\n"; + + canonicalized = matches[0]; + return true; + } + + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// Walk the top-level tree branches, looking for the first raw value that +// autoCompletes to a valid command/report. +void A3t::findCommand () +{ + std::string command; + for (int i = 0; i < _tree->branches (); ++i) + { + if (canonicalize (command, "report", (*_tree)[i]->attribute ("raw"))) + { + (*_tree)[i]->attribute ("canonical", command); + (*_tree)[i]->tag ("REPORT"); + (*_tree)[i]->tag ("CMD"); + } + + else if (canonicalize (command, "readcmd", (*_tree)[i]->attribute ("raw"))) + { + (*_tree)[i]->attribute ("canonical", command); + (*_tree)[i]->tag ("READCMD"); + (*_tree)[i]->tag ("CMD"); + } + + else if (canonicalize (command, "writecmd", (*_tree)[i]->attribute ("raw"))) + { + (*_tree)[i]->attribute ("canonical", command); + (*_tree)[i]->tag ("WRITECMD"); + (*_tree)[i]->tag ("CMD"); + } + + else if (canonicalize (command, "specialcmd", (*_tree)[i]->attribute ("raw"))) + { + (*_tree)[i]->attribute ("canonical", command); + (*_tree)[i]->tag ("SPECIALCMD"); + (*_tree)[i]->tag ("CMD"); + } + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/parser/A3t.h b/src/parser/A3t.h index 23dce99d0..e77692088 100644 --- a/src/parser/A3t.h +++ b/src/parser/A3t.h @@ -40,6 +40,9 @@ public: void identity (const std::string&, const std::string&); bool canonicalize (std::string&, const std::string&, const std::string&) const; +private: + void findCommand (); + private: Tree* _tree; std::multimap _entities; diff --git a/src/parser/args.cpp b/src/parser/args.cpp index 976649d97..0fb097a5f 100644 --- a/src/parser/args.cpp +++ b/src/parser/args.cpp @@ -41,9 +41,17 @@ int main (int argc, char** argv) A3t a3t (argc, argv); // Populate identity lists. - a3t.identity ("report", "list"); - a3t.identity ("readcmd", "info"); - a3t.identity ("writecmd", "modify"); + a3t.identity ("report", "list"); + a3t.identity ("report", "next"); + + a3t.identity ("readcmd", "info"); + a3t.identity ("readcmd", "projects"); + + a3t.identity ("writecmd", "add"); + a3t.identity ("writecmd", "modify"); + + a3t.identity ("specialcmd", "calendar"); + a3t.identity ("specialcmd", "edit"); Tree* tree = a3t.parse (); if (tree)