From efe15f575400d5adc254ea100e595550ebd544eb Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Mon, 28 Dec 2015 19:25:53 +0100 Subject: [PATCH] Parse +-Inf and NaN into JSON --- src/private/json.nim | 6 ++++++ src/yaml.nim | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/private/json.nim b/src/private/json.nim index 504d070..da3201c 100644 --- a/src/private/json.nim +++ b/src/private/json.nim @@ -38,6 +38,12 @@ proc jsonFromScalar(content: string, tag: TagId, of yTypeFloat: result.kind = JFloat result.fnum = parseFloat(content) + of yTypeFloatInf: + result.kind = JFloat + result.fnum = if content[0] == '-': NegInf else: Inf + of yTypeFloatNaN: + result.kind = JFloat + result.fnum = NaN of yTypeBoolTrue: result.kind = JBool result.bval = true diff --git a/src/yaml.nim b/src/yaml.nim index bb8c76c..95f5826 100644 --- a/src/yaml.nim +++ b/src/yaml.nim @@ -294,6 +294,13 @@ proc parseToJson*(s: Stream): seq[JsonNode] ## representation. The input may not contain any tags apart from those in ## ``coreTagLibrary``. Anchors and aliases will be resolved. Maps in the ## input must not contain non-scalars as keys. + ## + ## **Warning:** The special float values ``[+-]Inf`` and ``NaN`` will be + ## parsed into Nim's JSON structure without error. However, they cannot be + ## rendered to a JSON character stream, because these values are not part + ## of the JSON specification. Nim's JSON implementation currently does not + ## check for these values and will output invalid JSON when rendering one + ## of these values into a JSON character stream. proc parseToJson*(s: string): seq[JsonNode] ## see `parseToJson <#parseToJson,Stream,seq[JsonNode]>`_