|
@@ -42,7 +42,7 @@ class JsonParser {
|
|
|
If `str` is null, the result is unspecified.
|
|
|
**/
|
|
|
static public inline function parse(str : String) : Dynamic {
|
|
|
- return new JsonParser(str).parseRec();
|
|
|
+ return new JsonParser(str).doParse();
|
|
|
}
|
|
|
|
|
|
var str : String;
|
|
@@ -53,6 +53,20 @@ class JsonParser {
|
|
|
this.pos = 0;
|
|
|
}
|
|
|
|
|
|
+ function doParse() : Dynamic {
|
|
|
+ var result = parseRec();
|
|
|
+ var c;
|
|
|
+ while( !StringTools.isEof(c = nextChar()) ) {
|
|
|
+ switch( c ) {
|
|
|
+ case ' '.code, '\r'.code, '\n'.code, '\t'.code:
|
|
|
+ // allow trailing whitespace
|
|
|
+ default:
|
|
|
+ invalidChar();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
function parseRec() : Dynamic {
|
|
|
while( true ) {
|
|
|
var c = nextChar();
|
|
@@ -222,7 +236,7 @@ class JsonParser {
|
|
|
if (minus) minus = false;
|
|
|
digit = true; zero = false;
|
|
|
case '.'.code :
|
|
|
- if (minus || point) invalidNumber(start);
|
|
|
+ if (minus || point || e) invalidNumber(start);
|
|
|
digit = false; point = true;
|
|
|
case 'e'.code, 'E'.code :
|
|
|
if (minus || zero || e) invalidNumber(start);
|
|
@@ -237,6 +251,7 @@ class JsonParser {
|
|
|
}
|
|
|
if (end) break;
|
|
|
}
|
|
|
+
|
|
|
var f = Std.parseFloat(str.substr(start, pos - start));
|
|
|
var i = Std.int(f);
|
|
|
return if( i == f ) i else f;
|