Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[clarinet] added fastlist if available

  • Loading branch information...
commit 412f105c5c6ea47688eda4f9a3fbb381381ea261 1 parent 235babb
@dscape authored
Showing with 40 additions and 9 deletions.
  1. +12 −9 clarinet.js
  2. +28 −0 test/clarinet.js
View
21 clarinet.js
@@ -1,6 +1,10 @@
;(function (clarinet) {
// non node-js needs to set clarinet debug on root
- var env = process && process.env ? process.env : window;
+ var env = process && process.env ? process.env : window
+ , fastlist = FastList ||
+ (typeof require === 'function' && require('fastlist')) ||
+ Array
+ ;
clarinet.parser = function (opt) { return new CParser(opt);};
clarinet.CParser = CParser;
@@ -105,17 +109,16 @@
var parser = this;
clearBuffers(parser);
- parser.q = parser.c = "";
parser.bufferCheckPosition = clarinet.MAX_BUFFER_LENGTH;
- parser.opt = opt || {};
- parser.tags = [];
- parser.closed = parser.closedRoot = parser.sawRoot = false;
- parser.tag = parser.error = null;
- parser.state = S.BEGIN;
- parser.stack = [];
+ parser.q = parser.c = "";
+ parser.opt = opt || {};
+ parser.closed = parser.closedRoot = parser.sawRoot = false;
+ parser.tag = parser.error = null;
+ parser.state = S.BEGIN;
+ parser.stack = new fastlist();
// mostly just for error reporting
parser.position = parser.column = 0;
- parser.line = 1;
+ parser.line = 1;
emit(parser, "onready");
}
View
28 test/clarinet.js
@@ -40,6 +40,34 @@ var seps = [undefined, /\t|\n|\r| /, '']
, ['ready' , undefined]
]
}
+ , nested_array :
+ { text : '{"a":["b", "c"]}'
+ , events :
+ [ ["openobject" , "a"]
+ , ['openarray' , undefined]
+ , ['value' , 'b']
+ , ['value' , 'c']
+ , ['closearray' , undefined]
+ , ["closeobject" , undefined]
+ , ['end' , undefined]
+ , ['ready' , undefined]
+ ]
+ }
+ , array_of_objs :
+ { text : '[{"a":"b"}, {"c":"d"}]'
+ , events :
+ [ ['openarray' , undefined]
+ , ["openobject" , "a"]
+ , ['value' , 'b']
+ , ["closeobject" , undefined]
+ , ["openobject" , "c"]
+ , ['value' , 'd']
+ , ["closeobject" , undefined]
+ , ['closearray' , undefined]
+ , ['end' , undefined]
+ , ['ready' , undefined]
+ ]
+ }
};
function generic(key,sep) {
Please sign in to comment.
Something went wrong with that request. Please try again.