diff --git a/src/Lexer.cpp b/src/Lexer.cpp index a0a69b91..43ae4764 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -55,6 +56,7 @@ bool Lexer::token (std::string& token, Lexer::Type& type) return false; if (isString (token, type, "'\"") || + isDate (token, type) || isURL (token, type) || isHexNumber (token, type) || isNumber (token, type) || @@ -95,6 +97,7 @@ const std::string Lexer::typeName (const Lexer::Type& type) case Lexer::Type::pattern: return "pattern"; case Lexer::Type::op: return "op"; case Lexer::Type::word: return "word"; + case Lexer::Type::date: return "date"; } return "unknown"; @@ -375,6 +378,25 @@ bool Lexer::isString (std::string& token, Lexer::Type& type, const std::string& return false; } +//////////////////////////////////////////////////////////////////////////////// +// Lexer::Type::date +// +bool Lexer::isDate (std::string& token, Lexer::Type& type) +{ + // Try an ISO date parse. + std::size_t i = 0; + Datetime d; + if (d.parse (_text.substr (_cursor), i, Lexer::dateFormat)) + { + type = Lexer::Type::date; + token = _text.substr (_cursor, i); + _cursor += i; + return true; + } + + return false; +} + //////////////////////////////////////////////////////////////////////////////// // Lexer::Type::hex // 0xX+ @@ -617,6 +639,7 @@ std::string Lexer::typeToString (Lexer::Type type) else if (type == Lexer::Type::pattern) return std::string ("\033[37;42m") + "pattern" + "\033[0m"; else if (type == Lexer::Type::op) return std::string ("\033[38;5;7m\033[48;5;203m") + "op" + "\033[0m"; else if (type == Lexer::Type::word) return std::string ("\033[38;5;15m\033[48;5;236m") + "word" + "\033[0m"; + else if (type == Lexer::Type::date) return std::string ("\033[38;5;15m\033[48;5;34m") + "date" + "\033[0m"; else return std::string ("\033[37;41m") + "unknown" + "\033[0m"; } diff --git a/src/Lexer.h b/src/Lexer.h index f5bfbf62..1f9c401a 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -45,7 +45,8 @@ public: path, pattern, op, - word }; + word, + date }; explicit Lexer (const std::string&); bool token (std::string&, Lexer::Type&); @@ -73,6 +74,7 @@ public: // Stream Classifiers. bool isEOS () const; bool isString (std::string&, Lexer::Type&, const std::string&); + bool isDate (std::string&, Lexer::Type&); bool isNumber (std::string&, Lexer::Type&); bool isInteger (std::string&, Lexer::Type&); bool isHexNumber (std::string&, Lexer::Type&);