diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3c3629e..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/Makefile b/Makefile deleted file mode 100644 index 6660a8e..0000000 --- a/Makefile +++ /dev/null @@ -1,17 +0,0 @@ - -all: build test site - -build: - ./node_modules/jison/lib/cli.js src/jsonlint.y src/jsonlint.l - mv jsonlint.js lib/jsonlint.js - node scripts/bundle.js | ./node_modules/uglify-js/bin/uglifyjs > web/jsonlint.js - -site: - cp web/jsonlint.js ../jsonlint-pages/jsonlint.js - -deploy: site - cd ../jsonlint-pages && git commit -a -m 'deploy site updates' && git push origin gh-pages - -test: lib/jsonlint.js test/all-tests.js - node test/all-tests.js - diff --git a/README.md b/README.md deleted file mode 100644 index 5a51966..0000000 --- a/README.md +++ /dev/null @@ -1,65 +0,0 @@ -JSON Lint -========= - -A pure [JavaScript version](http://zaach.github.com/jsonlint/) of the service provided at [jsonlint.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. - -### Options - - $ jsonlint -h - - Usage: jsonlint [file] [options] - - file file to parse; otherwise uses stdin - - Options: - -v, --version print version and exit - -s, --sort-keys sort object keys - -i, --in-place overwrite the file - -t CHAR, --indent CHAR character(s) to use for indentation [ ] - -c, --compact compact error display - -V, --validate a JSON schema to use for validation - -e, --environment which specification of JSON Schema the validation file uses [json-schema-draft-03] - -q, --quiet do not print the parsed json to STDOUT [false] - -p, --pretty-print force pretty printing even if invalid - - -## 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`. - -## Vim Plugins - -* [Syntastic](http://www.vim.org/scripts/script.php?script_id=2736) -* [sourcebeautify](http://www.vim.org/scripts/script.php?script_id=4079) -* [ALE](https://github.com/w0rp/ale) - -## MIT License - -Copyright (C) 2012 Zachary Carter - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/bower.json b/bower.json deleted file mode 100644 index b25b3cd..0000000 --- a/bower.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "jsonlint", - "version": "1.6.0", - "main": "lib/jsonlint.js", - "ignore": [ - "**/.*", - "node_modules", - "scripts", - "src", - "test", - "web", - "package.json", - "Makefile", - "README.md" - ] -} diff --git a/web/jsonlint.html b/index.html similarity index 96% rename from web/jsonlint.html rename to index.html index b088066..4f6f6e8 100644 --- a/web/jsonlint.html +++ b/index.html @@ -45,9 +45,7 @@

JSON Lint

A pure JavaScript version of the service provided at jsonlint.com.

- +

diff --git a/web/json2.js b/json2.js similarity index 100% rename from web/json2.js rename to json2.js diff --git a/web/jsonlint.js b/jsonlint.js similarity index 100% rename from web/jsonlint.js rename to jsonlint.js diff --git a/lib/cli.js b/lib/cli.js deleted file mode 100755 index 2e6fafc..0000000 --- a/lib/cli.js +++ /dev/null @@ -1,179 +0,0 @@ -#!/usr/bin/env node - -var fs = require("fs"); -var path = require("path"); -var parser = require("./jsonlint").parser; -var JSV = require("JSV").JSV; -var formatter = require("./formatter.js").formatter; - -var options = require("@gerhobbelt/nomnom") - .script("jsonlint") - .options({ - file: { - position: 0, - help: "file to parse; otherwise uses stdin" - }, - version: { - flag : true, - string: '-v, --version', - help: 'print version and exit', - callback: function() { - return require("../package").version; - } - }, - sort : { - flag : true, - string: '-s, --sort-keys', - help: 'sort object keys' - }, - inplace : { - flag : true, - string: '-i, --in-place', - help: 'overwrite the file' - }, - indent : { - string: '-t CHAR, --indent CHAR', - "default": " ", - help: 'character(s) to use for indentation' - }, - compact : { - flag : true, - string: '-c, --compact', - help : 'compact error display' - }, - validate : { - string: '-V, --validate', - help : 'a JSON schema to use for validation' - }, - env : { - string: '-e, --environment', - "default": "json-schema-draft-03", - help: 'which specification of JSON Schema the validation file uses' - }, - quiet: { - flag: true, - key: "value", - string: '-q, --quiet', - "default": false, - help: 'do not print the parsed json to STDOUT' - }, - forcePrettyPrint: { - flag: true, - string: '-p, --pretty-print', - help: 'force pretty printing even if invalid' - } - }).parse(); - -if (options.compact) { - var fileName = options.file? options.file + ': ' : ''; - parser.parseError = parser.lexer.parseError = function(str, hash) { - console.error(fileName + 'line '+ hash.loc.first_line +', col '+ hash.loc.last_column +', found: \''+ hash.token +'\' - expected: '+ hash.expected.join(', ') +'.'); - throw new Error(str); - }; -} - -function parse (source) { - var parsed, - formatted; - - try { - parsed = options.sort ? - sortObject(parser.parse(source)) : - parser.parse(source); - - if (options.validate) { - var env = JSV.createEnvironment(options.env); - var schema = JSON.parse(fs.readFileSync(path.normalize(options.validate), "utf8")); - var report = env.validate(parsed, schema); - if (report.errors.length) { - throw report.errors.reduce(schemaError, 'Validation Errors:'); - } - } - - return JSON.stringify(parsed, null, options.indent); - } catch (e) { - if (options.forcePrettyPrint) { - /* From https://github.com/umbrae/jsonlintdotcom: - * If we failed to validate, run our manual formatter and then re-validate so that we - * can get a better line number. On a successful validate, we don't want to run our - * manual formatter because the automatic one is faster and probably more reliable. - */ - - try { - formatted = formatter.formatJson(source, options.indent); - // Re-parse so exception output gets better line numbers - parsed = parser.parse(formatted); - } catch (e) { - if (! options.compact) { - console.error(e); - } - // force the pretty print before exiting - console.log(formatted); - } - } else { - if (! options.compact) { - console.error(e); - } - } - process.exit(1); - } -} - -function schemaError (str, err) { - return str + - "\n\n"+err.message + - "\nuri: " + err.uri + - "\nschemaUri: " + err.schemaUri + - "\nattribute: " + err.attribute + - "\ndetails: " + JSON.stringify(err.details); -} - -function main (args) { - var source = ''; - if (options.file) { - var json = path.normalize(options.file); - source = parse(fs.readFileSync(json, "utf8")); - if (options.inplace) { - fs.writeSync(fs.openSync(json,'w+'), source, 0, "utf8"); - } else { - if (! options.quiet) { console.log(source)}; - } - } else { - var stdin = process.openStdin(); - stdin.setEncoding('utf8'); - - stdin.on('data', function (chunk) { - source += chunk.toString('utf8'); - }); - stdin.on('end', function () { - if (! options.quiet) {console.log(parse(source))}; - }); - } -} - -// from http://stackoverflow.com/questions/1359761/sorting-a-json-object-in-javascript -function sortObject(o) { - if (Array.isArray(o)) { - return o.map(sortObject); - } else if (Object.prototype.toString.call(o) !== '[object Object]') { - return o; - } - - var sorted = {}, - key, a = []; - - for (key in o) { - if (o.hasOwnProperty(key)) { - a.push(key); - } - } - - a.sort(); - - for (key = 0; key < a.length; key++) { - sorted[a[key]] = sortObject(o[a[key]]); - } - return sorted; -} - -main(process.argv.slice(1)); diff --git a/lib/formatter.js b/lib/formatter.js deleted file mode 100644 index e6e2726..0000000 --- a/lib/formatter.js +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env node - -/** - * Manual formatter taken straight from https://github.com/umbrae/jsonlintdotcom -**/ - -/*jslint white: true, devel: true, onevar: true, browser: true, undef: true, nomen: true, regexp: true, plusplus: false, bitwise: true, newcap: true, maxerr: 50, indent: 4 */ - -/** - * jsl.format - Provide json reformatting in a character-by-character approach, so that even invalid JSON may be reformatted (to the best of its ability). - * -**/ -var formatter = (function () { - - function repeat(s, count) { - return new Array(count + 1).join(s); - } - - function formatJson(json, indentChars) { - var i = 0, - il = 0, - tab = (typeof indentChars !== "undefined") ? indentChars : " ", - newJson = "", - indentLevel = 0, - inString = false, - currentChar = null; - - for (i = 0, il = json.length; i < il; i += 1) { - currentChar = json.charAt(i); - - switch (currentChar) { - case '{': - case '[': - if (!inString) { - newJson += currentChar + "\n" + repeat(tab, indentLevel + 1); - indentLevel += 1; - } else { - newJson += currentChar; - } - break; - case '}': - case ']': - if (!inString) { - indentLevel -= 1; - newJson += "\n" + repeat(tab, indentLevel) + currentChar; - } else { - newJson += currentChar; - } - break; - case ',': - if (!inString) { - newJson += ",\n" + repeat(tab, indentLevel); - } else { - newJson += currentChar; - } - break; - case ':': - if (!inString) { - newJson += ": "; - } else { - newJson += currentChar; - } - break; - case ' ': - case "\n": - case "\t": - if (inString) { - newJson += currentChar; - } - break; - case '"': - if (i > 0 && json.charAt(i - 1) !== '\\') { - inString = !inString; - } - newJson += currentChar; - break; - default: - newJson += currentChar; - break; - } - } - - return newJson; - } - - return { "formatJson": formatJson }; - -}()); - -if (typeof require !== 'undefined' && typeof exports !== 'undefined') { - exports.formatter = formatter; -} \ No newline at end of file diff --git a/lib/jsonlint.js b/lib/jsonlint.js deleted file mode 100644 index 598c18c..0000000 --- a/lib/jsonlint.js +++ /dev/null @@ -1,432 +0,0 @@ -/* Jison generated parser */ -var jsonlint = (function(){ -var parser = {trace: function trace() { }, -yy: {}, -symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONValue":13,"EOF":14,"JSONObject":15,"JSONArray":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1}, -terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"}, -productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]], -performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) { - -var $0 = $$.length - 1; -switch (yystate) { -case 1: // replace escaped characters with actual character - this.$ = yytext.replace(/\\(\\|")/g, "$"+"1") - .replace(/\\n/g,'\n') - .replace(/\\r/g,'\r') - .replace(/\\t/g,'\t') - .replace(/\\v/g,'\v') - .replace(/\\f/g,'\f') - .replace(/\\b/g,'\b'); - -break; -case 2:this.$ = Number(yytext); -break; -case 3:this.$ = null; -break; -case 4:this.$ = true; -break; -case 5:this.$ = false; -break; -case 6:return this.$ = $$[$0-1]; -break; -case 13:this.$ = {}; -break; -case 14:this.$ = $$[$0-1]; -break; -case 15:this.$ = [$$[$0-2], $$[$0]]; -break; -case 16:this.$ = {}; this.$[$$[$0][0]] = $$[$0][1]; -break; -case 17:this.$ = $$[$0-2]; $$[$0-2][$$[$0][0]] = $$[$0][1]; -break; -case 18:this.$ = []; -break; -case 19:this.$ = $$[$0-1]; -break; -case 20:this.$ = [$$[$0]]; -break; -case 21:this.$ = $$[$0-2]; $$[$0-2].push($$[$0]); -break; -} -}, -table: [{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],12:1,13:2,15:7,16:8,17:[1,14],23:[1,15]},{1:[3]},{14:[1,16]},{14:[2,7],18:[2,7],22:[2,7],24:[2,7]},{14:[2,8],18:[2,8],22:[2,8],24:[2,8]},{14:[2,9],18:[2,9],22:[2,9],24:[2,9]},{14:[2,10],18:[2,10],22:[2,10],24:[2,10]},{14:[2,11],18:[2,11],22:[2,11],24:[2,11]},{14:[2,12],18:[2,12],22:[2,12],24:[2,12]},{14:[2,3],18:[2,3],22:[2,3],24:[2,3]},{14:[2,4],18:[2,4],22:[2,4],24:[2,4]},{14:[2,5],18:[2,5],22:[2,5],24:[2,5]},{14:[2,1],18:[2,1],21:[2,1],22:[2,1],24:[2,1]},{14:[2,2],18:[2,2],22:[2,2],24:[2,2]},{3:20,4:[1,12],18:[1,17],19:18,20:19},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:23,15:7,16:8,17:[1,14],23:[1,15],24:[1,21],25:22},{1:[2,6]},{14:[2,13],18:[2,13],22:[2,13],24:[2,13]},{18:[1,24],22:[1,25]},{18:[2,16],22:[2,16]},{21:[1,26]},{14:[2,18],18:[2,18],22:[2,18],24:[2,18]},{22:[1,28],24:[1,27]},{22:[2,20],24:[2,20]},{14:[2,14],18:[2,14],22:[2,14],24:[2,14]},{3:20,4:[1,12],20:29},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:30,15:7,16:8,17:[1,14],23:[1,15]},{14:[2,19],18:[2,19],22:[2,19],24:[2,19]},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:31,15:7,16:8,17:[1,14],23:[1,15]},{18:[2,17],22:[2,17]},{18:[2,15],22:[2,15]},{22:[2,21],24:[2,21]}], -defaultActions: {16:[2,6]}, -parseError: function parseError(str, hash) { - throw new Error(str); -}, -parse: function parse(input) { - 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; - 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; // $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]; - } - - // handle parse error - _handle_error: - if (typeof action === 'undefined' || !action.length || !action[0]) { - - if (!recovering) { - // Report error - expected = []; - for (p in table[state]) if (this.terminals_[p] && p > 2) { - expected.push("'"+this.terminals_[p]+"'"); - } - var errStr = ''; - if (this.lexer.showPosition) { - errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'"; - } else { - 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}); - } - - // just recovered from another error - if (recovering == 3) { - if (symbol == EOF) { - throw new Error(errStr || 'Parsing halted.'); - } - - // discard current lookahead and grab another - yyleng = this.lexer.yyleng; - yytext = this.lexer.yytext; - yylineno = this.lexer.yylineno; - yyloc = this.lexer.yylloc; - symbol = lex(); - } - - // try to recover from error - while (1) { - // check for error recovery rule in this state - if ((TERROR.toString()) in table[state]) { - break; - } - 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_[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: // accept - return true; - } - - } - - return true; -}}; -/* Jison generated lexer */ -var lexer = (function(){ -var lexer = ({EOF:1, -parseError:function parseError(str, hash) { - if (this.yy.parseError) { - this.yy.parseError(str, hash); - } else { - throw new Error(str); - } - }, -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.conditionStack = ['INITIAL']; - this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0}; - return this; - }, -input:function () { - var ch = this._input[0]; - this.yytext+=ch; - this.yyleng++; - this.match+=ch; - this.matched+=ch; - var lines = ch.match(/\n/); - if (lines) this.yylineno++; - this._input = this._input.slice(1); - return ch; - }, -unput:function (ch) { - this._input = ch + this._input; - return this; - }, -more:function () { - this._more = true; - return this; - }, -less:function (n) { - this._input = this.match.slice(n) + this._input; - }, -pastInput:function () { - var past = this.matched.substr(0, this.matched.length - this.match.length); - 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, ""); - }, -showPosition:function () { - var pre = this.pastInput(); - 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, - tempMatch, - index, - col, - lines; - if (!this._more) { - this.yytext = ''; - this.match = ''; - } - var rules = this._currentRules(); - for (var i=0;i < rules.length; i++) { - tempMatch = this._input.match(this.rules[rules[i]]); - if (tempMatch && (!match || tempMatch[0].length > match[0].length)) { - match = tempMatch; - index = i; - if (!this.options.flex) break; - } - } - if (match) { - 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.yyleng = this.yytext.length; - this._more = false; - this._input = this._input.slice(match[0].length); - this.matched += match[0]; - token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]); - if (this.done && this._input) this.done = false; - if (token) return token; - else return; - } - 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}); - } - }, -lex:function lex() { - var r = this.next(); - 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; - }, -topState:function () { - return this.conditionStack[this.conditionStack.length-2]; - }, -pushState:function begin(condition) { - this.begin(condition); - }}); -lexer.options = {}; -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 6 -break; -case 2:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 4 -break; -case 3:return 17 -break; -case 4:return 18 -break; -case 5:return 23 -break; -case 6:return 24 -break; -case 7:return 22 -break; -case 8:return 21 -break; -case 9:return 10 -break; -case 10:return 11 -break; -case 11:return 8 -break; -case 12:return 14 -break; -case 13:return 'INVALID' -break; -} -}; -lexer.rules = [/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\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,13],"inclusive":true}}; - - -; -return lexer;})() -parser.lexer = lexer; -return parser; -})(); -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()); - var source = cwd.join(args[1]).read({charset: "utf-8"}); - } - return exports.parser.parse(source); -} -if (typeof module !== 'undefined' && require.main === module) { - exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args); -} -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 5139c33..0000000 --- a/package-lock.json +++ /dev/null @@ -1,243 +0,0 @@ -{ - "name": "jsonlint", - "version": "1.6.3", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "JSONSelect": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/JSONSelect/-/JSONSelect-0.4.0.tgz", - "integrity": "sha1-oI7cxn6z/L6Z7WMIVTRKDPKCu40=", - "dev": true - }, - "JSV": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/JSV/-/JSV-4.0.2.tgz", - "integrity": "sha1-0Hf2glVx+CEy+d/67Vh7QCn+/1c=" - }, - "amdefine": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", - "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", - "dev": true, - "optional": true - }, - "ansi-font": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/ansi-font/-/ansi-font-0.0.2.tgz", - "integrity": "sha1-iQMBvVhBRi/TnAt3Ca/R9SUUMzE=", - "dev": true - }, - "ansi-styles": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-1.0.0.tgz", - "integrity": "sha1-yxAt8cVvUSPquLZ817mAJ6AnkXg=" - }, - "chalk": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-0.4.0.tgz", - "integrity": "sha1-UZmj3c0MHv4jvAjBsCewYXbgxk8=", - "requires": { - "ansi-styles": "1.0.0", - "has-color": "0.1.7", - "strip-ansi": "0.1.1" - } - }, - "cjson": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/cjson/-/cjson-0.3.0.tgz", - "integrity": "sha1-5kObkHA9MS/24iJAl76pLOPQKhQ=", - "dev": true, - "requires": { - "jsonlint": "1.6.0" - } - }, - "colors": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/colors/-/colors-0.5.1.tgz", - "integrity": "sha1-fQAj6usVTo7p/Oddy5I9DtFmd3Q=", - "dev": true - }, - "commander": { - "version": "2.14.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz", - "integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==", - "dev": true - }, - "ebnf-parser": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/ebnf-parser/-/ebnf-parser-0.1.10.tgz", - "integrity": "sha1-zR9rpHfFY4xAyX7ZtXLbW6tdgzE=", - "dev": true - }, - "escodegen": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.3.3.tgz", - "integrity": "sha1-8CQBb1qI4Eb9EgBQVek5gC5sXyM=", - "dev": true, - "requires": { - "esprima": "1.1.1", - "estraverse": "1.5.1", - "esutils": "1.0.0", - "source-map": "0.1.43" - } - }, - "esprima": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-1.1.1.tgz", - "integrity": "sha1-W28VR/TRAuZw4UDFCb5ncdautUk=", - "dev": true - }, - "estraverse": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-1.5.1.tgz", - "integrity": "sha1-hno+jlip+EYYr7bC3bzZFrfLr3E=", - "dev": true - }, - "esutils": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-1.0.0.tgz", - "integrity": "sha1-gVHTWOIMisx/t0XnRywAJf5JZXA=", - "dev": true - }, - "has-color": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/has-color/-/has-color-0.1.7.tgz", - "integrity": "sha1-ZxRKUmDDT8PMpnfQQdr1L+e3iy8=" - }, - "jison": { - "version": "0.4.18", - "resolved": "https://registry.npmjs.org/jison/-/jison-0.4.18.tgz", - "integrity": "sha512-FKkCiJvozgC7VTHhMJ00a0/IApSxhlGsFIshLW6trWJ8ONX2TQJBBz6DlcO1Gffy4w9LT+uL+PA+CVnUSJMF7w==", - "dev": true, - "requires": { - "JSONSelect": "0.4.0", - "cjson": "0.3.0", - "ebnf-parser": "0.1.10", - "escodegen": "1.3.3", - "esprima": "1.1.1", - "jison-lex": "0.3.4", - "lex-parser": "0.1.4", - "nomnom": "1.5.2" - }, - "dependencies": { - "nomnom": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/nomnom/-/nomnom-1.5.2.tgz", - "integrity": "sha1-9DRUSKhTz71cDSYyDyR3qwUm/i8=", - "dev": true, - "requires": { - "colors": "0.5.1", - "underscore": "1.1.7" - } - }, - "underscore": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.1.7.tgz", - "integrity": "sha1-QLq4S60Z0jAJbo1u9ii/8FXYPbA=", - "dev": true - } - } - }, - "jison-lex": { - "version": "0.3.4", - "resolved": "https://registry.npmjs.org/jison-lex/-/jison-lex-0.3.4.tgz", - "integrity": "sha1-gcoo2E+ESZ36jFlNzePYo/Jux6U=", - "dev": true, - "requires": { - "lex-parser": "0.1.4", - "nomnom": "1.5.2" - }, - "dependencies": { - "nomnom": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/nomnom/-/nomnom-1.5.2.tgz", - "integrity": "sha1-9DRUSKhTz71cDSYyDyR3qwUm/i8=", - "dev": true, - "requires": { - "colors": "0.5.1", - "underscore": "1.1.7" - } - }, - "underscore": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.1.7.tgz", - "integrity": "sha1-QLq4S60Z0jAJbo1u9ii/8FXYPbA=", - "dev": true - } - } - }, - "jsonlint": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/jsonlint/-/jsonlint-1.6.0.tgz", - "integrity": "sha1-iKpGvCiaesk7tGyuLVihh6m7SUo=", - "dev": true, - "requires": { - "JSV": "4.0.2", - "nomnom": "1.8.1" - } - }, - "lex-parser": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/lex-parser/-/lex-parser-0.1.4.tgz", - "integrity": "sha1-ZMTwJfF/1Tv7RXY/rrFvAVp0dVA=", - "dev": true - }, - "nomnom": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/nomnom/-/nomnom-1.8.1.tgz", - "integrity": "sha1-IVH3Ikcrp55Qp2/BJbuMjy5Nwqc=", - "requires": { - "chalk": "0.4.0", - "underscore": "1.6.0" - } - }, - "source-map": { - "version": "0.1.43", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz", - "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=", - "dev": true, - "optional": true, - "requires": { - "amdefine": "1.0.1" - } - }, - "strip-ansi": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-0.1.1.tgz", - "integrity": "sha1-OeipjQRNFQZgq+SmgIrPcLt7yZE=" - }, - "test": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/test/-/test-0.6.0.tgz", - "integrity": "sha1-WYasRF7Bd1QyJRLRBLoyyKY+k44=", - "dev": true, - "requires": { - "ansi-font": "0.0.2" - } - }, - "uglify-js": { - "version": "3.3.11", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.11.tgz", - "integrity": "sha512-AKLsYcdV+sS5eAE4NtVXF6f2u/DCQynQm0jTGxF261+Vltu1dYNuHzjqDmk11gInj+H/zJIM2EAwXG3MzPb3VA==", - "dev": true, - "requires": { - "commander": "2.14.1", - "source-map": "0.6.1" - }, - "dependencies": { - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } - } - }, - "underscore": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz", - "integrity": "sha1-izixDKze9jM3uLJOT/htRa6lKag=" - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index 7a064ed..0000000 --- a/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "author": "Zach Carter (http://zaa.ch)", - "name": "jsonlint", - "description": "Validate JSON", - "keywords": [ - "json", - "validation", - "lint", - "jsonlint" - ], - "version": "1.6.3", - "license": "MIT", - "preferGlobal": true, - "repository": { - "type": "git", - "url": "git://github.com/zaach/jsonlint.git" - }, - "bugs": { - "url": "http://github.com/zaach/jsonlint/issues" - }, - "main": "lib/jsonlint.js", - "bin": { - "jsonlint": "lib/cli.js" - }, - "engines": { - "node": ">= 0.6" - }, - "dependencies": { - "@gerhobbelt/nomnom": "^1.8.4-27", - "JSV": "^4.0.x" - }, - "devDependencies": { - "test": "*", - "jison": "*", - "uglify-js": "*" - }, - "scripts": { - "test": "node test/all-tests.js" - }, - "homepage": "http://zaach.github.com/jsonlint/", - "optionalDependencies": {} -} diff --git a/scripts/bundle.js b/scripts/bundle.js deleted file mode 100644 index c8e542d..0000000 --- a/scripts/bundle.js +++ /dev/null @@ -1,8 +0,0 @@ -var fs = require('fs'); - -var source = "var jsonlint = (function(){var require=true,module=false;var exports={};" + - fs.readFileSync(__dirname+'/../lib/jsonlint.js', 'utf8') + - "return exports;})()"; - -console.log(source); - diff --git a/src/jsonlint.l b/src/jsonlint.l deleted file mode 100644 index 35491e1..0000000 --- a/src/jsonlint.l +++ /dev/null @@ -1,24 +0,0 @@ -int "-"?([0-9]|[1-9][0-9]+) -exp [eE][-+]?[0-9]+ -frac "."[0-9]+ - -%% -\s+ /* skip whitespace */ - -{int}{frac}?{exp}?\b return 'NUMBER' -\"(?:'\\'[\\"bfnrt/]|'\\u'[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*\" yytext = yytext.substr(1,yyleng-2); return 'STRING' - -"{" return '{' -"}" return '}' -"[" return '[' -"]" return ']' -"," return ',' -":" return ':' -"true" return 'TRUE' -"false" return 'FALSE' -"null" return 'NULL' -<> return 'EOF' -. return 'INVALID' - -%% - diff --git a/src/jsonlint.y b/src/jsonlint.y deleted file mode 100644 index a4d6d29..0000000 --- a/src/jsonlint.y +++ /dev/null @@ -1,86 +0,0 @@ -%start JSONText - -/* - ECMA-262 5th Edition, 15.12.1 The JSON Grammar. -*/ - - -%% - -JSONString - : STRING - { // replace escaped characters with actual character - $$ = yytext.replace(/\\(\\|")/g, "$"+"1") - .replace(/\\n/g,'\n') - .replace(/\\r/g,'\r') - .replace(/\\t/g,'\t') - .replace(/\\v/g,'\v') - .replace(/\\f/g,'\f') - .replace(/\\b/g,'\b'); - } - ; - -JSONNumber - : NUMBER - {$$ = Number(yytext);} - ; - -JSONNullLiteral - : NULL - {$$ = null;} - ; - -JSONBooleanLiteral - : TRUE - {$$ = true;} - | FALSE - {$$ = false;} - ; - -JSONText - : JSONValue EOF - {return $$ = $1;} - ; - -JSONValue - : JSONNullLiteral - | JSONBooleanLiteral - | JSONString - | JSONNumber - | JSONObject - | JSONArray - ; - -JSONObject - : '{' '}' - {{$$ = {};}} - | '{' JSONMemberList '}' - {$$ = $2;} - ; - -JSONMember - : JSONString ':' JSONValue - {$$ = [$1, $3];} - ; - -JSONMemberList - : JSONMember - {{$$ = {}; $$[$1[0]] = $1[1];}} - | JSONMemberList ',' JSONMember - {$$ = $1; $1[$3[0]] = $3[1];} - ; - -JSONArray - : '[' ']' - {$$ = [];} - | '[' JSONElementList ']' - {$$ = $2;} - ; - -JSONElementList - : JSONValue - {$$ = [$1];} - | JSONElementList ',' JSONValue - {$$ = $1; $1.push($3);} - ; - diff --git a/test/all-tests.js b/test/all-tests.js deleted file mode 100644 index 8a2fede..0000000 --- a/test/all-tests.js +++ /dev/null @@ -1,232 +0,0 @@ -var fs = require("fs"), - assert = require("assert"), - parser = require("../lib/jsonlint").parser; - -exports["test object"] = function () { - var json = '{"foo": "bar"}'; - assert.deepEqual(parser.parse(json), {"foo": "bar"}); -}; - -exports["test escaped backslash"] = function () { - var json = '{"foo": "\\\\"}'; - assert.deepEqual(parser.parse(json), {"foo": "\\"}); -}; - -exports["test escaped chars"] = function () { - var json = '{"foo": "\\\\\\\""}'; - assert.deepEqual(parser.parse(json), {"foo": '\\\"'}); -}; - -exports["test escaped \\n"] = function () { - var json = '{"foo": "\\\\\\n"}'; - assert.deepEqual(parser.parse(json), {"foo": '\\\n'}); -}; - -exports["test string with escaped line break"] = function () { - var json = '{"foo": "bar\\nbar"}'; - assert.deepEqual(parser.parse(json), {"foo": "bar\nbar"}); - assert.equal(JSON.stringify(parser.parse(json)).length, 18); -}; - -exports["test string with line break"] = function () { - var json = '{"foo": "bar\nbar"}'; - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test string literal"] = function () { - var json = '"foo"'; - assert.equal(parser.parse(json), "foo"); -}; - -exports["test number literal"] = function () { - var json = '1234'; - assert.equal(parser.parse(json), 1234); -}; - -exports["test null literal"] = function () { - var json = '1234'; - assert.equal(parser.parse(json), 1234); -}; - -exports["test boolean literal"] = function () { - var json = 'true'; - assert.equal(parser.parse(json), true); -}; - -exports["test unclosed array"] = function () { - var json = fs.readFileSync(__dirname + "/fails/2.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test unquotedkey keys must be quoted"] = function () { - var json = fs.readFileSync(__dirname + "/fails/3.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test extra comma"] = function () { - var json = fs.readFileSync(__dirname + "/fails/4.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test double extra comma"] = function () { - var json = fs.readFileSync(__dirname + "/fails/5.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test missing value"] = function () { - var json = fs.readFileSync(__dirname + "/fails/6.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test comma after the close"] = function () { - var json = fs.readFileSync(__dirname + "/fails/7.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test extra close"] = function () { - var json = fs.readFileSync(__dirname + "/fails/8.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test extra comma after value"] = function () { - var json = fs.readFileSync(__dirname + "/fails/9.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test extra value after close with misplaced quotes"] = function () { - var json = fs.readFileSync(__dirname + "/fails/10.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test illegal expression addition"] = function () { - var json = fs.readFileSync(__dirname + "/fails/11.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test illegal invocation of alert"] = function () { - var json = fs.readFileSync(__dirname + "/fails/12.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test numbers cannot have leading zeroes"] = function () { - var json = fs.readFileSync(__dirname + "/fails/13.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test numbers cannot be hex"] = function () { - var json = fs.readFileSync(__dirname + "/fails/14.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test illegal backslash escape \\0"] = function () { - var json = fs.readFileSync(__dirname + "/fails/15.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test unquoted text"] = function () { - var json = fs.readFileSync(__dirname + "/fails/16.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test illegal backslash escape \\x"] = function () { - var json = fs.readFileSync(__dirname + "/fails/17.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test missing colon"] = function () { - var json = fs.readFileSync(__dirname + "/fails/19.json") - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test double colon"] = function () { - var json = fs.readFileSync(__dirname + "/fails/20.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test comma instead of colon"] = function () { - var json = fs.readFileSync(__dirname + "/fails/21.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test colon instead of comma"] = function () { - var json = fs.readFileSync(__dirname + "/fails/22.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test bad raw value"] = function () { - var json = fs.readFileSync(__dirname + "/fails/23.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test single quotes"] = function () { - var json = fs.readFileSync(__dirname + "/fails/24.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test tab character in string"] = function () { - var json = fs.readFileSync(__dirname + "/fails/25.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test tab character in string 2"] = function () { - var json = fs.readFileSync(__dirname + "/fails/26.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test line break in string"] = function () { - var json = fs.readFileSync(__dirname + "/fails/27.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test line break in string in array"] = function () { - var json = fs.readFileSync(__dirname + "/fails/28.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test 0e"] = function () { - var json = fs.readFileSync(__dirname + "/fails/29.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test 0e+"] = function () { - var json = fs.readFileSync(__dirname + "/fails/30.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test 0e+ 1"] = function () { - var json = fs.readFileSync(__dirname + "/fails/31.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test comma instead of closing brace"] = function () { - var json = fs.readFileSync(__dirname + "/fails/32.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -}; - -exports["test bracket mismatch"] = function () { - var json = fs.readFileSync(__dirname + "/fails/33.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -} - -exports["test extra brace"] = function () { - var json = fs.readFileSync(__dirname + "/fails/34.json").toString(); - assert["throws"](function () {parser.parse(json)}, "should throw error"); -} - -exports["test pass-1"] = function () { - var json = fs.readFileSync(__dirname + "/passes/1.json").toString(); - assert.doesNotThrow(function () {parser.parse(json)}, "should pass"); -} - -exports["test pass-2"] = function () { - var json = fs.readFileSync(__dirname + "/passes/2.json").toString(); - assert.doesNotThrow(function () {parser.parse(json)}, "should pass"); -} - -exports["test pass-3"] = function () { - var json = fs.readFileSync(__dirname + "/passes/3.json").toString(); - assert.doesNotThrow(function () {parser.parse(json)}, "should pass"); -} - -if (require.main === module) - require("test").run(exports); diff --git a/test/fails/10.json b/test/fails/10.json deleted file mode 100644 index 5d8c004..0000000 --- a/test/fails/10.json +++ /dev/null @@ -1 +0,0 @@ -{"Extra value after close": true} "misplaced quoted value" \ No newline at end of file diff --git a/test/fails/11.json b/test/fails/11.json deleted file mode 100644 index 76eb95b..0000000 --- a/test/fails/11.json +++ /dev/null @@ -1 +0,0 @@ -{"Illegal expression": 1 + 2} \ No newline at end of file diff --git a/test/fails/12.json b/test/fails/12.json deleted file mode 100644 index 77580a4..0000000 --- a/test/fails/12.json +++ /dev/null @@ -1 +0,0 @@ -{"Illegal invocation": alert()} \ No newline at end of file diff --git a/test/fails/13.json b/test/fails/13.json deleted file mode 100644 index 379406b..0000000 --- a/test/fails/13.json +++ /dev/null @@ -1 +0,0 @@ -{"Numbers cannot have leading zeroes": 013} \ No newline at end of file diff --git a/test/fails/14.json b/test/fails/14.json deleted file mode 100644 index 0ed366b..0000000 --- a/test/fails/14.json +++ /dev/null @@ -1 +0,0 @@ -{"Numbers cannot be hex": 0x14} \ No newline at end of file diff --git a/test/fails/15.json b/test/fails/15.json deleted file mode 100644 index fc8376b..0000000 --- a/test/fails/15.json +++ /dev/null @@ -1 +0,0 @@ -["Illegal backslash escape: \x15"] \ No newline at end of file diff --git a/test/fails/16.json b/test/fails/16.json deleted file mode 100644 index 3fe21d4..0000000 --- a/test/fails/16.json +++ /dev/null @@ -1 +0,0 @@ -[\naked] \ No newline at end of file diff --git a/test/fails/17.json b/test/fails/17.json deleted file mode 100644 index 62b9214..0000000 --- a/test/fails/17.json +++ /dev/null @@ -1 +0,0 @@ -["Illegal backslash escape: \017"] \ No newline at end of file diff --git a/test/fails/19.json b/test/fails/19.json deleted file mode 100644 index 3b9c46f..0000000 --- a/test/fails/19.json +++ /dev/null @@ -1 +0,0 @@ -{"Missing colon" null} \ No newline at end of file diff --git a/test/fails/2.json b/test/fails/2.json deleted file mode 100644 index 6b7c11e..0000000 --- a/test/fails/2.json +++ /dev/null @@ -1 +0,0 @@ -["Unclosed array" \ No newline at end of file diff --git a/test/fails/20.json b/test/fails/20.json deleted file mode 100644 index 27c1af3..0000000 --- a/test/fails/20.json +++ /dev/null @@ -1 +0,0 @@ -{"Double colon":: null} \ No newline at end of file diff --git a/test/fails/21.json b/test/fails/21.json deleted file mode 100644 index 6247457..0000000 --- a/test/fails/21.json +++ /dev/null @@ -1 +0,0 @@ -{"Comma instead of colon", null} \ No newline at end of file diff --git a/test/fails/22.json b/test/fails/22.json deleted file mode 100644 index a775258..0000000 --- a/test/fails/22.json +++ /dev/null @@ -1 +0,0 @@ -["Colon instead of comma": false] \ No newline at end of file diff --git a/test/fails/23.json b/test/fails/23.json deleted file mode 100644 index 494add1..0000000 --- a/test/fails/23.json +++ /dev/null @@ -1 +0,0 @@ -["Bad value", truth] \ No newline at end of file diff --git a/test/fails/24.json b/test/fails/24.json deleted file mode 100644 index caff239..0000000 --- a/test/fails/24.json +++ /dev/null @@ -1 +0,0 @@ -['single quote'] \ No newline at end of file diff --git a/test/fails/25.json b/test/fails/25.json deleted file mode 100644 index 8b7ad23..0000000 --- a/test/fails/25.json +++ /dev/null @@ -1 +0,0 @@ -[" tab character in string "] \ No newline at end of file diff --git a/test/fails/26.json b/test/fails/26.json deleted file mode 100644 index 845d26a..0000000 --- a/test/fails/26.json +++ /dev/null @@ -1 +0,0 @@ -["tab\ character\ in\ string\ "] \ No newline at end of file diff --git a/test/fails/27.json b/test/fails/27.json deleted file mode 100644 index 6b01a2c..0000000 --- a/test/fails/27.json +++ /dev/null @@ -1,2 +0,0 @@ -["line -break"] \ No newline at end of file diff --git a/test/fails/28.json b/test/fails/28.json deleted file mode 100644 index 621a010..0000000 --- a/test/fails/28.json +++ /dev/null @@ -1,2 +0,0 @@ -["line\ -break"] \ No newline at end of file diff --git a/test/fails/29.json b/test/fails/29.json deleted file mode 100644 index 47ec421..0000000 --- a/test/fails/29.json +++ /dev/null @@ -1 +0,0 @@ -[0e] \ No newline at end of file diff --git a/test/fails/3.json b/test/fails/3.json deleted file mode 100644 index 168c81e..0000000 --- a/test/fails/3.json +++ /dev/null @@ -1 +0,0 @@ -{unquoted_key: "keys must be quoted"} \ No newline at end of file diff --git a/test/fails/30.json b/test/fails/30.json deleted file mode 100644 index 8ab0bc4..0000000 --- a/test/fails/30.json +++ /dev/null @@ -1 +0,0 @@ -[0e+] \ No newline at end of file diff --git a/test/fails/31.json b/test/fails/31.json deleted file mode 100644 index 1cce602..0000000 --- a/test/fails/31.json +++ /dev/null @@ -1 +0,0 @@ -[0e+-1] \ No newline at end of file diff --git a/test/fails/32.json b/test/fails/32.json deleted file mode 100644 index 45cba73..0000000 --- a/test/fails/32.json +++ /dev/null @@ -1 +0,0 @@ -{"Comma instead if closing brace": true, \ No newline at end of file diff --git a/test/fails/33.json b/test/fails/33.json deleted file mode 100644 index ca5eb19..0000000 --- a/test/fails/33.json +++ /dev/null @@ -1 +0,0 @@ -["mismatch"} \ No newline at end of file diff --git a/test/fails/34.json b/test/fails/34.json deleted file mode 100644 index 11ef16a..0000000 --- a/test/fails/34.json +++ /dev/null @@ -1 +0,0 @@ -{"extra brace": 1}} diff --git a/test/fails/4.json b/test/fails/4.json deleted file mode 100644 index 9de168b..0000000 --- a/test/fails/4.json +++ /dev/null @@ -1 +0,0 @@ -["extra comma",] \ No newline at end of file diff --git a/test/fails/5.json b/test/fails/5.json deleted file mode 100644 index ddf3ce3..0000000 --- a/test/fails/5.json +++ /dev/null @@ -1 +0,0 @@ -["double extra comma",,] \ No newline at end of file diff --git a/test/fails/6.json b/test/fails/6.json deleted file mode 100644 index ed91580..0000000 --- a/test/fails/6.json +++ /dev/null @@ -1 +0,0 @@ -[ , "<-- missing value"] \ No newline at end of file diff --git a/test/fails/7.json b/test/fails/7.json deleted file mode 100644 index 8a96af3..0000000 --- a/test/fails/7.json +++ /dev/null @@ -1 +0,0 @@ -["Comma after the close"], \ No newline at end of file diff --git a/test/fails/8.json b/test/fails/8.json deleted file mode 100644 index b28479c..0000000 --- a/test/fails/8.json +++ /dev/null @@ -1 +0,0 @@ -["Extra close"]] \ No newline at end of file diff --git a/test/fails/9.json b/test/fails/9.json deleted file mode 100644 index 5815574..0000000 --- a/test/fails/9.json +++ /dev/null @@ -1 +0,0 @@ -{"Extra comma": true,} \ No newline at end of file diff --git a/test/passes/1.json b/test/passes/1.json deleted file mode 100644 index 70e2685..0000000 --- a/test/passes/1.json +++ /dev/null @@ -1,58 +0,0 @@ -[ - "JSON Test Pattern pass1", - {"object with 1 member":["array with 1 element"]}, - {}, - [], - -42, - true, - false, - null, - { - "integer": 1234567890, - "real": -9876.543210, - "e": 0.123456789e-12, - "E": 1.234567890E+34, - "": 23456789012E66, - "zero": 0, - "one": 1, - "space": " ", - "quote": "\"", - "backslash": "\\", - "controls": "\b\f\n\r\t", - "slash": "/ & \/", - "alpha": "abcdefghijklmnopqrstuvwyz", - "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", - "digit": "0123456789", - "0123456789": "digit", - "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", - "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", - "true": true, - "false": false, - "null": null, - "array":[ ], - "object":{ }, - "address": "50 St. James Street", - "url": "http://www.JSON.org/", - "comment": "// /* */": " ", - " s p a c e d " :[1,2 , 3 - -, - -4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], - "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", - "quotes": "" \u0022 %22 0x22 034 "", - "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" -: "A key can be any string" - }, - 0.5 ,98.6 -, -99.44 -, - -1066, -1e1, -0.1e1, -1e-1, -1e00,2e+00,2e-00 -,"rosebud"] \ No newline at end of file diff --git a/test/passes/2.json b/test/passes/2.json deleted file mode 100644 index d3c63c7..0000000 --- a/test/passes/2.json +++ /dev/null @@ -1 +0,0 @@ -[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] \ No newline at end of file diff --git a/test/passes/3.json b/test/passes/3.json deleted file mode 100644 index 4528d51..0000000 --- a/test/passes/3.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "JSON Test Pattern pass3": { - "The outermost value": "must be an object or array.", - "In this test": "It is an object." - } -}