On 6/8/10, Oliver Hunt <[email protected]> wrote: > On Jun 8, 2010, at 8:46 PM, Garrett Smith wrote: >
[...] >> IF anyone has a correct JSON parser, I would appreciate it. Also, are >> there any good test suites for JSON? > > I spent quite a bit of time ensuring JSC's JSON parser exactly matched the > spec grammar, and hence exhibits this behaviour so I believe the parser in > JSC is "correct" -- if you're interested the code can be found at (note > that it's under an MIT style license) > http://trac.webkit.org/browser/trunk/JavaScriptCore/runtime/LiteralParser.cpp I see, so \d. is no good. I was more looking for a few regexps to fill in a tight function for the FAQ. While your C++ looks clean, transliterating that would surely be a no-go for the FAQ. Strategy-outline: // TODO: define validJSONExp. var parseJSON = NATIVE_JSON_PARSE_SUPPORT ? function(responseText) { return JSON.parse(responseText); } : function(responseText) { if(validJSONExp.test(responseText)) { return new Function("return(" + responseText + ")")(); } else { throw SyntaxError("JSON parse error"); } }; The goal is to essentially match exactly what JSON parse would do for 1 argument and for the FAQ, the code would be tighter to use a RegExp. I'll figure it out. > At the time I recall talking a bit with Hallvord Steen of Opera, and he was > working on a testsuite of some sort but I can no longer recall the url. > OK. Good to know. > That said I think allowing '1.' (etc) makes sense as it's fairly standard > across multiple programming languages, and I am unaware of any specific > reason for disallowing it. > It seems like it would have made sense. Now, well, no, not now; the spec is released and implemented like that in at least two implementations. > In the long term I don't see changing the grammar to allow a trailing period > as being harmful as it's a relaxation. In the short term vendors that > follow the spec may fail to parse content :-( > Changing it now would probably just create more confusion. _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

