hjson-js
hjson-js copied to clipboard
dsf.math cannot handle "nan" without newline following
When trying to parse nan values using dsf.math, I get an error with the following simple test case:
var hjson = require('hjson');
var dsf = [ hjson.dsf.math() ];
hjson.parse(`{ A: nan, B: 1.0 }`, { dsf: dsf });
Error: End of input while parsing an object (missing '}') at line 1,18 >>> A: nan, B: 1.0 } ...
However, if you put a newline after the nan, then it works fine:
hjson.parse(`{ A: nan,
B: 1.0 }`, { dsf: dsf });
I'm new to hjson, but is there a trick to getting this to work, or is there a bug in the parser?
I also have another case where the parser won't accept floats with a leading + symbol, requiring a newline after as well:
hjson.parse(`{ A: +123.45, B: -987.65 }`, { dsf: dsf });
Error: End of input while parsing an object (missing '}') at line 1,26 >>> A: +123.45, B: -987 ...
nan
is not recognized as a number by Hjson. It is therefore treated as an unquoted string, and then everything after nan
on the same line is seen as part of the unquoted string.
A leading +
is also not recognized as a number, also gets treated as an unquoted string.
See syntax definition of number:
https://hjson.github.io/syntax.html