diff --git a/src/T.h b/src/T.h index 14004a9c3..5e457aba1 100644 --- a/src/T.h +++ b/src/T.h @@ -50,6 +50,8 @@ public: int getId () const { return mId; } void setId (int id) { mId = id; } + std::vector getAllIds () const { return mSequence; } + void addId (int id) { mSequence.push_back (id); } status getStatus () const { return mStatus; } void setStatus (status s) { mStatus = s; } @@ -95,6 +97,7 @@ private: status mStatus; std::string mUUID; int mId; + std::vector mSequence; std::string mDescription; std::vector mTags; std::vector mRemoveTags; diff --git a/src/parse.cpp b/src/parse.cpp index f4778307e..c57762ec9 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -306,6 +306,60 @@ static bool validId (const std::string& input) return true; } +//////////////////////////////////////////////////////////////////////////////// +// 1,2-4,6 +static bool validSequence ( + const std::string& input, + std::vector & ids) +{ + std::vector ranges; + split (ranges, input, ','); + + std::vector ::iterator it; + for (it = ranges.begin (); it != ranges.end (); ++it) + { + std::vector range; + split (range, *it, '-'); + + switch (range.size ()) + { + case 1: + if (! validId (range[0])) + return false; + + int id = ::atoi (range[0].c_str ()); + ids.push_back (id); +// std::cout << "# seq: " << id << std::endl; + break; + + case 2: + { + if (! validId (range[0]) || + ! validId (range[1])) + return false; + + int low = ::atoi (range[0].c_str ()); + int high = ::atoi (range[1].c_str ()); + if (low >= high) + return false; + + for (int i = low; i <= high; ++i) +// { + ids.push_back (i); +// std::cout << "# seq: " << i << std::endl; +// } + } + break; + + default: + return false; + break; + } + } + + return ids.size () > 1 ? true : false; +} + //////////////////////////////////////////////////////////////////////////////// static bool validTag (const std::string& input) { @@ -390,15 +444,25 @@ bool validDuration (std::string& input) } //////////////////////////////////////////////////////////////////////////////// -// Token Distinguishing characteristic -// ------- ----------------------------- -// command first positional -// id \d+ -// description default, accumulate -// substitution /\w+/\w*/ -// tags [-+]\w+ -// attributes \w+:.+ +// Token EBNF +// ------- ---------------------------------- +// command first non-id recognized argument // +// id ::= \d+ +// +// substitution ::= "/" from "/" to "/g" +// | "/" from "/" to "/" ; +// +// tags ::= "+" word +// | "-" word ; +// +// attributes ::= word ":" value +// | word ":" +// +// sequence ::= id "," sequence +// | id "-" id ; +// +// description (whatever isn't one of the above) void parse ( std::vector & args, std::string& command, @@ -420,12 +484,30 @@ void parse ( std::string from; std::string to; bool global; + std::vector sequence; // An id is the first argument found that contains all digits. - if (lowerCase (command) != "add" && // "add" doesn't require an ID - task.getId () == 0 && - validId (arg)) + if (lowerCase (command) != "add" && +/* + task.getSequenceCount () == 0 && +*/ + validSequence (arg, sequence)) + { +/* + for (?) + task.addSequence (?) +*/ + std::cout << "# look like a sequence" << std::endl; + foreach (id, sequence) + task.addId (*id); + } + + else if (lowerCase (command) != "add" && // "add" doesn't require an ID + task.getId () == 0 && + validId (arg)) + { task.setId (::atoi (arg.c_str ())); + } // Tags begin with + or - and contain arbitrary text. else if (validTag (arg))