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.
This commit is contained in:
Paul Beckingham 2013-08-30 14:08:09 -07:00
parent 46cd57b4aa
commit 50d4b37519
3 changed files with 34 additions and 1 deletions

View file

@ -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);

View file

@ -42,6 +42,7 @@ public:
private:
void findBinary ();
void findTerminator ();
void findCommand ();
private:

View file

@ -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\<c \(one or two\) modify 'quoted string' \'not quoted\' due:eom+1wk+1d
echo; ./args 123 mod pro:'P 1' +home /from/to/g
echo; ./args add -- modify