From 9e3a09919c18f72e95af6c9f87493fb7fbbbf501 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Thu, 14 Nov 2019 07:53:41 +0100
Subject: [PATCH] make lexer tokens comparable

---
 alib2cli/src/lexer/Lexer.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/alib2cli/src/lexer/Lexer.h b/alib2cli/src/lexer/Lexer.h
index 60733d5e38..1d7c276be0 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 ) {
-- 
GitLab