From 8a23faa8b06952aeda7b2229a4414e930cdd80a3 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 16 Jun 2024 13:50:06 +0200 Subject: [PATCH] number parser now reads scientific notation correctly, and throws exception if ill-formed --- util.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/util.cpp b/util.cpp index 136e892c..629a8d31 100644 --- a/util.cpp +++ b/util.cpp @@ -418,7 +418,15 @@ cld exp_parser::parse(int prio) { else if(number[0] >= 'a' && number[0] <= 'z') throw hr_parse_exception("unknown value: " + number); else if(number[0] >= 'A' && number[0] <= 'Z') throw hr_parse_exception("unknown value: " + number); else if(number[0] == '_') throw hr_parse_exception("unknown value: " + number); - else { std::stringstream ss; res = 0; ss << number; ss >> res; } + else { + if(among(number.back(), 'e', 'E')) { + if(eat("-")) number = number + "-" + next_token(); + else if(eat("+")) number = number + "+" + next_token(); + } + std::stringstream ss; res = 0; ss << number; + ss >> res; + if(ss.fail() || !ss.eof()) throw hr_parse_exception("unknown value: " + number); + } } while(true) { skip_white();