Chris Cannam
unread,Sep 15, 2014, 2:42:08 PM9/15/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to yeti...@googlegroups.com
I've been using the yeti.experimental.json module a bit.
I know that when I asked about this once before, it was suggested that
this wasn't the best long-term solution for json parse/serialise, but it
does work, with a few eccentricities.
One of the eccentricities is that it doesn't cope with whitespace in
your json file at all. Here's a patch that fixes that for me:
jsonParse str is string -> json =
(invalid = failWith . ("Invalid JSON: " ^);
- var tokens = matchAll
('\s++|([{:,}\[\]]|"(?:[^\\"]|\\["\\/bfnrtu])*+"|' ^
-
'-?\d++(?:\.\d++)?(?:[eE][+-]?\d++)?|null|true|false)')
- (`at` 0) invalid str;
+ nontoken s = if strTrim s == '' then [] else invalid s; fi;
+ var tokens = concat
+ (matchAll ('([{:,}\[\]]|"(?:[^\\"]|\\["\\/bfnrtu])*+"|' ^
+
'-?\d++(?:\.\d++)?(?:[eE][+-]?\d++)?|null|true|false)')
+ (take 1) nontoken str);
fetch () =
case tokens of
s :: rest:
tokens := rest;
case s of
- '': fetch ();
'{':
m = [:];
empty? tokens or head tokens != '}' loop
Chris