1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-23 13:07:16 +00:00

number parser now reads scientific notation correctly, and throws exception if ill-formed

This commit is contained in:
Zeno Rogue 2024-06-16 13:50:06 +02:00
parent 85874dbb1c
commit 8a23faa8b0

View File

@ -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();