Fixed an error in double parsing logic
All checks were successful
ci/woodpecker/push/workflow Pipeline was successful

This commit is contained in:
2025-09-30 21:32:02 +03:00
committed by Emin Arslan
parent 8d3cc2181e
commit acc9b94c1f
2 changed files with 10 additions and 8 deletions

View File

@@ -19,9 +19,8 @@ enum TokenType {
struct Token { struct Token {
enum TokenType type; enum TokenType type;
std::variant<int64_t, double, std::string> value; std::variant<int64_t, double, std::string> value;
bool operator==(Token const& other);
}; };
bool operator==(Token const& one, Token const& other);
std::ostream &operator<<(std::ostream &os, Token const &t); std::ostream &operator<<(std::ostream &os, Token const &t);
class Lexer { class Lexer {

View File

@@ -23,8 +23,8 @@ std::ostream &operator<<(std::ostream &os, Token const &t) {
return os; return os;
} }
bool Token::operator==(Token const& other) { bool operator==(Token const& one, Token const& other) {
return this->type == other.type && this->value == other.value; return one.type == other.type && one.value == other.value;
} }
bool ispunct(char c) { bool ispunct(char c) {
@@ -65,9 +65,10 @@ Token Lexer::lexNumOrSym() {
// ... this will almost certainly change, won't it? // ... this will almost certainly change, won't it?
string s = acc.str(); string s = acc.str();
string iterate_over = (s.at(0) == '-') ? s.substr(1) : s; string iterate_over = (s.at(0) == '-') ? s.substr(1) : s;
bool is_number = true; bool is_number = false;
bool dot_seen = false; bool dot_seen = false;
for (char c : s) { for (char c : iterate_over) {
if (c == '.') { if (c == '.') {
if (dot_seen) { if (dot_seen) {
is_number = false; is_number = false;
@@ -76,14 +77,16 @@ Token Lexer::lexNumOrSym() {
dot_seen = true; dot_seen = true;
continue; continue;
} }
if (!isdigit(c)) { if (isdigit(c)) {
is_number = true;
} else {
is_number = false; is_number = false;
break; break;
} }
} }
if (is_number && dot_seen) { if (is_number && dot_seen) {
if (s == ".") if (iterate_over == ".")
return {TokenType::Symbol, s}; return {TokenType::Symbol, s};
return {TokenType::Double, stod(s)}; return {TokenType::Double, stod(s)};
} else if (is_number) { } else if (is_number) {