mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-04 12:28:35 +02:00
Parsing
- Created A3::is_operator to allow for more complex processing. Renamed old A3::is_operator to A3::which_operator.
This commit is contained in:
parent
562fd8ce3c
commit
1994240899
2 changed files with 24 additions and 5 deletions
26
src/A3.cpp
26
src/A3.cpp
|
@ -738,7 +738,7 @@ const A3 A3::tokenize (const A3& input) const
|
|||
found_something_after_sequence = true;
|
||||
}
|
||||
|
||||
else if (n.getOneOf (operators, s))
|
||||
else if (is_operator (operators, n, s))
|
||||
{
|
||||
output.push_back (Arg (s, Arg::cat_op));
|
||||
if (found_sequence)
|
||||
|
@ -1201,13 +1201,13 @@ const A3 A3::postfix (const A3& input) const
|
|||
else
|
||||
throw std::string ("Mismatched parentheses in expression");
|
||||
}
|
||||
else if (is_operator (arg->_raw, type, precedence, associativity))
|
||||
else if (which_operator (arg->_raw, type, precedence, associativity))
|
||||
{
|
||||
char type2;
|
||||
int precedence2;
|
||||
char associativity2;
|
||||
while (op_stack.size () > 0 &&
|
||||
is_operator (op_stack.back ()._raw, type2, precedence2, associativity2) &&
|
||||
which_operator (op_stack.back ()._raw, type2, precedence2, associativity2) &&
|
||||
((associativity == 'l' && precedence <= precedence2) ||
|
||||
(associativity == 'r' && precedence < precedence2)))
|
||||
{
|
||||
|
@ -1731,6 +1731,24 @@ bool A3::is_integer (Nibbler& n, int& i)
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool A3::is_operator (
|
||||
std::vector <std::string>& operators,
|
||||
Nibbler& n,
|
||||
std::string& result)
|
||||
{
|
||||
n.save ();
|
||||
|
||||
if (n.getOneOf (operators, result) &&
|
||||
isTokenEnd (n.str (), n.cursor () - 1))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
n.restore ();
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool A3::extract_pattern (const std::string& input, std::string& pattern)
|
||||
{
|
||||
|
@ -1967,7 +1985,7 @@ bool A3::extract_uuid (
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool A3::is_operator (
|
||||
bool A3::which_operator (
|
||||
const std::string& input,
|
||||
char& type,
|
||||
int& precedence,
|
||||
|
|
3
src/A3.h
3
src/A3.h
|
@ -88,6 +88,7 @@ public:
|
|||
static bool is_tag (Nibbler&, std::string&);
|
||||
static bool is_number (Nibbler&, double&);
|
||||
static bool is_integer (Nibbler&, int&);
|
||||
static bool is_operator (std::vector <std::string>&, Nibbler&, std::string&);
|
||||
|
||||
static bool extract_pattern (const std::string&, std::string&);
|
||||
static bool extract_tag (const std::string&, char&, std::string&);
|
||||
|
@ -97,7 +98,7 @@ public:
|
|||
static bool extract_id (const std::string&, std::vector <int>&);
|
||||
static bool extract_uuid (const std::string&, std::vector <std::string>&);
|
||||
|
||||
static bool is_operator (const std::string&, char&, int&, char&);
|
||||
static bool which_operator (const std::string&, char&, int&, char&);
|
||||
|
||||
void dump (const std::string&);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue