1
0
mirror of synced 2025-12-15 02:37:59 +08:00

command line interface and updates for npm

This commit is contained in:
Zach Carter
2011-05-01 17:36:27 -04:00
parent ac7b47930b
commit 9c1023cfb1
12 changed files with 486 additions and 357 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
node_modules/jison
node_modules/test
node_modules/uglify-js
node_modules/.bin

View File

@@ -1,32 +0,0 @@
#!/usr/bin/env narwhal
var FILE = require("file"),
ENV = require("system").env,
OS = require("os"),
jake = require("jake");
var cwd = FILE.path(FILE.cwd());
jake.task("build", ["build:commonjs", "build:web"]);
jake.task("build:commonjs", function () {
OS.system(['jison', 'src/grammar.jison', 'src/grammar.jisonlex']);
OS.system(['mv', 'grammar.js', 'lib/jsonlint.js']);
});
jake.task("build:web", function () {
var lint = cwd.join('lib', 'jsonlint.js');
var sourceArray = ["var jsonlint = (function(){var require=true,module=false;var exports={};"];
sourceArray.push(lint.read({charset: "utf-8"}),
"return exports;})()");
var source = require("jsmin").encode(sourceArray.join("\n"));
var stream = cwd.join('web', 'jsonlint.js').open("w");
stream.print(source).close();
});
jake.task("test", function () {
OS.system(['narwhal', 'tests/all-tests.js']);
});

11
Makefile Normal file
View File

@@ -0,0 +1,11 @@
all: build test
build:
jison src/jsonlint.y src/jsonlint.l
mv jsonlint.js lib/jsonlint.js
node scripts/bundle.js | uglifyjs > web/jsonlint.js
test: lib/jsonlint.js test/all-tests.js
node test/all-tests.js

View File

@@ -3,3 +3,27 @@ JSON Lint
A pure [JavaScript version](http://zaach.github.com/jsonlint/) of the service provided at [jsonlin.com](http://jsonlint.com).
## Command line interface
Install jsonlint with npm to use the command line interface:
npm install jsonlint -g
Validate a file like so:
jsonlint myfile.json
or pipe input into stdin:
cat myfile.json | jsonlint
jsonlint will either report a syntax error with details or pretty print the source if it is valid.
## Module interface
I'm not sure why you wouldn't use the built in `JSON.parse` but you can use jsonlint from a CommonJS module:
var jsonlint = require("jsonlint");
jsonlint.parse('{"creative?": false}');
It returns the parsed object or throws an `Error`.

33
lib/cli.js Executable file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env node
var sys = require("sys");
var parser = require("./jsonlint").parser;
function parse (source) {
try {
sys.puts(JSON.stringify(parser.parse(source),null," "));
} catch (e) {
sys.puts(e);
process.exit(1);
}
}
function main (args) {
var source = '';
if (args[1]) {
source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
parse(source);
} else {
var stdin = process.openStdin();
stdin.setEncoding('utf8');
stdin.on('data', function (chunk) {
source += chunk.toString('utf8');
});
stdin.on('end', function () {
parse(source);
});
}
}
main(process.argv.slice(1));

View File

@@ -1,166 +1,249 @@
/* Jison generated parser */
var grammar = (function(){
var parser = {trace: function trace() {
},
var jsonlint = (function(){
var parser = {trace: function trace() { },
yy: {},
symbols_: {"JSONString":2,"STRING":3,"JSONNumber":4,"NUMBER":5,"JSONNullLiteral":6,"NULL":7,"JSONBooleanLiteral":8,"TRUE":9,"FALSE":10,"JSONText":11,"JSONObject":12,"JSONArray":13,"JSONValue":14,"{":15,"}":16,"JSONMemberList":17,"JSONMember":18,":":19,",":20,"[":21,"]":22,"JSONElementList":23,"$accept":0,"$end":1},
terminals_: {"3":"STRING","5":"NUMBER","7":"NULL","9":"TRUE","10":"FALSE","15":"{","16":"}","19":":","20":",","21":"[","22":"]"},
productions_: [0,[2,1],[4,1],[6,1],[8,1],[8,1],[11,1],[11,1],[14,1],[14,1],[14,1],[14,1],[14,1],[14,1],[12,2],[12,3],[18,3],[17,1],[17,3],[13,2],[13,3],[23,1],[23,3]],
performAction: function anonymous(yytext, yyleng, yylineno, yy) {
var $$ = arguments[5], $0 = arguments[5].length;
switch (arguments[4]) {
case 1:
this.$ = yytext;
symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONObject":13,"JSONArray":14,"JSONValue":15,"{":16,"}":17,"JSONMemberList":18,"JSONMember":19,":":20,",":21,"[":22,"]":23,"JSONElementList":24,"$accept":0,"$end":1},
terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",16:"{",17:"}",20:":",21:",",22:"[",23:"]"},
productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,1],[12,1],[15,1],[15,1],[15,1],[15,1],[15,1],[15,1],[13,2],[13,3],[19,3],[18,1],[18,3],[14,2],[14,3],[24,1],[24,3]],
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
var $0 = $$.length - 1;
switch (yystate) {
case 1:this.$ = yytext;
break;
case 2:
this.$ = Number(yytext);
case 2:this.$ = Number(yytext);
break;
case 3:
this.$ = null;
case 3:this.$ = null;
break;
case 4:
this.$ = true;
case 4:this.$ = true;
break;
case 5:
this.$ = false;
case 5:this.$ = false;
break;
case 6:
return this.$ = $$[$0 - 1 + 1 - 1];
case 6:return this.$ = $$[$0];
break;
case 7:
return this.$ = $$[$0 - 1 + 1 - 1];
case 7:return this.$ = $$[$0];
break;
case 8:
this.$ = $$[$0 - 1 + 1 - 1];
case 8:this.$ = $$[$0];
break;
case 9:
this.$ = $$[$0 - 1 + 1 - 1];
case 9:this.$ = $$[$0];
break;
case 10:
this.$ = $$[$0 - 1 + 1 - 1];
case 10:this.$ = $$[$0];
break;
case 11:
this.$ = $$[$0 - 1 + 1 - 1];
case 11:this.$ = $$[$0];
break;
case 12:
this.$ = $$[$0 - 1 + 1 - 1];
case 12:this.$ = $$[$0];
break;
case 13:
this.$ = $$[$0 - 1 + 1 - 1];
case 13:this.$ = $$[$0];
break;
case 14:
this.$ = {};
case 14:this.$ = {};
break;
case 15:
this.$ = $$[$0 - 3 + 2 - 1];
case 15:this.$ = $$[$0-1];
break;
case 16:
this.$ = [$$[$0 - 3 + 1 - 1], $$[$0 - 3 + 3 - 1]];
case 16:this.$ = [$$[$0-2], $$[$0]];
break;
case 17:
this.$ = {};
this.$[$$[$0 - 1 + 1 - 1][0]] = $$[$0 - 1 + 1 - 1][1];
case 17:this.$ = {}; this.$[$$[$0][0]] = $$[$0][1];
break;
case 18:
this.$ = $$[$0 - 3 + 1 - 1];
$$[$0 - 3 + 1 - 1][$$[$0 - 3 + 3 - 1][0]] = $$[$0 - 3 + 3 - 1][1];
case 18:this.$ = $$[$0-2]; $$[$0-2][$$[$0][0]] = $$[$0][1];
break;
case 19:
this.$ = [];
case 19:this.$ = [];
break;
case 20:
this.$ = $$[$0 - 3 + 2 - 1];
case 20:this.$ = $$[$0-1];
break;
case 21:
this.$ = [$$[$0 - 1 + 1 - 1]];
case 21:this.$ = [$$[$0]];
break;
case 22:
this.$ = $$[$0 - 3 + 1 - 1];
$$[$0 - 3 + 1 - 1].push($$[$0 - 3 + 3 - 1]);
case 22:this.$ = $$[$0-2]; $$[$0-2].push($$[$0]);
break;
default:;
}
},
table: [{"11":1,"12":2,"13":3,"15":[1,4],"21":[1,5]},{"1":[3]},{"1":[2,6]},{"1":[2,7]},{"16":[1,6],"17":7,"18":8,"2":9,"3":[1,10]},{"22":[1,11],"23":12,"14":13,"6":14,"8":15,"2":16,"4":17,"12":18,"13":19,"7":[1,20],"9":[1,21],"10":[1,22],"3":[1,10],"5":[1,23],"15":[1,4],"21":[1,5]},{"1":[2,14],"22":[2,14],"20":[2,14],"16":[2,14]},{"16":[1,24],"20":[1,25]},{"16":[2,17],"20":[2,17]},{"19":[1,26]},{"19":[2,1],"22":[2,1],"20":[2,1],"16":[2,1]},{"1":[2,19],"22":[2,19],"20":[2,19],"16":[2,19]},{"22":[1,27],"20":[1,28]},{"22":[2,21],"20":[2,21]},{"22":[2,8],"20":[2,8],"16":[2,8]},{"22":[2,9],"20":[2,9],"16":[2,9]},{"22":[2,10],"20":[2,10],"16":[2,10]},{"22":[2,11],"20":[2,11],"16":[2,11]},{"22":[2,12],"20":[2,12],"16":[2,12]},{"22":[2,13],"20":[2,13],"16":[2,13]},{"22":[2,3],"20":[2,3],"16":[2,3]},{"22":[2,4],"20":[2,4],"16":[2,4]},{"22":[2,5],"20":[2,5],"16":[2,5]},{"22":[2,2],"20":[2,2],"16":[2,2]},{"1":[2,15],"22":[2,15],"20":[2,15],"16":[2,15]},{"18":29,"2":9,"3":[1,10]},{"14":30,"6":14,"8":15,"2":16,"4":17,"12":18,"13":19,"7":[1,20],"9":[1,21],"10":[1,22],"3":[1,10],"5":[1,23],"15":[1,4],"21":[1,5]},{"1":[2,20],"22":[2,20],"20":[2,20],"16":[2,20]},{"14":31,"6":14,"8":15,"2":16,"4":17,"12":18,"13":19,"7":[1,20],"9":[1,21],"10":[1,22],"3":[1,10],"5":[1,23],"15":[1,4],"21":[1,5]},{"16":[2,18],"20":[2,18]},{"16":[2,16],"20":[2,16]},{"22":[2,22],"20":[2,22]}],
table: [{12:1,13:2,14:3,16:[1,4],22:[1,5]},{1:[3]},{1:[2,6]},{1:[2,7]},{3:9,4:[1,10],17:[1,6],18:7,19:8},{3:16,4:[1,10],5:17,6:[1,23],7:14,8:[1,20],9:15,10:[1,21],11:[1,22],13:18,14:19,15:13,16:[1,4],22:[1,5],23:[1,11],24:12},{1:[2,14],17:[2,14],21:[2,14],23:[2,14]},{17:[1,24],21:[1,25]},{17:[2,17],21:[2,17]},{20:[1,26]},{17:[2,1],20:[2,1],21:[2,1],23:[2,1]},{1:[2,19],17:[2,19],21:[2,19],23:[2,19]},{21:[1,28],23:[1,27]},{21:[2,21],23:[2,21]},{17:[2,8],21:[2,8],23:[2,8]},{17:[2,9],21:[2,9],23:[2,9]},{17:[2,10],21:[2,10],23:[2,10]},{17:[2,11],21:[2,11],23:[2,11]},{17:[2,12],21:[2,12],23:[2,12]},{17:[2,13],21:[2,13],23:[2,13]},{17:[2,3],21:[2,3],23:[2,3]},{17:[2,4],21:[2,4],23:[2,4]},{17:[2,5],21:[2,5],23:[2,5]},{17:[2,2],21:[2,2],23:[2,2]},{1:[2,15],17:[2,15],21:[2,15],23:[2,15]},{3:9,4:[1,10],19:29},{3:16,4:[1,10],5:17,6:[1,23],7:14,8:[1,20],9:15,10:[1,21],11:[1,22],13:18,14:19,15:30,16:[1,4],22:[1,5]},{1:[2,20],17:[2,20],21:[2,20],23:[2,20]},{3:16,4:[1,10],5:17,6:[1,23],7:14,8:[1,20],9:15,10:[1,21],11:[1,22],13:18,14:19,15:31,16:[1,4],22:[1,5]},{17:[2,18],21:[2,18]},{17:[2,16],21:[2,16]},{21:[2,22],23:[2,22]}],
defaultActions: {2:[2,6],3:[2,7]},
parseError: function parseError(str, hash) {
throw new Error(str);
},
parse: function parse(input) {
var self = this, stack = [0], vstack = [null], table = this.table, yytext = "", yylineno = 0, yyleng = 0, shifts = 0, reductions = 0;
var self = this,
stack = [0],
vstack = [null], // semantic value stack
lstack = [], // location stack
table = this.table,
yytext = '',
yylineno = 0,
yyleng = 0,
recovering = 0,
TERROR = 2,
EOF = 1;
//this.reductionCount = this.shiftCount = 0;
this.lexer.setInput(input);
this.lexer.yy = this.yy;
var parseError = this.yy.parseError = this.yy.parseError || this.parseError;
this.yy.lexer = this.lexer;
if (typeof this.lexer.yylloc == 'undefined')
this.lexer.yylloc = {};
var yyloc = this.lexer.yylloc;
lstack.push(yyloc);
if (typeof this.yy.parseError === 'function')
this.parseError = this.yy.parseError;
function popStack (n) {
stack.length = stack.length - 2*n;
vstack.length = vstack.length - n;
lstack.length = lstack.length - n;
}
function lex() {
var token;
token = self.lexer.lex() || 1;
if (typeof token !== "number") {
token = self.symbols_[token];
token = self.lexer.lex() || 1; // $end = 1
// if token isn't its numeric value, convert
if (typeof token !== 'number') {
token = self.symbols_[token] || token;
}
return token;
};
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected;
while (true) {
// retreive state number from top of stack
state = stack[stack.length-1];
// use default actions if available
if (this.defaultActions[state]) {
action = this.defaultActions[state];
} else {
if (symbol == null)
symbol = lex();
// read action for current state and first input
action = table[state] && table[state][symbol];
}
var symbol, state, action, a, r, yyval = {}, p, len, ip = 0, newState, expected;
symbol = lex();
while (true) {
state = stack[stack.length - 1];
action = table[state] && table[state][symbol];
if (typeof action === "undefined" || !action.length || !action[0]) {
// handle parse error
if (typeof action === 'undefined' || !action.length || !action[0]) {
if (!recovering) {
// Report error
expected = [];
for (p in table[state]) {
if (this.terminals_[p] && p != 1) {
for (p in table[state]) if (this.terminals_[p] && p > 2) {
expected.push("'"+this.terminals_[p]+"'");
}
}
var errStr = '';
if (this.lexer.showPosition) {
parseError("Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", "), {text: this.lexer.match, token: this.terminals_[symbol], line: this.lexer.yylineno, expected: expected});
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+'\nExpecting '+expected.join(', ');
} else {
parseError("Parse error on line " + (yylineno + 1) + ": Unexpected '" + this.terminals_[symbol] + "'", {text: this.lexer.match, token: this.terminals_[symbol], line: this.lexer.yylineno, expected: expected});
errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
(symbol == 1 /*EOF*/ ? "end of input" :
("'"+(this.terminals_[symbol] || symbol)+"'"));
}
this.parseError(errStr,
{text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
}
if (action[0] instanceof Array && action.length > 1) {
throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
// just recovered from another error
if (recovering == 3) {
if (symbol == EOF) {
throw new Error(errStr || 'Parsing halted.');
}
a = action;
switch (a[0]) {
case 1:
shifts++;
stack.push(symbol);
++ip;
// discard current lookahead and grab another
yyleng = this.lexer.yyleng;
yytext = this.lexer.yytext;
yylineno = this.lexer.yylineno;
yyloc = this.lexer.yylloc;
symbol = lex();
vstack.push(null);
stack.push(a[1]);
}
// try to recover from error
while (1) {
// check for error recovery rule in this state
if ((TERROR.toString()) in table[state]) {
break;
case 2:
reductions++;
len = this.productions_[a[1]][1];
yyval.$ = vstack[vstack.length - len];
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, a[1], vstack);
if (typeof r !== "undefined") {
}
if (state == 0) {
throw new Error(errStr || 'Parsing halted.');
}
popStack(1);
state = stack[stack.length-1];
}
preErrorSymbol = symbol; // save the lookahead token
symbol = TERROR; // insert generic error symbol as new lookahead
state = stack[stack.length-1];
action = table[state] && table[state][TERROR];
recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
}
// this shouldn't happen, unless resolve defaults are off
if (action[0] instanceof Array && action.length > 1) {
throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
}
switch (action[0]) {
case 1: // shift
//this.shiftCount++;
stack.push(symbol);
vstack.push(this.lexer.yytext);
lstack.push(this.lexer.yylloc);
stack.push(action[1]); // push state
symbol = null;
if (!preErrorSymbol) { // normal execution/no error
yyleng = this.lexer.yyleng;
yytext = this.lexer.yytext;
yylineno = this.lexer.yylineno;
yyloc = this.lexer.yylloc;
if (recovering > 0)
recovering--;
} else { // error just occurred, resume old lookahead f/ before error
symbol = preErrorSymbol;
preErrorSymbol = null;
}
break;
case 2: // reduce
//this.reductionCount++;
len = this.productions_[action[1]][1];
// perform semantic action
yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
// default location, uses first token for firsts, last for lasts
yyval._$ = {
first_line: lstack[lstack.length-(len||1)].first_line,
last_line: lstack[lstack.length-1].last_line,
first_column: lstack[lstack.length-(len||1)].first_column,
last_column: lstack[lstack.length-1].last_column
};
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
if (typeof r !== 'undefined') {
return r;
}
// pop off stack
if (len) {
stack = stack.slice(0,-1*len*2);
vstack = vstack.slice(0, -1*len);
lstack = lstack.slice(0, -1*len);
}
stack.push(this.productions_[a[1]][0]);
stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce)
vstack.push(yyval.$);
lstack.push(yyval._$);
// goto new state = table[STATE][NONTERMINAL]
newState = table[stack[stack.length-2]][stack[stack.length-1]];
stack.push(newState);
break;
case 3:
this.reductionCount = reductions;
this.shiftCount = shifts;
case 3: // accept
return true;
default:;
}
}
return true;
}};/* Jison generated lexer */
var lexer = (function(){var lexer = ({EOF:"",
var lexer = (function(){var lexer = ({EOF:1,
parseError:function parseError(str, hash) {
if (this.yy.parseError) {
this.yy.parseError(str, hash);
@@ -172,7 +255,9 @@ setInput:function (input) {
this._input = input;
this._more = this._less = this.done = false;
this.yylineno = this.yyleng = 0;
this.yytext = this.matched = this.match = "";
this.yytext = this.matched = this.match = '';
this.conditionStack = ['INITIAL'];
this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
return this;
},
input:function () {
@@ -182,9 +267,7 @@ input:function () {
this.match+=ch;
this.matched+=ch;
var lines = ch.match(/\n/);
if (lines) {
this.yylineno++;
}
if (lines) this.yylineno++;
this._input = this._input.slice(1);
return ch;
},
@@ -198,39 +281,44 @@ more:function () {
},
pastInput:function () {
var past = this.matched.substr(0, this.matched.length - this.match.length);
return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, "");
return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
},
upcomingInput:function () {
var next = this.match;
if (next.length < 20) {
next += this._input.substr(0, 20-next.length);
}
return (next.substr(0, 20) + (next.length > 20 ? "..." : "")).replace(/\n/g, "");
return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
},
showPosition:function () {
var pre = this.pastInput();
var c = (new Array(pre.length + 1)).join("-");
var c = new Array(pre.length + 1).join("-");
return pre + this.upcomingInput() + "\n" + c+"^";
},
next:function () {
if (this.done) {
return this.EOF;
}
if (!this._input) {
this.done = true;
}
var token, match, lines;
if (!this._input) this.done = true;
var token,
match,
col,
lines;
if (!this._more) {
this.yytext = "";
this.match = "";
this.yytext = '';
this.match = '';
}
for (var i = 0; i < this.rules.length; i++) {
match = this._input.match(this.rules[i]);
var rules = this._currentRules();
for (var i=0;i < rules.length; i++) {
match = this._input.match(this.rules[rules[i]]);
if (match) {
lines = match[0].match(/\n/g);
if (lines) {
this.yylineno += lines.length;
}
lines = match[0].match(/\n.*/g);
if (lines) this.yylineno += lines.length;
this.yylloc = {first_line: this.yylloc.last_line,
last_line: this.yylineno+1,
first_column: this.yylloc.last_column,
last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
this.yytext += match[0];
this.match += match[0];
this.matches = match;
@@ -238,88 +326,87 @@ next:function () {
this._more = false;
this._input = this._input.slice(match[0].length);
this.matched += match[0];
token = this.performAction.call(this, this.yy, this, i);
if (token) {
return token;
} else {
return;
token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]);
if (token) return token;
else return;
}
}
}
if (this._input == this.EOF) {
if (this._input === "") {
return this.EOF;
} else {
this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {text: "", token: null, line: this.yylineno});
this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
{text: "", token: null, line: this.yylineno});
}
},
lex:function () {
lex:function lex() {
var r = this.next();
if (typeof r !== "undefined") {
if (typeof r !== 'undefined') {
return r;
} else {
return this.lex();
}
},
begin:function begin(condition) {
this.conditionStack.push(condition);
},
popState:function popState() {
return this.conditionStack.pop();
},
_currentRules:function _currentRules() {
return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
}});
lexer.performAction = function anonymous(yy, yy_) {
switch (arguments[2]) {
case 0:
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
var YYSTATE=YY_START
switch($avoiding_name_collisions) {
case 0:/* skip whitespace */
break;
case 1:
return 5;
case 1:return 6;
break;
case 2:
yy_.yytext = yy_.yytext.substr(1, yy_.yyleng - 2);
return 3;
case 2:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 4;
break;
case 3:
return 15;
case 3: return 16
break;
case 4:
return 16;
case 4: return 17
break;
case 5:
return 21;
case 5:return 22
break;
case 6:
return 22;
case 6:return 23
break;
case 7:
return 20;
case 7:return 21
break;
case 8:
return 19;
case 8:return 20
break;
case 9:
return 9;
case 9:return 10
break;
case 10:
return 10;
case 10:return 11
break;
case 11:
return 7;
case 11:return 8
break;
case 12:
return "INVALID";
case 12:return 'INVALID'
break;
default:;
}
};
lexer.rules = [/^\s+/,/^-?([0-9]|[1-9][0-9]+)(\.[0-9]+)?([eE][-+]?[0-9]+)?\b\b/,/^"(\\["bfnrt\/\\]|\\u[a-fA-F0-9]{4}|[^\0-\x08\x0a-\x1f"\\])*"/,/^\{/,/^\}/,/^\[/,/^\]/,/^,/,/^:/,/^true\b/,/^false\b/,/^null\b/,/^./];return lexer;})()
lexer.rules = [/^\s+/,/^-?([0-9]|[1-9][0-9]+)(\.[0-9]+)?([eE][-+]?[0-9]+)?\b\b/,/^"(\\["bfnrt/\\]|\\u[a-fA-F0-9]{4}|[^\0-\x08\x0a-\x1f"\\])*"/,/^\{/,/^\}/,/^\[/,/^\]/,/^,/,/^:/,/^true\b/,/^false\b/,/^null\b/,/^./];
lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12],"inclusive":true}};return lexer;})()
parser.lexer = lexer;
return parser;
})();
if (typeof require !== 'undefined') {
exports.parser = grammar;
exports.parse = function () { return grammar.parse.apply(grammar, arguments); }
if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
exports.parser = jsonlint;
exports.parse = function () { return jsonlint.parse.apply(jsonlint, arguments); }
exports.main = function commonjsMain(args) {
if (!args[1])
throw new Error('Usage: '+args[0]+' FILE');
if (typeof process !== 'undefined') {
var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
} else {
var cwd = require("file").path(require("file").cwd());
if (!args[1]) {
throw new Error("Usage: " + args[0] + " FILE");
}
var source = cwd.join(args[1]).read({charset: "utf-8"});
this.parse(source);
}
if (require.main === module) {
exports.main(require("system").args);
return exports.parser.parse(source);
}
if (typeof module !== 'undefined' && require.main === module) {
exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
}
}

View File

@@ -1,14 +1,30 @@
{
"author": "Zach Carter <zach@carter.name> (http://zaa.ch)",
"name": "jsonlint",
"author": "Zach Carter",
"email": "zach@carter.name",
"keywords": [
"jsonlint",
"json",
"parser",
"lint"
],
"githubName": "jsonlint",
"type": "zip",
"location": "http://github.com/zaach/jsonlint/zipball/master"
"description": "Validate JSON",
"keywords": ["json", "validation", "lint", "jsonlint"],
"version": "1.0.0",
"preferGlobal": true,
"repository": {
"type": "git",
"url": "git://github.com/zaach/jsonlint.git"
},
"bugs": {
"web": "http://github.com/zaach/jsonlint/issues"
},
"main": "lib/jsonlint.js",
"bin": "lib/cli.js",
"engines": {
"node": "0.4 || 0.5"
},
"dependencies": {},
"devDependencies": {
"test": "*",
"jison": "*",
"uglify-js": "*"
},
"scripts": {
"test": "node test/all-tests.js"
},
"homepage": "http://zaach.github.com/jsonlint/"
}

9
scripts/bundle.js Normal file
View File

@@ -0,0 +1,9 @@
var fs = require('fs');
var sys = require('sys');
var source = "var jsonlint = (function(){var require=true,module=false;var exports={};" +
fs.readFileSync(__dirname+'/../lib/jsonlint.js', 'utf8') +
"return exports;})()";
sys.puts(source);

6
tests/all-tests.js → test/all-tests.js Executable file → Normal file
View File

@@ -1,6 +1,4 @@
#!/usr/bin/env narwhal
var fs = require("file"),
var fs = require("fs"),
assert = require("assert"),
parser = require("../lib/jsonlint").parser;
@@ -20,4 +18,4 @@ exports["test string with line break"] = function () {
};
if (require.main === module)
require("os").exit(require("test").run(exports));
require("test").run(exports);

File diff suppressed because one or more lines are too long