mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 00:57:19 +02:00
Lexer: Improved the recognition in ::isSet
This commit is contained in:
parent
6e710bf9b5
commit
f7ab55abeb
1 changed files with 31 additions and 34 deletions
|
@ -771,58 +771,55 @@ bool Lexer::isPair (std::string& token, Lexer::Type& type)
|
||||||
// Lexer::Type::set
|
// Lexer::Type::set
|
||||||
// a single number: 1
|
// a single number: 1
|
||||||
// a list of numbers: 1,3,5
|
// a list of numbers: 1,3,5
|
||||||
// a list of numbers: 1 3 5
|
|
||||||
// a range: 5-10
|
// a range: 5-10
|
||||||
// or a combination: 1,3,5-10 12
|
// or a combination: 1,3,5-10
|
||||||
//
|
//
|
||||||
// <id> [ - <id> ] [ , <id> [ - <id> ] ] ...
|
// <id> [ - <id> ] [ , <id> [ - <id> ] ] ...
|
||||||
bool Lexer::isSet (std::string& token, Lexer::Type& type)
|
bool Lexer::isSet (std::string& token, Lexer::Type& type)
|
||||||
{
|
{
|
||||||
std::size_t marker = _cursor;
|
std::size_t marker = _cursor;
|
||||||
bool moreThanJustANumber = false;
|
int count = 0;
|
||||||
|
std::string dummyToken;
|
||||||
|
Lexer::Type dummyType;
|
||||||
|
|
||||||
if (isDigit (_text[marker]))
|
do
|
||||||
{
|
{
|
||||||
++marker;
|
if (isInteger (dummyToken, dummyType))
|
||||||
while (isDigit (_text[marker]))
|
|
||||||
utf8_next_char (_text, marker);
|
|
||||||
|
|
||||||
if (_text[marker] == '-')
|
|
||||||
{
|
{
|
||||||
++marker;
|
++count;
|
||||||
while (isDigit (_text[marker]))
|
if (isLiteral ("-", false, false))
|
||||||
{
|
{
|
||||||
utf8_next_char (_text, marker);
|
if (isInteger (dummyToken, dummyType))
|
||||||
moreThanJustANumber = true;
|
++count;
|
||||||
}
|
else
|
||||||
}
|
|
||||||
|
|
||||||
while (_text[marker] == ',')
|
|
||||||
{
|
{
|
||||||
++marker;
|
|
||||||
while (isDigit (_text[marker]))
|
|
||||||
utf8_next_char (_text, marker);
|
|
||||||
|
|
||||||
moreThanJustANumber = true;
|
|
||||||
|
|
||||||
if (_text[marker] == '-')
|
|
||||||
{
|
|
||||||
++marker;
|
|
||||||
while (isDigit (_text[marker]))
|
|
||||||
utf8_next_char (_text, marker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (moreThanJustANumber)
|
|
||||||
{
|
|
||||||
token = _text.substr (_cursor, marker - _cursor);
|
|
||||||
type = Lexer::Type::set;
|
|
||||||
_cursor = marker;
|
_cursor = marker;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_cursor = marker;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (isLiteral (",", false, false));
|
||||||
|
|
||||||
|
// Success is multiple numbers, matching the pattern.
|
||||||
|
if (count > 1 &&
|
||||||
|
(isEOS () ||
|
||||||
|
isWhitespace (_text[_cursor]) ||
|
||||||
|
isHardBoundary (_text[_cursor], _text[_cursor + 1])))
|
||||||
|
{
|
||||||
|
token = _text.substr (marker, _cursor - marker);
|
||||||
|
type = Lexer::Type::set;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
_cursor = marker;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue