From: Karol Gugala Date: Wed, 27 Jan 2021 19:34:00 +0000 (+0100) Subject: frontend: json: parse negative values X-Git-Tag: working-ls180~74 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cc7d18d29a5314c6350b7378bc788f48f3925337;p=yosys.git frontend: json: parse negative values Signed-off-by: Karol Gugala --- diff --git a/frontends/json/jsonparse.cc b/frontends/json/jsonparse.cc index 1b34aaf3a..312f6d3be 100644 --- a/frontends/json/jsonparse.cc +++ b/frontends/json/jsonparse.cc @@ -72,10 +72,17 @@ struct JsonNode break; } - if ('0' <= ch && ch <= '9') + if (('0' <= ch && ch <= '9') || ch == '-') { + bool negative = false; type = 'N'; - data_number = ch - '0'; + if (ch == '-') { + data_number = 0; + negative = true; + } else { + data_number = ch - '0'; + } + data_string += ch; while (1) @@ -97,6 +104,7 @@ struct JsonNode data_string += ch; } + data_number = negative ? -data_number : data_number; data_string = ""; break;