From 9ce7f63d85d175f7164a60ef66b77ae27f35df36 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 31 Jul 2011 16:18:25 -0400 Subject: [PATCH] Bug - Fixed bug where argument processing was not properly shut off by the terminator -- in A3::tokenize. --- src/A3.cpp | 288 +++++++++++++++++++++++++++------------------------- test/args.t | 16 +-- 2 files changed, 160 insertions(+), 144 deletions(-) diff --git a/src/A3.cpp b/src/A3.cpp index 1bd5c1c4f..52460cbe5 100644 --- a/src/A3.cpp +++ b/src/A3.cpp @@ -652,6 +652,7 @@ const A3 A3::tokenize (const A3& input) const n.skipWS (); // For identifying sequence versus non-sequence. + bool terminated = false; bool found_sequence = false; bool found_something_after_sequence = false; @@ -661,154 +662,169 @@ const A3 A3::tokenize (const A3& input) const time_t t; while (! n.depleted ()) { - if (n.getQuoted ('"', s, true) || - n.getQuoted ('\'', s, true)) + if (!terminated) { - output.push_back (Arg (s, "string")); - if (found_sequence) - found_something_after_sequence = true; - } + if (n.getLiteral ("--")) + terminated = true; - else if (is_subst (n, s)) - { - output.push_back (Arg (s, "subst")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (is_pattern (n, s)) - { - output.push_back (Arg (s, "pattern")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (is_tag (n, s)) - { - output.push_back (Arg (s, "tag")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (n.getOneOf (operators, s)) - { - output.push_back (Arg (s, "op")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (is_attr (n, s)) - { - // The "limit:xxx" attribute is not stored, but the value is retained. - if (s.length () > 6 && - s.substr (0, 6) == "limit:") + else if (n.getQuoted ('"', s, true) || + n.getQuoted ('\'', s, true)) { - output._limit = s.substr (6); + output.push_back (Arg (s, "string")); + if (found_sequence) + found_something_after_sequence = true; } + + else if (is_subst (n, s)) + { + output.push_back (Arg (s, "subst")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (is_pattern (n, s)) + { + output.push_back (Arg (s, "pattern")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (is_tag (n, s)) + { + output.push_back (Arg (s, "tag")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (n.getOneOf (operators, s)) + { + output.push_back (Arg (s, "op")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (is_attr (n, s)) + { + // The "limit:xxx" attribute is not stored, but the value is retained. + if (s.length () > 6 && + s.substr (0, 6) == "limit:") + { + output._limit = s.substr (6); + } + else + { + output.push_back (Arg (s, "attr")); + if (found_sequence) + found_something_after_sequence = true; + } + } + + else if (is_attmod (n, s)) + { + output.push_back (Arg (s, "attmod")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (is_dom (n, s)) + { + output.push_back (Arg (s, "dom")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (n.getDateISO (t)) + { + output.push_back (Arg (Date (t).toISO (), "date")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (n.getDate (date_format, t)) + { + output.push_back (Arg (Date (t).toString (date_format), "date")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (is_duration (n, s)) + { + output.push_back (Arg (s, "duration")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (is_id (n, s)) + { + if (found_something_after_sequence) + { + output.push_back (Arg (s, "num")); + } + else + { + output.push_back (Arg (s, "id")); + found_sequence = true; + } + } + + else if (is_uuid (n, s)) + { + if (found_something_after_sequence) + { + output.push_back (Arg (s, "num")); + } + else + { + output.push_back (Arg (s, "uuid")); + found_sequence = true; + } + } + + // TODO This may be redundant. + else if (n.getNumber (d)) + { + output.push_back (Arg (format (d), "num")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (n.getInt (i)) + { + output.push_back (Arg (format (i), "int")); + if (found_sequence) + found_something_after_sequence = true; + } + + else if (n.getName (s) || + n.getWord (s)) + { + if (Date::valid (s)) + output.push_back (Arg (s, "date")); + else + output.push_back (Arg (s, "word")); + + if (found_sequence) + found_something_after_sequence = true; + } + else { - output.push_back (Arg (s, "attr")); + if (! n.getUntilWS (s)) + n.getUntilEOS (s); + + output.push_back (Arg (s, "word")); if (found_sequence) found_something_after_sequence = true; } } - - else if (is_attmod (n, s)) - { - output.push_back (Arg (s, "attmod")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (is_dom (n, s)) - { - output.push_back (Arg (s, "dom")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (n.getDateISO (t)) - { - output.push_back (Arg (Date (t).toISO (), "date")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (n.getDate (date_format, t)) - { - output.push_back (Arg (Date (t).toString (date_format), "date")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (is_duration (n, s)) - { - output.push_back (Arg (s, "duration")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (is_id (n, s)) - { - if (found_something_after_sequence) - { - output.push_back (Arg (s, "num")); - } - else - { - output.push_back (Arg (s, "id")); - found_sequence = true; - } - } - - else if (is_uuid (n, s)) - { - if (found_something_after_sequence) - { - output.push_back (Arg (s, "num")); - } - else - { - output.push_back (Arg (s, "uuid")); - found_sequence = true; - } - } - - // TODO This may be redundant. - else if (n.getNumber (d)) - { - output.push_back (Arg (format (d), "num")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (n.getInt (i)) - { - output.push_back (Arg (format (i), "int")); - if (found_sequence) - found_something_after_sequence = true; - } - - else if (n.getName (s) || - n.getWord (s)) - { - if (Date::valid (s)) - output.push_back (Arg (s, "date")); - else - output.push_back (Arg (s, "word")); - - if (found_sequence) - found_something_after_sequence = true; - } - else { - if (! n.getUntilWS (s)) - n.getUntilEOS (s); - - output.push_back (Arg (s, "word")); - if (found_sequence) - found_something_after_sequence = true; + if (n.getUntilEOS (s)) + { + output.push_back (Arg (s, "word")); + if (found_sequence) + found_something_after_sequence = true; + } } n.skipWS (); diff --git a/test/args.t b/test/args.t index 20c64ce28..d5e493d64 100755 --- a/test/args.t +++ b/test/args.t @@ -44,21 +44,21 @@ qx{../src/task rc:args.rc add project:p pri:H +tag foo}; my $output = qx{../src/task rc:args.rc info 1}; like ($output, qr/Description\s+foo\n/ms, 'task add project:p pri:H +tag foo'); -qx{../src/task rc:args.rc 1 project:p pri:H +tag -- foo}; +qx{../src/task rc:args.rc 1 modify project:p pri:H +tag -- foo}; $output = qx{../src/task rc:args.rc info 1}; -like ($output, qr/Description\s+foo\n/ms, 'task 1 project:p pri:H +tag -- foo'); +like ($output, qr/Description\s+foo\n/ms, 'task 1 modify project:p pri:H +tag -- foo'); -qx{../src/task rc:args.rc 1 project:p pri:H -- +tag foo}; +qx{../src/task rc:args.rc 1 modify project:p pri:H -- +tag foo}; $output = qx{../src/task rc:args.rc info 1}; -like ($output, qr/Description\s+\+tag\sfoo\n/ms, 'task 1 project:p pri:H -- +tag foo'); +like ($output, qr/Description\s+\+tag\sfoo\n/ms, 'task 1 modify project:p pri:H -- +tag foo'); -qx{../src/task rc:args.rc 1 project:p -- pri:H +tag foo}; +qx{../src/task rc:args.rc 1 modify project:p -- pri:H +tag foo}; $output = qx{../src/task rc:args.rc info 1}; -like ($output, qr/Description\s+pri:H\s\+tag\sfoo\n/ms, 'task 1 project:p -- pri:H +tag foo'); +like ($output, qr/Description\s+pri:H\s\+tag\sfoo\n/ms, 'task 1 modify project:p -- pri:H +tag foo'); -qx{../src/task rc:args.rc 1 -- project:p pri:H +tag foo}; +qx{../src/task rc:args.rc 1 modify -- project:p pri:H +tag foo}; $output = qx{../src/task rc:args.rc info 1}; -like ($output, qr/Description\s+project:p\spri:H\s\+tag\sfoo\n/ms, 'task 1 -- project:p pri:H +tag foo'); +like ($output, qr/Description\s+project:p\spri:H\s\+tag\sfoo\n/ms, 'task 1 modify -- project:p pri:H +tag foo'); # Cleanup. unlink 'pending.data';