From 50d4b375194f81f93480d5953a4236667e003e4d Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 30 Aug 2013 14:08:09 -0700 Subject: [PATCH] A3t::findTerminator - Locates and tags the terminator operator, suppressing all subsequent parsing. This is done early in the process, and every other step must observe the TERMINATOR tag. --- src/parser/A3t.cpp | 21 +++++++++++++++++++++ src/parser/A3t.h | 1 + src/parser/run | 13 ++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/parser/A3t.cpp b/src/parser/A3t.cpp index 858120149..412ca03a0 100644 --- a/src/parser/A3t.cpp +++ b/src/parser/A3t.cpp @@ -56,6 +56,7 @@ A3t::~A3t () Tree* A3t::parse () { findBinary (); + findTerminator (); findCommand (); return _tree; @@ -116,6 +117,22 @@ void A3t::findBinary () } } +//////////////////////////////////////////////////////////////////////////////// +// The parser override operator terminates all subsequent cleverness, leaving +// all args in the raw state. +void A3t::findTerminator () +{ + std::string command; + for (int i = 0; i < _tree->branches (); ++i) + { + if (_tree->operator[](i)->attribute ("raw") == "--") + { + _tree->operator[](i)->tag ("TERMINATOR"); + break; + } + } +} + //////////////////////////////////////////////////////////////////////////////// // Walk the top-level tree branches, looking for the first raw value that // autoCompletes to a valid command/report. @@ -124,6 +141,10 @@ void A3t::findCommand () std::string command; for (int i = 0; i < _tree->branches (); ++i) { + // Parser override operator. + if (_tree->operator[](i)->attribute ("raw") == "--") + break; + if (canonicalize (command, "report", _tree->operator[](i)->attribute ("raw"))) { _tree->operator[](i)->attribute ("canonical", command); diff --git a/src/parser/A3t.h b/src/parser/A3t.h index e9a8a2bc3..ab3632c03 100644 --- a/src/parser/A3t.h +++ b/src/parser/A3t.h @@ -42,6 +42,7 @@ public: private: void findBinary (); + void findTerminator (); void findCommand (); private: diff --git a/src/parser/run b/src/parser/run index 190f620e0..58a1727d3 100755 --- a/src/parser/run +++ b/src/parser/run @@ -1,2 +1,13 @@ #./parser $* grammar.bnf 123 mod pro:H -./args 123 mod pro:H + +#echo; ./args rc:x rc.debug:1 rc.hyphenate:off list pro:foo "(du<123.due or due.aft:som)" and entry '>'8/31/2011 +2w+1d /pattern/ +#echo; ./args rc:x rc.debug:1 rc.hyphenate:off list "pro:foo (du<123.due or due.aft:som) and entry >8/31/2011 +2w+1d /pattern/" +#echo; ./args rc:x rc.debug:1 1-3,5 7 or +tag modify pri:H /from/to/g -tag +#echo; ./args rc:x rc.debug:1 add pro:foo due:eom-2wk recur:monthly do the thing +#echo; ./args rc:x rc.debug:1 add pro:foo -- due:eom-2wk recur:monthly do the thing +#echo; ./args rc:x rc.debug:1 1234 done pri:H +#echo; ./args rc:x rc.debug:1 a.b\