Skip to content
Snippets Groups Projects
Commit 9e3a0991 authored by Jan Trávníček's avatar Jan Trávníček Committed by Jan Travnicek
Browse files

make lexer tokens comparable

parent 2185ac3a
No related branches found
No related tags found
1 merge request!117Merge jt
...@@ -26,7 +26,7 @@ private: ...@@ -26,7 +26,7 @@ private:
Hint m_hint; Hint m_hint;
   
public: public:
enum class TokenType { enum class TokenType : unsigned {
IDENTIFIER, IDENTIFIER,
INTEGER, INTEGER,
STRING, STRING,
...@@ -55,6 +55,10 @@ public: ...@@ -55,6 +55,10 @@ public:
EOS EOS
}; };
   
friend bool operator < ( TokenType first, TokenType second ) {
return static_cast < unsigned > ( first ) < static_cast < unsigned > ( second );
}
static std::string tokenTypeToString ( TokenType type ) { static std::string tokenTypeToString ( TokenType type ) {
switch ( type ) { switch ( type ) {
case TokenType::IDENTIFIER : case TokenType::IDENTIFIER :
...@@ -141,6 +145,10 @@ public: ...@@ -141,6 +145,10 @@ public:
return out << ( std::string ) token; 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 ) { explicit Lexer ( CharSequence source ) : m_source ( std::move ( source ) ), m_hint ( Hint::NONE ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment