Add --expr, an option to parse a single expression (suitable for JSON)

This commit is contained in:
Mihai Bazon
2013-05-15 13:27:23 +03:00
parent caa8896a8a
commit ca3388cf5a
2 changed files with 14 additions and 5 deletions

View File

@@ -588,9 +588,10 @@ var ATOMIC_START_TOKEN = array_to_hash([ "atom", "num", "string", "regexp", "nam
function parse($TEXT, options) {
options = defaults(options, {
strict : false,
filename : null,
toplevel : null
strict : false,
filename : null,
toplevel : null,
expression : false
});
var S = {
@@ -1386,6 +1387,10 @@ function parse($TEXT, options) {
return ret;
};
if (options.expression) {
return expression(true);
}
return (function(){
var start = S.token;
var body = [];