mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 17:07:19 +02:00
Lexer2
- Migrated ::dequote method from Lexer.
This commit is contained in:
parent
be80bc4ea3
commit
aab93b2cda
4 changed files with 43 additions and 29 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Nibbler.h>
|
#include <Nibbler.h>
|
||||||
#include <Lexer.h>
|
#include <Lexer.h>
|
||||||
|
#include <Lexer2.h>
|
||||||
#include <CLI.h>
|
#include <CLI.h>
|
||||||
#include <Color.h>
|
#include <Color.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
|
@ -1638,7 +1639,7 @@ void CLI::desugarFilterPlainArgs ()
|
||||||
reconstructed.push_back (op);
|
reconstructed.push_back (op);
|
||||||
|
|
||||||
std::string pattern = a->attribute ("raw");
|
std::string pattern = a->attribute ("raw");
|
||||||
Lexer::dequote (pattern);
|
Lexer2::dequote (pattern);
|
||||||
A rhs ("argPattern", "'" + pattern + "'");
|
A rhs ("argPattern", "'" + pattern + "'");
|
||||||
rhs.tag ("LITERAL");
|
rhs.tag ("LITERAL");
|
||||||
rhs.tag ("FILTER");
|
rhs.tag ("FILTER");
|
||||||
|
|
|
@ -237,6 +237,18 @@ bool Lexer2::isPunctuation (int c)
|
||||||
ispunct (c);
|
ispunct (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void Lexer2::dequote (std::string& input)
|
||||||
|
{
|
||||||
|
int quote = input[0];
|
||||||
|
size_t len = input.length ();
|
||||||
|
if ((quote == '\'' || quote == '"') &&
|
||||||
|
quote == input[len - 1])
|
||||||
|
{
|
||||||
|
input = input.substr (1, len - 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Lexer2::isEOS () const
|
bool Lexer2::isEOS () const
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,6 +62,7 @@ public:
|
||||||
static bool isTripleCharOperator (int, int, int, int);
|
static bool isTripleCharOperator (int, int, int, int);
|
||||||
static bool isBoundary (int, int);
|
static bool isBoundary (int, int);
|
||||||
static bool isPunctuation (int);
|
static bool isPunctuation (int);
|
||||||
|
static void dequote (std::string&);
|
||||||
|
|
||||||
// Helpers.
|
// Helpers.
|
||||||
bool isEOS () const;
|
bool isEOS () const;
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <Variant.h>
|
#include <Variant.h>
|
||||||
#include <ISO8601.h>
|
#include <ISO8601.h>
|
||||||
#include <Lexer.h>
|
#include <Lexer2.h>
|
||||||
#include <Date.h>
|
#include <Date.h>
|
||||||
#include <Duration.h>
|
#include <Duration.h>
|
||||||
#include <RX.h>
|
#include <RX.h>
|
||||||
|
@ -196,10 +196,10 @@ bool Variant::operator&& (const Variant& other) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
left.cast (type_boolean);
|
left.cast (type_boolean);
|
||||||
right.cast (type_boolean);
|
right.cast (type_boolean);
|
||||||
|
@ -214,10 +214,10 @@ bool Variant::operator|| (const Variant& other) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
left.cast (type_boolean);
|
left.cast (type_boolean);
|
||||||
right.cast (type_boolean);
|
right.cast (type_boolean);
|
||||||
|
@ -232,10 +232,10 @@ bool Variant::operator_xor (const Variant& other) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
left.cast (type_boolean);
|
left.cast (type_boolean);
|
||||||
right.cast (type_boolean);
|
right.cast (type_boolean);
|
||||||
|
@ -251,10 +251,10 @@ bool Variant::operator< (const Variant& other) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
switch (left._type)
|
switch (left._type)
|
||||||
{
|
{
|
||||||
|
@ -396,10 +396,10 @@ bool Variant::operator<= (const Variant& other) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
switch (left._type)
|
switch (left._type)
|
||||||
{
|
{
|
||||||
|
@ -542,10 +542,10 @@ bool Variant::operator> (const Variant& other) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
switch (left._type)
|
switch (left._type)
|
||||||
{
|
{
|
||||||
|
@ -686,10 +686,10 @@ bool Variant::operator>= (const Variant& other) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
switch (left._type)
|
switch (left._type)
|
||||||
{
|
{
|
||||||
|
@ -832,10 +832,10 @@ bool Variant::operator== (const Variant& other) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
switch (left._type)
|
switch (left._type)
|
||||||
{
|
{
|
||||||
|
@ -962,16 +962,16 @@ bool Variant::operator_match (const Variant& other, const Task& task) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
left.cast (type_string);
|
left.cast (type_string);
|
||||||
right.cast (type_string);
|
right.cast (type_string);
|
||||||
|
|
||||||
std::string pattern = right._string;
|
std::string pattern = right._string;
|
||||||
Lexer::dequote (pattern);
|
Lexer2::dequote (pattern);
|
||||||
|
|
||||||
if (searchUsingRegex)
|
if (searchUsingRegex)
|
||||||
{
|
{
|
||||||
|
@ -1032,10 +1032,10 @@ bool Variant::operator_partial (const Variant& other) const
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
switch (left._type)
|
switch (left._type)
|
||||||
{
|
{
|
||||||
|
@ -1220,7 +1220,7 @@ bool Variant::operator_hastag (const Variant& other, const Task& task) const
|
||||||
{
|
{
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
right.cast (type_string);
|
right.cast (type_string);
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
return task.hasTag (right._string);
|
return task.hasTag (right._string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1236,7 +1236,7 @@ bool Variant::operator! () const
|
||||||
Variant left (*this);
|
Variant left (*this);
|
||||||
|
|
||||||
if (left._type == type_string)
|
if (left._type == type_string)
|
||||||
Lexer::dequote (left._string);
|
Lexer2::dequote (left._string);
|
||||||
|
|
||||||
left.cast (type_boolean);
|
left.cast (type_boolean);
|
||||||
return ! left._bool;
|
return ! left._bool;
|
||||||
|
@ -1401,7 +1401,7 @@ Variant& Variant::operator+= (const Variant& other)
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
switch (_type)
|
switch (_type)
|
||||||
{
|
{
|
||||||
|
@ -1513,7 +1513,7 @@ Variant& Variant::operator*= (const Variant& other)
|
||||||
Variant right (other);
|
Variant right (other);
|
||||||
|
|
||||||
if (right._type == type_string)
|
if (right._type == type_string)
|
||||||
Lexer::dequote (right._string);
|
Lexer2::dequote (right._string);
|
||||||
|
|
||||||
switch (_type)
|
switch (_type)
|
||||||
{
|
{
|
||||||
|
@ -1970,7 +1970,7 @@ Variant::operator std::string () const
|
||||||
void Variant::sqrt ()
|
void Variant::sqrt ()
|
||||||
{
|
{
|
||||||
if (_type == type_string)
|
if (_type == type_string)
|
||||||
Lexer::dequote (_string);
|
Lexer2::dequote (_string);
|
||||||
|
|
||||||
cast (type_real);
|
cast (type_real);
|
||||||
if (_real < 0.0)
|
if (_real < 0.0)
|
||||||
|
@ -2046,7 +2046,7 @@ void Variant::cast (const enum type new_type)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case type_string:
|
case type_string:
|
||||||
Lexer::dequote (_string);
|
Lexer2::dequote (_string);
|
||||||
switch (new_type)
|
switch (new_type)
|
||||||
{
|
{
|
||||||
case type_unknown: break;
|
case type_unknown: break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue