yason
yason copied to clipboard
trivial addition of NaN
NaNs are not supported in JSON by default (though in Perl parser apparently). Some JSON files contain them, though.
I found this to be a useful change in parse.lisp
;; export *allow-nan* and 'nan symbols in package.lisp
(defvar *allow-nan* t)
(defun parse-constant (input)
(let ((buffer (make-adjustable-string)))
(loop while (alpha-char-p (peek-char nil input))
do (vector-push-extend (read-char input) buffer))
(cond ((string= buffer "true")
(if *parse-json-booleans-as-symbols* 'true t))
((string= buffer "false")
(if *parse-json-booleans-as-symbols* 'false nil))
((string= buffer "null")
(if *parse-json-booleans-as-symbols* 'null nil))
((and *allow-nan* (string-equal buffer "nan")) ;; allow NaN, nan, etc
'nan)
(t
(error "invalid constant '~A'" buffer)))))
In a followup, I appended updated version that does NaN,nan,inf,infinity,+infinity,-infinity (case insensitive). In parse-number it switches to parse-symbol if it encounters a +/- followed by 'i' or 'I' (for infinity)
Also, the original yason didn't allow a number to have a leading plus sign like {x: +99} because parse% checked only for a leading (#- #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9). This is correct according to JSON standard, but the new version loosens this restriction to allow parsing of slightly non-compliant JSON.
Would you please create a pull-request here? Thanks a lot!
I think I sent a pull request from repository below, but I've never done this before, so have no idea if I did it right.
My modified version is: https://github.com/jetmonk/yason/tree/jetmonk-patch-1
I think I did this, but I've never done this before.
My modified version is: https://github.com/jetmonk/yason/tree/jetmonk-patch-1
Hmmm.... looking at the change I'm not really sure how you would achieve this, but it looks like you're reverting all my latest changes?
https://github.com/phmarek/yason/compare/master...jetmonk:jetmonk-patch-1
My only guess is that you did the changes against the old version and then told git to reset the git HEAD pointer to the (then newer) git HEAD without doing a merge or rebase?!
Sorry. 2nd pull request submitted. Hope this one is OK.