mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Cleanup
- Eliminated Expression.{h,cpp}. E9 now replaces it.
This commit is contained in:
parent
879356fad2
commit
ab8a6d9e88
6 changed files with 75 additions and 1169 deletions
1
src/A3.h
1
src/A3.h
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <Nibbler.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
|
|
||||||
#define ARGUMENTS_SEQUENCE_MAX_RANGE 1000
|
#define ARGUMENTS_SEQUENCE_MAX_RANGE 1000
|
||||||
|
|
|
@ -17,7 +17,6 @@ set (task_SRCS A3.cpp A3.h
|
||||||
Directory.cpp Directory.h
|
Directory.cpp Directory.h
|
||||||
Duration.cpp Duration.h
|
Duration.cpp Duration.h
|
||||||
E9.cpp E9.h
|
E9.cpp E9.h
|
||||||
Expression.cpp Expression.h
|
|
||||||
File.cpp File.h
|
File.cpp File.h
|
||||||
Hooks.cpp Hooks.h
|
Hooks.cpp Hooks.h
|
||||||
JSON.cpp JSON.h
|
JSON.cpp JSON.h
|
||||||
|
|
69
src/E9.cpp
69
src/E9.cpp
|
@ -85,6 +85,7 @@ void E9::eval (const Task& task, std::vector <Arg>& value_stack)
|
||||||
// Unary operators.
|
// Unary operators.
|
||||||
if (arg->_raw == "!")
|
if (arg->_raw == "!")
|
||||||
{
|
{
|
||||||
|
// TODO Are there sufficient arguments?
|
||||||
Arg right = value_stack.back ();
|
Arg right = value_stack.back ();
|
||||||
value_stack.pop_back ();
|
value_stack.pop_back ();
|
||||||
operator_not (result, right);
|
operator_not (result, right);
|
||||||
|
@ -93,6 +94,7 @@ void E9::eval (const Task& task, std::vector <Arg>& value_stack)
|
||||||
// Binary operators.
|
// Binary operators.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// TODO Are there sufficient arguments?
|
||||||
Arg right = value_stack.back ();
|
Arg right = value_stack.back ();
|
||||||
value_stack.pop_back ();
|
value_stack.pop_back ();
|
||||||
Arg left = value_stack.back ();
|
Arg left = value_stack.back ();
|
||||||
|
@ -180,6 +182,10 @@ void E9::operator_xor (Arg& result, Arg& left, Arg& right)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TODO Special handling for priority.
|
||||||
|
// if (left._string != "H" && right._string == "H") result = true;
|
||||||
|
// else if (left._string == "L" && right._string == "M") result = true;
|
||||||
|
// else if (left._string == "" && right._string != "") result = true;
|
||||||
void E9::operator_lt (Arg& result, Arg& left, Arg& right)
|
void E9::operator_lt (Arg& result, Arg& left, Arg& right)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -192,6 +198,11 @@ void E9::operator_lt (Arg& result, Arg& left, Arg& right)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TODO Special handling for priority.
|
||||||
|
// if (left._string == right._string ) result = true;
|
||||||
|
// else if ( right._string == "H") result = true;
|
||||||
|
// else if (left._string == "L" && right._string == "M") result = true;
|
||||||
|
// else if (left._string == "" ) result = true;
|
||||||
void E9::operator_lte (Arg& result, Arg& left, Arg& right)
|
void E9::operator_lte (Arg& result, Arg& left, Arg& right)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -204,6 +215,11 @@ void E9::operator_lte (Arg& result, Arg& left, Arg& right)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TODO Special handling for priority.
|
||||||
|
// if (left._string == right._string ) result = true;
|
||||||
|
// else if (left._string == "H" ) result = true;
|
||||||
|
// else if (left._string == "M" && right._string == "L") result = true;
|
||||||
|
// else if ( right._string == "" ) result = true;
|
||||||
void E9::operator_gte (Arg& result, Arg& left, Arg& right)
|
void E9::operator_gte (Arg& result, Arg& left, Arg& right)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -216,6 +232,10 @@ void E9::operator_gte (Arg& result, Arg& left, Arg& right)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// TODO Special handling for priority.
|
||||||
|
// if (left._string == "H" && right._string != "H") result = true;
|
||||||
|
// else if (left._string == "M" && right._string == "L") result = true;
|
||||||
|
// else if (left._string != "" && right._string == "") result = true;
|
||||||
void E9::operator_gt (Arg& result, Arg& left, Arg& right)
|
void E9::operator_gt (Arg& result, Arg& left, Arg& right)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -240,6 +260,18 @@ void E9::operator_inequal (Arg& result, Arg& left, Arg& right)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// bool result = false;
|
||||||
|
// if (left._raw == "project" || left._raw == "recur")
|
||||||
|
// {
|
||||||
|
// left.cast (Variant::v_string);
|
||||||
|
// right.cast (Variant::v_string);
|
||||||
|
// if (right._string.length () <= left._string.length ())
|
||||||
|
// result = compare (right._string,
|
||||||
|
// left._string.substr (0, right._string.length ()),
|
||||||
|
// (bool) case_sensitive);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// result = (left == right);
|
||||||
void E9::operator_equal (Arg& result, Arg& left, Arg& right)
|
void E9::operator_equal (Arg& result, Arg& left, Arg& right)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -264,6 +296,16 @@ void E9::operator_match (Arg& result, Arg& left, Arg& right)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// bool case_sensitive = context.config.getBoolean ("search.case.sensitive");
|
||||||
|
// bool result = !eval_match (left, right, case_sensitive);
|
||||||
|
//
|
||||||
|
// // Matches against description are really against either description,
|
||||||
|
// // annotations or project.
|
||||||
|
// // Short-circuit if match already failed.
|
||||||
|
// if (result && left._raw == "description")
|
||||||
|
// {
|
||||||
|
// // TODO check further.
|
||||||
|
// }
|
||||||
void E9::operator_nomatch (Arg& result, Arg& left, Arg& right)
|
void E9::operator_nomatch (Arg& result, Arg& left, Arg& right)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -324,3 +366,30 @@ void E9::operator_subtract (Arg& result, Arg& left, Arg& right)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/*
|
||||||
|
bool Expression::eval_match (Variant& left, Variant& right, bool case_sensitive)
|
||||||
|
{
|
||||||
|
if (right._raw_type == "rx")
|
||||||
|
{
|
||||||
|
left.cast (Variant::v_string);
|
||||||
|
right.cast (Variant::v_string);
|
||||||
|
|
||||||
|
// Create a cached entry, if it does not already exist.
|
||||||
|
if (_regexes.find (right._string) == _regexes.end ())
|
||||||
|
_regexes[right._string] = RX (right._string, case_sensitive);
|
||||||
|
|
||||||
|
if (_regexes[right._string].match (left._string))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
left.cast (Variant::v_string);
|
||||||
|
right.cast (Variant::v_string);
|
||||||
|
if (find (left._string, right._string, (bool) case_sensitive) != std::string::npos)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
1087
src/Expression.cpp
1087
src/Expression.cpp
File diff suppressed because it is too large
Load diff
|
@ -1,73 +0,0 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 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_EXPRESSION
|
|
||||||
#define INCLUDED_EXPRESSION
|
|
||||||
#define L10N // Localization complete.
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <stack>
|
|
||||||
#include <Arguments.h>
|
|
||||||
#include <Task.h>
|
|
||||||
#include <RX.h>
|
|
||||||
#include <Variant.h>
|
|
||||||
|
|
||||||
class Expression
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Expression (Arguments&);
|
|
||||||
~Expression ();
|
|
||||||
bool eval (const Task&);
|
|
||||||
bool evalFilter (const Task&);
|
|
||||||
std::string evalExpression (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
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <Expression.h>
|
|
||||||
#include <E9.h>
|
#include <E9.h>
|
||||||
#include <Att.h>
|
#include <Att.h>
|
||||||
#include <Timer.h>
|
#include <Timer.h>
|
||||||
|
@ -280,8 +279,7 @@ void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
|
||||||
|
|
||||||
if (f.size ())
|
if (f.size ())
|
||||||
{
|
{
|
||||||
Expression e (f);
|
E9 e (filt);
|
||||||
E9 expr (filt);
|
|
||||||
|
|
||||||
std::vector <Task>::iterator task;
|
std::vector <Task>::iterator task;
|
||||||
for (task = input.begin (); task != input.end (); ++task)
|
for (task = input.begin (); task != input.end (); ++task)
|
||||||
|
@ -310,8 +308,7 @@ void Command::filter (std::vector <Task>& output)
|
||||||
if (f.size ())
|
if (f.size ())
|
||||||
{
|
{
|
||||||
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
||||||
Expression e (f);
|
E9 e (filt);
|
||||||
E9 expr (filt);
|
|
||||||
|
|
||||||
output.clear ();
|
output.clear ();
|
||||||
std::vector <Task>::const_iterator task;
|
std::vector <Task>::const_iterator task;
|
||||||
|
@ -429,9 +426,9 @@ void Command::modify_task (
|
||||||
if (Arguments::is_attribute (name, name)) // Canonicalize
|
if (Arguments::is_attribute (name, name)) // Canonicalize
|
||||||
{
|
{
|
||||||
// All values must be eval'd first.
|
// All values must be eval'd first.
|
||||||
Arguments fragment;
|
A3 fragment;
|
||||||
fragment.push_back (Triple (value, "exp", "attr"));
|
fragment.push_back (Arg (value, "attr"));
|
||||||
Expression e (fragment);
|
E9 e (fragment);
|
||||||
std::string result = e.evalExpression (task);
|
std::string result = e.evalExpression (task);
|
||||||
context.debug (std::string ("Eval '") + value + "' --> '" + result + "'");
|
context.debug (std::string ("Eval '") + value + "' --> '" + result + "'");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue