From 8d3cc2181e80d9d1bd15957226191611bf84d2bc Mon Sep 17 00:00:00 2001 From: haxala1r Date: Tue, 30 Sep 2025 20:58:56 +0300 Subject: [PATCH] Added equality operator to Token, will be useful for testing. --- src/include/lex.hpp | 2 ++ src/lex.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/include/lex.hpp b/src/include/lex.hpp index 1329a08..add0c91 100644 --- a/src/include/lex.hpp +++ b/src/include/lex.hpp @@ -19,6 +19,8 @@ enum TokenType { struct Token { enum TokenType type; std::variant value; + + bool operator==(Token const& other); }; std::ostream &operator<<(std::ostream &os, Token const &t); diff --git a/src/lex.cpp b/src/lex.cpp index d04ea83..ce4d7a8 100644 --- a/src/lex.cpp +++ b/src/lex.cpp @@ -23,6 +23,10 @@ std::ostream &operator<<(std::ostream &os, Token const &t) { return os; } +bool Token::operator==(Token const& other) { + return this->type == other.type && this->value == other.value; +} + bool ispunct(char c) { for (char i : "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") { if (i == c) return true;