hjson / hjson-js

Hjson for JavaScript
https://hjson.github.io/
MIT License
416 stars 49 forks source link

dsf.math cannot handle "nan" without newline following #53

Closed waynepiekarski closed 2 years ago

waynepiekarski commented 3 years ago

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?

waynepiekarski commented 3 years ago

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 ...

trobro commented 2 years ago

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