mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 22:47:20 +02:00
Lexer: Added end-boundary sensitivity to ::isLiteral and ::isOneOf
This commit is contained in:
parent
3e74aa51e2
commit
391d527328
2 changed files with 12 additions and 10 deletions
|
@ -1101,14 +1101,16 @@ bool Lexer::isWord (std::string& token, Lexer::Type& type)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Lexer::isLiteral (const std::string& literal)
|
bool Lexer::isLiteral (const std::string& literal, bool endBoundary)
|
||||||
{
|
{
|
||||||
if (_text.find (literal, _cursor) == 0 &&
|
auto len = literal.length ();
|
||||||
(isEOS () ||
|
if (_text.find (literal, _cursor) == _cursor &&
|
||||||
Lexer::isWhitespace (_text[_cursor + literal.length ()]) ||
|
(! endBoundary ||
|
||||||
Lexer::isSingleCharOperator (_text[_cursor + literal.length ()])))
|
_text.length () == _cursor + len ||
|
||||||
|
Lexer::isWhitespace (_text[_cursor + len]) ||
|
||||||
|
Lexer::isSingleCharOperator (_text[_cursor + len])))
|
||||||
{
|
{
|
||||||
_cursor += literal.length ();
|
_cursor += len;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1116,10 +1118,10 @@ bool Lexer::isLiteral (const std::string& literal)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Lexer::isOneOf (const std::vector <std::string>& options)
|
bool Lexer::isOneOf (const std::vector <std::string>& options, bool endBoundary)
|
||||||
{
|
{
|
||||||
for (auto& item : options)
|
for (auto& item : options)
|
||||||
if (isLiteral (item))
|
if (isLiteral (item, endBoundary))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -105,8 +105,8 @@ public:
|
||||||
bool isDOM (std::string&, Lexer::Type&);
|
bool isDOM (std::string&, Lexer::Type&);
|
||||||
bool isIdentifier (std::string&, Lexer::Type&);
|
bool isIdentifier (std::string&, Lexer::Type&);
|
||||||
bool isWord (std::string&, Lexer::Type&);
|
bool isWord (std::string&, Lexer::Type&);
|
||||||
bool isLiteral (const std::string&);
|
bool isLiteral (const std::string&, bool);
|
||||||
bool isOneOf (const std::vector <std::string>&);
|
bool isOneOf (const std::vector <std::string>&, bool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _text;
|
std::string _text;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue