Expressions

- Added list of non-word characters to assist is_attr.
This commit is contained in:
Paul Beckingham 2011-06-10 00:17:52 -04:00
parent 2ab24fa08b
commit f8d9338102
4 changed files with 80 additions and 56 deletions

View file

@ -56,8 +56,8 @@
their descriptions. their descriptions.
# Tracked Bugs, sorted by ID. # Tracked Bugs, sorted by ID.
+ Fixed bug #475, which allowed a blank annotation command to be entered (thanks + Fixed bug #475, which allowed a blank annotation command to be entered
to Andreas Kalex). (thanks to Andreas Kalex).
+ Fixed bug #511, which caused display problem on Cygwin when colored output + Fixed bug #511, which caused display problem on Cygwin when colored output
used the full width of the terminal. The 'avoidlastcolumn' configuration used the full width of the terminal. The 'avoidlastcolumn' configuration
variable forces taskwarrior to never use the last column. variable forces taskwarrior to never use the last column.

View file

@ -32,6 +32,7 @@
#include <sys/select.h> #include <sys/select.h>
#include <Context.h> #include <Context.h>
#include <Nibbler.h> #include <Nibbler.h>
#include <Lexer.h>
#include <Directory.h> #include <Directory.h>
#include <ViewText.h> #include <ViewText.h>
#include <text.h> #include <text.h>
@ -107,6 +108,8 @@ static struct
#define NUM_MODIFIER_NAMES (sizeof (modifierNames) / sizeof (modifierNames[0])) #define NUM_MODIFIER_NAMES (sizeof (modifierNames) / sizeof (modifierNames[0]))
#define NUM_OPERATORS (sizeof (operators) / sizeof (operators[0])) #define NUM_OPERATORS (sizeof (operators) / sizeof (operators[0]))
static const char* non_word_chars = " +-*/%()=<>!~";
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Arguments::Arguments () Arguments::Arguments ()
{ {
@ -603,6 +606,9 @@ bool Arguments::is_attr (const std::string& input)
if (name.length () == 0) if (name.length () == 0)
return false; return false;
if (name.find_first_of (non_word_chars) != std::string::npos)
return false;
if (n.skip (':') || if (n.skip (':') ||
n.skip ('=')) n.skip ('='))
{ {
@ -642,6 +648,9 @@ bool Arguments::is_attmod (const std::string& input)
if (name.length () == 0) if (name.length () == 0)
return false; return false;
if (name.find_first_of (non_word_chars) != std::string::npos)
return false;
if (n.skip ('.')) if (n.skip ('.'))
{ {
n.skip ('~'); n.skip ('~');
@ -820,8 +829,14 @@ bool Arguments::is_operator (
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Arguments::is_expression (const std::string& input) bool Arguments::is_expression (const std::string& input)
{ {
Lexer lexer (unquoteText (input));
lexer.skipWhitespace (true);
lexer.coalesceAlpha (true);
lexer.coalesceDigits (true);
lexer.coalesceQuoted (true);
std::vector <std::string> tokens; std::vector <std::string> tokens;
splitq (tokens, input, ' '); lexer.tokenize (tokens);
std::vector <std::string>::iterator token; std::vector <std::string>::iterator token;
for (token = tokens.begin (); token != tokens.end (); ++token) for (token = tokens.begin (); token != tokens.end (); ++token)

View file

@ -25,6 +25,7 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <sstream> #include <sstream>
#include <map> #include <map>
#include <vector> #include <vector>
@ -96,14 +97,16 @@ int CmdCustom::execute (std::string& output)
Arguments f = context.args.extract_read_only_filter (); Arguments f = context.args.extract_read_only_filter ();
Expression e (f); Expression e (f);
return 0;
std::vector <Task> filtered; std::vector <Task> filtered;
std::vector <Task>::iterator task; std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task) for (task = tasks.begin (); task != tasks.end (); ++task)
if (e.eval (*task)) if (e.eval (*task))
filtered.push_back (*task); filtered.push_back (*task);
std::cout << "# tasks=" << tasks.size () << "\n"
<< "# filtered=" << filtered.size () << "\n";
return 0;
//////////////////////////////////// ////////////////////////////////////
// Sort the tasks. // Sort the tasks.

View file

@ -34,7 +34,7 @@ Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
UnitTest t (109); UnitTest t (113);
const char* fake[] = const char* fake[] =
{ {
@ -78,18 +78,24 @@ int main (int argc, char** argv)
t.ok (Arguments::is_attr ("name=\"one\""), "name=\"one\" -> attr"); t.ok (Arguments::is_attr ("name=\"one\""), "name=\"one\" -> attr");
t.ok (Arguments::is_attr ("name=\"one two\""), "name=\"one two\" -> attr"); t.ok (Arguments::is_attr ("name=\"one two\""), "name=\"one two\" -> attr");
// bool is_attmod (const std::string&); t.notok (Arguments::is_attr ("name"), "name -> not attr");
t.ok (Arguments::is_attmod ("name.is:"), "name.is: -> attr"); t.notok (Arguments::is_attr ("(name=val and 1<2)"), "(name=val and 1<2) -> not attr");
t.ok (Arguments::is_attmod ("name.is:\"\""), "name.is:\"\" -> attr");
t.ok (Arguments::is_attmod ("name.is:one"), "name.is:one -> attr");
t.ok (Arguments::is_attmod ("name.is:\"one\""), "name.is:\"one\" -> attr");
t.ok (Arguments::is_attmod ("name.is:\"one two\""), "name.is:\"one two\" -> attr");
t.ok (Arguments::is_attmod ("name.is="), "name.is= -> attr"); // bool is_attmod (const std::string&);
t.ok (Arguments::is_attmod ("name.is=\"\""), "name.is=\"\" -> attr"); t.ok (Arguments::is_attmod ("name.is:"), "name.is: -> attmod");
t.ok (Arguments::is_attmod ("name.is=one"), "name.is=one -> attr"); t.ok (Arguments::is_attmod ("name.is:\"\""), "name.is:\"\" -> attmod");
t.ok (Arguments::is_attmod ("name.is=\"one\""), "name.is=\"one\" -> attr"); t.ok (Arguments::is_attmod ("name.is:one"), "name.is:one -> attmod");
t.ok (Arguments::is_attmod ("name.is=\"one two\""), "name.is=\"one two\" -> attr"); t.ok (Arguments::is_attmod ("name.is:\"one\""), "name.is:\"one\" -> attmod");
t.ok (Arguments::is_attmod ("name.is:\"one two\""), "name.is:\"one two\" -> attmod");
t.ok (Arguments::is_attmod ("name.is="), "name.is= -> attmod");
t.ok (Arguments::is_attmod ("name.is=\"\""), "name.is=\"\" -> attmod");
t.ok (Arguments::is_attmod ("name.is=one"), "name.is=one -> attmod");
t.ok (Arguments::is_attmod ("name.is=\"one\""), "name.is=\"one\" -> attmod");
t.ok (Arguments::is_attmod ("name.is=\"one two\""), "name.is=\"one two\" -> attmod");
t.notok (Arguments::is_attmod ("name"), "name -> not attmod");
t.notok (Arguments::is_attmod ("(name=value and 1<2"), "(name=value and 1<2 -> not attmod");
// bool is_subst (const std::string&); // bool is_subst (const std::string&);
t.notok (Arguments::is_subst ("///"), "/// -> not subst"); t.notok (Arguments::is_subst ("///"), "/// -> not subst");