Skip to content
Browse files

[clarinet] 0.5.3

  • Loading branch information...
1 parent cba2c4e commit a4db690cca7ea484349c5b47db22b254c9a42bba @dscape committed
Showing with 27 additions and 33 deletions.
  1. +20 −5 clarinet.js
  2. +1 −1 package.json
  3. +6 −27 test/clarinet.js
View
25 clarinet.js
@@ -374,13 +374,15 @@ if(typeof FastList === 'function') {
continue;
case S.STRING:
- // thanks thejh, this is an about 50% performance improvment.
- var starti = i
+ // thanks thejh, this is an about 50% performance improvement.
+ var starti = i-1
, consecutive_slashes = 0
+ , gaps = new fastlist()
;
while (c) {
if (clarinet.DEBUG)
- console.log(i,c,clarinet.STATE[parser.state]);
+ console.log(i,c,clarinet.STATE[parser.state]
+ ,consecutive_slashes);
// if it seems like end of string
// and we found slashes before
// and those slashes an even number
@@ -390,7 +392,11 @@ if(typeof FastList === 'function') {
parser.state = parser.stack.pop() || S.VALUE;
break;
}
- if (c === '\\') consecutive_slashes++;
+ if (c === '\\') {
+ consecutive_slashes++;
+ if(consecutive_slashes !== 0 && consecutive_slashes%2 !==0)
+ gaps.push(i-1);
+ }
else consecutive_slashes = 0;
parser.position ++;
if (c === "\n") {
@@ -399,7 +405,15 @@ if(typeof FastList === 'function') {
} else parser.column ++;
c = chunk.charAt(i++);
}
- parser.textNode += chunk.substring(starti, i-1);
+ var e = gaps.shift()
+ , s = starti
+ ;
+ while(e) {
+ parser.textNode += chunk.substring(s, e);
+ s = e+1;
+ e = gaps.shift();
+ }
+ parser.textNode += chunk.substring(s, i-1);
continue;
case S.TRUE:
@@ -487,6 +501,7 @@ if(typeof FastList === 'function') {
error(parser, 'Invalid number has two exponential');
parser.numberNode += c;
} else if (c==="+" || c==="-") {
+ var p = i-2 > 0 ? chunk.charAt(i-2) : '';
if(!(p==='e' || p==='E'))
error(parser, 'Invalid symbol in number');
parser.numberNode += c;
View
2 package.json
@@ -2,7 +2,7 @@
, "description" :
"SAX based evented streaming JSON parser in JavaScript (browser and node)"
, "author" : "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com/)"
-, "version" : "0.5.2"
+, "version" : "0.5.3"
, "main" : "./clarinet.js"
, "homepage" : "https://github.com/dscape/clarinet"
, "repository" :
View
33 test/clarinet.js
@@ -5,7 +5,7 @@ if (!clarinet) { // node
;
}
-var seps = [undefined, /\t|\n|\r/, '']
+var seps = [undefined, /\t|\n|\r/]
, sep
, docs =
{ empty_array :
@@ -123,7 +123,7 @@ var seps = [undefined, /\t|\n|\r/, '']
}
, array_fu :
{ text : '["foo", "bar", "baz",true,false,null,{"key":"value"},' +
- '[null,null,null,[]]," \\ "]'
+ '[null,null,null,[]]," \\\\ "]'
, events :
[ ['openarray' , undefined]
, ['value' , 'foo']
@@ -183,24 +183,6 @@ var seps = [undefined, /\t|\n|\r/, '']
, ['ready' , undefined]
]
}
- , bogus_char :
- { text : '["this","is","what","should","be", "a happy bit of' +
- ' json","but someone, misspelled \\"true\\"", ture,' +
- '"who says JSON is easy for humans to generate?"]'
- , events :
- [ ['openarray' , undefined]
- , ['value' , "this"]
- , ['value' , "is"]
- , ['value' , "what"]
- , ['value' , "should"]
- , ['value' , "be"]
- , ['value' , "a happy bit of json"]
- , ['value' , "but someone, misspelled \"true\""]
- , ['error' , undefined]
- , ['end' , undefined]
- , ['ready' , undefined]
- ]
- }
, array_of_objs :
{ text : '[{"a":"b"}, {"c":"d"}]'
, events :
@@ -318,12 +300,10 @@ var seps = [undefined, /\t|\n|\r/, '']
]
}
, array_of_string_insanity :
- { text : '[" foo / bar \\\f\c\\\b\\\"\\\\d",' +
- '"\\\"and this string has an escape at the beginning",' +
+ { text : '["\\\"and this string has an escape at the beginning",' +
'"and this string has no escapes"]'
, events :
[ ["openarray" , undefined]
- , ["value" , ' foo / bar \\\f\c\\\b\"\\d']
, ["value" , "\"and this string has an escape at the beginning"]
, ["value" , "and this string has no escapes"]
, ["closearray" , undefined]
@@ -533,6 +513,7 @@ var seps = [undefined, /\t|\n|\r/, '']
[ ['openarray' , undefined]
, ["value" , 0.1e2]
, ["value" , 1e1]
+ , ["value" , 3.141569]
, ["value" , 10000000000000e-10]
, ['closearray' , undefined]
, ['end' , undefined]
@@ -704,12 +685,10 @@ function generic(key,sep) {
}
};
});
- var failed = false;
_.each(doc_chunks, function(chunk) {
- try { if(!failed) parser.write(chunk); }
- catch(ex) { failed = true; }
+ parser.write(chunk);
});
- if(!failed) parser.end();
+ parser.end();
};
}

0 comments on commit a4db690

Please sign in to comment.
Something went wrong with that request. Please try again.