diff --git a/alib2cli/src/lexer/Lexer.h b/alib2cli/src/lexer/Lexer.h index 60733d5e38867f66bfc288a461a1e440bd49ef11..1d7c276be0c289e9a52e376a8667722abe724cdb 100644 --- a/alib2cli/src/lexer/Lexer.h +++ b/alib2cli/src/lexer/Lexer.h @@ -26,7 +26,7 @@ private: Hint m_hint; public: - enum class TokenType { + enum class TokenType : unsigned { IDENTIFIER, INTEGER, STRING, @@ -55,6 +55,10 @@ public: EOS }; + friend bool operator < ( TokenType first, TokenType second ) { + return static_cast < unsigned > ( first ) < static_cast < unsigned > ( second ); + } + static std::string tokenTypeToString ( TokenType type ) { switch ( type ) { case TokenType::IDENTIFIER : @@ -141,6 +145,10 @@ public: return out << ( std::string ) token; } + bool operator < ( const Token & token ) const { + return std::tie ( m_type, m_value ) < std::tie ( token.m_type, token.m_value ); // m_raw omitted intentionally + } + }; explicit Lexer ( CharSequence source ) : m_source ( std::move ( source ) ), m_hint ( Hint::NONE ) {