- Added special look-ahead rules to remove cases where '3M' was considered
  a number.
This commit is contained in:
Paul Beckingham 2011-08-13 14:10:24 -04:00
parent e238b94d1b
commit 7aa7fe083f
2 changed files with 82 additions and 6 deletions

View file

@ -592,9 +592,28 @@ const A3 A3::extract_modifications () const
else if (! before_command) else if (! before_command)
{ {
// "rc" and "override" categories are not included.
if (arg->_category == "rc" || if (arg->_category == "rc" ||
arg->_category == "override") arg->_category == "override")
{
; ;
}
// Any arguments identified as "id" or "uuid" are downgraded to "word".
// This is because any true "id" or "uuid" values have already been
// removed in the filter. What remains are numeric arguments in command
// lines that do not otherwise include an id, such as:
//
// task add Read the article on page 2
else if (arg->_category == "id" ||
arg->_category == "uuid")
{
Arg downgrade (*arg);
downgrade._category = "word";
mods.push_back (downgrade);
}
// Everything else is included.
else else
mods.push_back (*arg); mods.push_back (*arg);
} }
@ -780,14 +799,14 @@ const A3 A3::tokenize (const A3& input) const
} }
} }
else if (n.getNumber (d)) else if (is_number (n, d))
{ {
output.push_back (Arg (format (d), "num")); output.push_back (Arg (format (d), "num"));
if (found_sequence) if (found_sequence)
found_something_after_sequence = true; found_something_after_sequence = true;
} }
else if (n.getInt (i)) else if (is_integer (n, i))
{ {
output.push_back (Arg (format (i), "int")); output.push_back (Arg (format (i), "int"));
if (found_sequence) if (found_sequence)
@ -1548,10 +1567,17 @@ bool A3::is_id (Nibbler& n, std::string& result)
} }
} }
std::string::size_type end = n.cursor (); char next = n.next ();
n.restore (); if (next == '\0' ||
if (n.getN (end - start, result)) next == ')' ||
return true; next == ' ' ||
next == '-')
{
std::string::size_type end = n.cursor ();
n.restore ();
if (n.getN (end - start, result))
return true;
}
} }
n.restore (); n.restore ();
@ -1602,6 +1628,54 @@ bool A3::is_tag (Nibbler& n, std::string& result)
return false; return false;
} }
////////////////////////////////////////////////////////////////////////////////
// <number> followed by either: '\0', ')' ',' or '-'.
//
// This prevents the interpretation of '3M' as a number.
bool A3::is_number (Nibbler& n, double& d)
{
n.save ();
if (n.getNumber (d))
{
char next = n.next ();
if (next == '\0' ||
next == ')' ||
next == ' ' ||
next == '-')
{
return true;
}
n.restore ();
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
// <integer> followed by either: '\0', ')' ',' or '-'.
//
// This prevents the interpretation of '3M' as a number.
bool A3::is_integer (Nibbler& n, int& i)
{
n.save ();
if (n.getInt (i))
{
char next = n.next ();
if (next == '\0' ||
next == ')' ||
next == ' ' ||
next == '-')
{
return true;
}
n.restore ();
}
return false;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool A3::extract_pattern (const std::string& input, std::string& pattern) bool A3::extract_pattern (const std::string& input, std::string& pattern)
{ {

View file

@ -130,6 +130,8 @@ public:
static bool is_id (Nibbler&, std::string&); static bool is_id (Nibbler&, std::string&);
static bool is_uuid (Nibbler&, std::string&); static bool is_uuid (Nibbler&, std::string&);
static bool is_tag (Nibbler&, std::string&); static bool is_tag (Nibbler&, std::string&);
static bool is_number (Nibbler&, double&);
static bool is_integer (Nibbler&, int&);
static bool extract_pattern (const std::string&, std::string&); static bool extract_pattern (const std::string&, std::string&);
static bool extract_tag (const std::string&, char&, std::string&); static bool extract_tag (const std::string&, char&, std::string&);