mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-26 15:47:19 +02:00
Expressions reboot
- Created A3.{h,cpp} which will be a simpler, lightweight version of Arguments.{h,cpp} that does less, but does it better. - Created E9.{h,cpp} which will be a better implementation of Expression.{h,cpp} that does less, but does it better. - Integrated A3 into Context::initialize, and Arguments and A3 will coexist until A3 surpasses Arguments.
This commit is contained in:
parent
1164ea5cf1
commit
5b5978952a
8 changed files with 2839 additions and 14 deletions
1506
src/A3.cpp
Normal file
1506
src/A3.cpp
Normal file
File diff suppressed because it is too large
Load diff
140
src/A3.h
Normal file
140
src/A3.h
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// taskwarrior - a command line task list manager.
|
||||||
|
//
|
||||||
|
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
|
// Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
// version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
// details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along with
|
||||||
|
// this program; if not, write to the
|
||||||
|
//
|
||||||
|
// Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor,
|
||||||
|
// Boston, MA
|
||||||
|
// 02110-1301
|
||||||
|
// USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef INCLUDED_A3
|
||||||
|
#define INCLUDED_A3
|
||||||
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <File.h>
|
||||||
|
|
||||||
|
#define ARGUMENTS_SEQUENCE_MAX_RANGE 1000
|
||||||
|
|
||||||
|
class Arg
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Arg (
|
||||||
|
const std::string& raw,
|
||||||
|
const std::string& category)
|
||||||
|
: _raw (raw)
|
||||||
|
, _category (category)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Arg (const Arg& other)
|
||||||
|
{
|
||||||
|
_raw = other._raw;
|
||||||
|
_category = other._category;
|
||||||
|
}
|
||||||
|
|
||||||
|
Arg& operator= (const Arg& other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
{
|
||||||
|
_raw = other._raw;
|
||||||
|
_category = other._category;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator== (const Arg& other) const
|
||||||
|
{
|
||||||
|
return _raw == other._raw &&
|
||||||
|
_category == other._category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string _raw; // Raw input token, never modified
|
||||||
|
std::string _category; // Categorized argument
|
||||||
|
};
|
||||||
|
|
||||||
|
class A3 : public std::vector <Arg>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
A3 ();
|
||||||
|
~A3 ();
|
||||||
|
|
||||||
|
void capture (int, const char**);
|
||||||
|
void capture (const std::string&);
|
||||||
|
void capture_first (const std::string&);
|
||||||
|
|
||||||
|
void categorize ();
|
||||||
|
|
||||||
|
static bool is_command (const std::vector <std::string>&, std::string&);
|
||||||
|
|
||||||
|
/*
|
||||||
|
void append_stdin ();
|
||||||
|
void rc_override (std::string&, File&);
|
||||||
|
void get_data_location (std::string&);
|
||||||
|
void apply_overrides ();
|
||||||
|
void resolve_aliases ();
|
||||||
|
void inject_defaults ();
|
||||||
|
|
||||||
|
std::vector <std::string> list ();
|
||||||
|
static std::vector <std::string> operator_list ();
|
||||||
|
std::string combine ();
|
||||||
|
|
||||||
|
bool find_command (std::string&);
|
||||||
|
std::string find_limit ();
|
||||||
|
|
||||||
|
static bool is_multipart (const std::string&, std::vector <std::string>&);
|
||||||
|
static bool is_attr (const std::string&);
|
||||||
|
static bool is_attmod (const std::string&);
|
||||||
|
static bool is_subst (const std::string&);
|
||||||
|
static bool is_pattern (const std::string&);
|
||||||
|
static bool is_id (const std::string&);
|
||||||
|
static bool is_uuid (const std::string&);
|
||||||
|
static bool is_tag (const std::string&);
|
||||||
|
static bool is_operator (const std::string&);
|
||||||
|
static bool is_operator (const std::string&, char&, int&, char&);
|
||||||
|
static bool is_symbol_operator (const std::string&);
|
||||||
|
static bool is_attribute (const std::string&, std::string&);
|
||||||
|
static bool is_modifier (const std::string&);
|
||||||
|
static bool is_expression (const std::string&);
|
||||||
|
|
||||||
|
static bool extract_attr (const std::string&, std::string&, std::string&);
|
||||||
|
static bool extract_attmod (const std::string&, std::string&, std::string&, std::string&, std::string&);
|
||||||
|
static bool extract_subst (const std::string&, std::string&, std::string&, bool&);
|
||||||
|
static bool extract_pattern (const std::string&, std::string&);
|
||||||
|
static bool extract_id (const std::string&, std::vector <int>&);
|
||||||
|
static bool extract_uuid (const std::string&, std::vector <std::string>&);
|
||||||
|
static bool extract_tag (const std::string&, char&, std::string&);
|
||||||
|
static bool extract_operator (const std::string&, std::string&);
|
||||||
|
|
||||||
|
A3 extract_read_only_filter ();
|
||||||
|
A3 extract_write_filter ();
|
||||||
|
A3 extract_modifications (bool include_seq = false);
|
||||||
|
A3 extract_simple_words ();
|
||||||
|
|
||||||
|
static bool valid_modifier (const std::string&);
|
||||||
|
*/
|
||||||
|
void dump (const std::string&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
|
@ -5,7 +5,8 @@ include_directories (${CMAKE_SOURCE_DIR}
|
||||||
${CMAKE_SOURCE_DIR}/src/columns
|
${CMAKE_SOURCE_DIR}/src/columns
|
||||||
${TASK_INCLUDE_DIRS})
|
${TASK_INCLUDE_DIRS})
|
||||||
|
|
||||||
set (task_SRCS API.cpp API.h
|
set (task_SRCS A3.cpp A3.h
|
||||||
|
API.cpp API.h
|
||||||
Arguments.cpp Arguments.h
|
Arguments.cpp Arguments.h
|
||||||
Att.cpp Att.h
|
Att.cpp Att.h
|
||||||
Color.cpp Color.h
|
Color.cpp Color.h
|
||||||
|
@ -15,6 +16,7 @@ set (task_SRCS API.cpp API.h
|
||||||
Date.cpp Date.h
|
Date.cpp Date.h
|
||||||
Directory.cpp Directory.h
|
Directory.cpp Directory.h
|
||||||
Duration.cpp Duration.h
|
Duration.cpp Duration.h
|
||||||
|
E9.cpp E9.h
|
||||||
Expression.cpp Expression.h
|
Expression.cpp Expression.h
|
||||||
File.cpp File.h
|
File.cpp File.h
|
||||||
Hooks.cpp Hooks.h
|
Hooks.cpp Hooks.h
|
||||||
|
|
|
@ -73,8 +73,8 @@ int Context::initialize (int argc, const char** argv)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// char** argv --> std::vector <std::string> Context::args.
|
// char** argv --> std::vector <std::string> Context::args.
|
||||||
// TODO Handle "cal" case here.
|
|
||||||
args.capture (argc, argv);
|
args.capture (argc, argv);
|
||||||
|
a3.capture (argc, argv);
|
||||||
|
|
||||||
// echo one two -- three | task zero --> task zero one two
|
// echo one two -- three | task zero --> task zero one two
|
||||||
// 'three' is left in the input buffer.
|
// 'three' is left in the input buffer.
|
||||||
|
@ -122,6 +122,9 @@ int Context::initialize (int argc, const char** argv)
|
||||||
// Categorize all arguments one more time. THIS IS NECESSARY.
|
// Categorize all arguments one more time. THIS IS NECESSARY.
|
||||||
args.categorize ();
|
args.categorize ();
|
||||||
|
|
||||||
|
a3.categorize ();
|
||||||
|
a3.dump ("Initial"); // TODO Remove.
|
||||||
|
|
||||||
// Handle default command and assumed 'info' command.
|
// Handle default command and assumed 'info' command.
|
||||||
args.inject_defaults ();
|
args.inject_defaults ();
|
||||||
|
|
||||||
|
@ -283,7 +286,7 @@ int Context::dispatch (std::string &out)
|
||||||
tdb2.gc ();
|
tdb2.gc ();
|
||||||
}
|
}
|
||||||
|
|
||||||
args.dump ("Argument Categorization");
|
// args.dump ("Argument Categorization");
|
||||||
return c->execute (out);
|
return c->execute (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,6 +425,17 @@ const std::vector <std::string> Context::getColumns () const
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
const std::vector <std::string> Context::getCommands () const
|
||||||
|
{
|
||||||
|
std::vector <std::string> output;
|
||||||
|
std::map <std::string, Command*>::const_iterator i;
|
||||||
|
for (i = commands.begin (); i != commands.end (); ++i)
|
||||||
|
output.push_back (i->first);
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Context::assumeLocations ()
|
void Context::assumeLocations ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Arguments.h>
|
#include <Arguments.h>
|
||||||
|
#include <A3.h>
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
{
|
{
|
||||||
|
@ -59,6 +60,7 @@ public:
|
||||||
int getHeight (); // determine terminal height
|
int getHeight (); // determine terminal height
|
||||||
|
|
||||||
const std::vector <std::string> getColumns () const;
|
const std::vector <std::string> getColumns () const;
|
||||||
|
const std::vector <std::string> getCommands () const;
|
||||||
|
|
||||||
bool color (); // TTY or <other>?
|
bool color (); // TTY or <other>?
|
||||||
bool verbose (const std::string&); // Verbosity control
|
bool verbose (const std::string&); // Verbosity control
|
||||||
|
@ -81,6 +83,7 @@ private:
|
||||||
public:
|
public:
|
||||||
std::string program;
|
std::string program;
|
||||||
Arguments args;
|
Arguments args;
|
||||||
|
A3 a3;
|
||||||
std::string home_dir;
|
std::string home_dir;
|
||||||
File rc_file;
|
File rc_file;
|
||||||
Path data_dir;
|
Path data_dir;
|
||||||
|
|
1087
src/E9.cpp
Normal file
1087
src/E9.cpp
Normal file
File diff suppressed because it is too large
Load diff
73
src/E9.h
Normal file
73
src/E9.h
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// taskwarrior - a command line task list manager.
|
||||||
|
//
|
||||||
|
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
|
// Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
// version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
// details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along with
|
||||||
|
// this program; if not, write to the
|
||||||
|
//
|
||||||
|
// Free Software Foundation, Inc.,
|
||||||
|
// 51 Franklin Street, Fifth Floor,
|
||||||
|
// Boston, MA
|
||||||
|
// 02110-1301
|
||||||
|
// USA
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef INCLUDED_E9
|
||||||
|
#define INCLUDED_E9
|
||||||
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <stack>
|
||||||
|
#include <Arguments.h>
|
||||||
|
#include <Task.h>
|
||||||
|
#include <RX.h>
|
||||||
|
#include <Variant.h>
|
||||||
|
|
||||||
|
class E9
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
E9 (Arguments&);
|
||||||
|
~E9 ();
|
||||||
|
bool eval (const Task&);
|
||||||
|
bool evalFilter (const Task&);
|
||||||
|
std::string evalE9 (const Task&);
|
||||||
|
void eval (const Task&, std::vector <Variant>&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void expand_sequence ();
|
||||||
|
void implicit_and ();
|
||||||
|
void expand_tag ();
|
||||||
|
void expand_pattern ();
|
||||||
|
void expand_attr ();
|
||||||
|
void expand_attmod ();
|
||||||
|
void expand_word ();
|
||||||
|
void expand_tokens ();
|
||||||
|
void postfix ();
|
||||||
|
|
||||||
|
void tokenize (const std::string&, const std::string&, std::vector <std::string>&, Arguments&);
|
||||||
|
void create_variant (Variant&, const std::string&, const std::string&);
|
||||||
|
bool is_new_style ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool eval_match (Variant&, Variant&, bool);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Arguments _args;
|
||||||
|
std::map <std::string, RX> _regexes;
|
||||||
|
bool _prepared;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
|
@ -60,7 +60,7 @@ bool Expression::evalFilter (const Task& task)
|
||||||
|
|
||||||
if (!_prepared)
|
if (!_prepared)
|
||||||
{
|
{
|
||||||
_args.dump ("Expression::evalFilter");
|
// _args.dump ("Expression::evalFilter");
|
||||||
|
|
||||||
expand_sequence ();
|
expand_sequence ();
|
||||||
implicit_and ();
|
implicit_and ();
|
||||||
|
@ -93,7 +93,7 @@ std::string Expression::evalExpression (const Task& task)
|
||||||
|
|
||||||
if (!_prepared)
|
if (!_prepared)
|
||||||
{
|
{
|
||||||
_args.dump ("Expression::evalExpression");
|
// _args.dump ("Expression::evalExpression");
|
||||||
|
|
||||||
// expand_sequence ();
|
// expand_sequence ();
|
||||||
// implicit_and ();
|
// implicit_and ();
|
||||||
|
@ -567,7 +567,7 @@ void Expression::expand_sequence ()
|
||||||
}
|
}
|
||||||
|
|
||||||
_args.swap (temp);
|
_args.swap (temp);
|
||||||
_args.dump ("Expression::expand_sequence");
|
// _args.dump ("Expression::expand_sequence");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -595,7 +595,7 @@ void Expression::expand_tokens ()
|
||||||
if (delta)
|
if (delta)
|
||||||
{
|
{
|
||||||
_args.swap (temp);
|
_args.swap (temp);
|
||||||
_args.dump ("Expression::expand_tokens");
|
// _args.dump ("Expression::expand_tokens");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,7 +694,7 @@ void Expression::implicit_and ()
|
||||||
if (delta)
|
if (delta)
|
||||||
{
|
{
|
||||||
_args.swap (temp);
|
_args.swap (temp);
|
||||||
_args.dump ("Expression::implicit_and");
|
// _args.dump ("Expression::implicit_and");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,7 +728,7 @@ void Expression::expand_tag ()
|
||||||
if (delta)
|
if (delta)
|
||||||
{
|
{
|
||||||
_args.swap (temp);
|
_args.swap (temp);
|
||||||
_args.dump ("Expression::expand_tag");
|
// _args.dump ("Expression::expand_tag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -760,7 +760,7 @@ void Expression::expand_pattern ()
|
||||||
if (delta)
|
if (delta)
|
||||||
{
|
{
|
||||||
_args.swap (temp);
|
_args.swap (temp);
|
||||||
_args.dump ("Expression::expand_pattern");
|
// _args.dump ("Expression::expand_pattern");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -807,7 +807,7 @@ void Expression::expand_attr ()
|
||||||
if (delta)
|
if (delta)
|
||||||
{
|
{
|
||||||
_args.swap (temp);
|
_args.swap (temp);
|
||||||
_args.dump ("Expression::expand_attr");
|
// _args.dump ("Expression::expand_attr");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -933,7 +933,7 @@ void Expression::expand_attmod ()
|
||||||
if (delta)
|
if (delta)
|
||||||
{
|
{
|
||||||
_args.swap (temp);
|
_args.swap (temp);
|
||||||
_args.dump ("Expression::expand_attmod");
|
// _args.dump ("Expression::expand_attmod");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -963,7 +963,7 @@ void Expression::expand_word ()
|
||||||
if (delta)
|
if (delta)
|
||||||
{
|
{
|
||||||
_args.swap (temp);
|
_args.swap (temp);
|
||||||
_args.dump ("Expression::expand_word");
|
// _args.dump ("Expression::expand_word");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1063,7 +1063,7 @@ void Expression::postfix ()
|
||||||
}
|
}
|
||||||
|
|
||||||
_args.swap (temp);
|
_args.swap (temp);
|
||||||
_args.dump ("Expression::toPostfix");
|
// _args.dump ("Expression::toPostfix");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue