You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

431 lines
16 KiB

1 year ago
  1. /* Jison generated parser */
  2. var jsonlint = (function(){
  3. var parser = {trace: function trace() { },
  4. yy: {},
  5. 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},
  6. terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},
  7. 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]],
  8. performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
  9. var $0 = $$.length - 1;
  10. switch (yystate) {
  11. case 1: // replace escaped characters with actual character
  12. this.$ = yytext.replace(/\\(\\|")/g, "$"+"1")
  13. .replace(/\\n/g,'\n')
  14. .replace(/\\r/g,'\r')
  15. .replace(/\\t/g,'\t')
  16. .replace(/\\v/g,'\v')
  17. .replace(/\\f/g,'\f')
  18. .replace(/\\b/g,'\b');
  19. break;
  20. case 2:this.$ = Number(yytext);
  21. break;
  22. case 3:this.$ = null;
  23. break;
  24. case 4:this.$ = true;
  25. break;
  26. case 5:this.$ = false;
  27. break;
  28. case 6:return this.$ = $$[$0-1];
  29. break;
  30. case 13:this.$ = {};
  31. break;
  32. case 14:this.$ = $$[$0-1];
  33. break;
  34. case 15:this.$ = [$$[$0-2], $$[$0]];
  35. break;
  36. case 16:this.$ = {}; this.$[$$[$0][0]] = $$[$0][1];
  37. break;
  38. case 17:this.$ = $$[$0-2]; $$[$0-2][$$[$0][0]] = $$[$0][1];
  39. break;
  40. case 18:this.$ = [];
  41. break;
  42. case 19:this.$ = $$[$0-1];
  43. break;
  44. case 20:this.$ = [$$[$0]];
  45. break;
  46. case 21:this.$ = $$[$0-2]; $$[$0-2].push($$[$0]);
  47. break;
  48. }
  49. },
  50. 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]}],
  51. defaultActions: {16:[2,6]},
  52. parseError: function parseError(str, hash) {
  53. throw new Error(str);
  54. },
  55. parse: function parse(input) {
  56. var self = this,
  57. stack = [0],
  58. vstack = [null], // semantic value stack
  59. lstack = [], // location stack
  60. table = this.table,
  61. yytext = '',
  62. yylineno = 0,
  63. yyleng = 0,
  64. recovering = 0,
  65. TERROR = 2,
  66. EOF = 1;
  67. //this.reductionCount = this.shiftCount = 0;
  68. this.lexer.setInput(input);
  69. this.lexer.yy = this.yy;
  70. this.yy.lexer = this.lexer;
  71. if (typeof this.lexer.yylloc == 'undefined')
  72. this.lexer.yylloc = {};
  73. var yyloc = this.lexer.yylloc;
  74. lstack.push(yyloc);
  75. if (typeof this.yy.parseError === 'function')
  76. this.parseError = this.yy.parseError;
  77. function popStack (n) {
  78. stack.length = stack.length - 2*n;
  79. vstack.length = vstack.length - n;
  80. lstack.length = lstack.length - n;
  81. }
  82. function lex() {
  83. var token;
  84. token = self.lexer.lex() || 1; // $end = 1
  85. // if token isn't its numeric value, convert
  86. if (typeof token !== 'number') {
  87. token = self.symbols_[token] || token;
  88. }
  89. return token;
  90. }
  91. var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected;
  92. while (true) {
  93. // retreive state number from top of stack
  94. state = stack[stack.length-1];
  95. // use default actions if available
  96. if (this.defaultActions[state]) {
  97. action = this.defaultActions[state];
  98. } else {
  99. if (symbol == null)
  100. symbol = lex();
  101. // read action for current state and first input
  102. action = table[state] && table[state][symbol];
  103. }
  104. // handle parse error
  105. _handle_error:
  106. if (typeof action === 'undefined' || !action.length || !action[0]) {
  107. if (!recovering) {
  108. // Report error
  109. expected = [];
  110. for (p in table[state]) if (this.terminals_[p] && p > 2) {
  111. expected.push("'"+this.terminals_[p]+"'");
  112. }
  113. var errStr = '';
  114. if (this.lexer.showPosition) {
  115. errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'";
  116. } else {
  117. errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
  118. (symbol == 1 /*EOF*/ ? "end of input" :
  119. ("'"+(this.terminals_[symbol] || symbol)+"'"));
  120. }
  121. this.parseError(errStr,
  122. {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
  123. }
  124. // just recovered from another error
  125. if (recovering == 3) {
  126. if (symbol == EOF) {
  127. throw new Error(errStr || 'Parsing halted.');
  128. }
  129. // discard current lookahead and grab another
  130. yyleng = this.lexer.yyleng;
  131. yytext = this.lexer.yytext;
  132. yylineno = this.lexer.yylineno;
  133. yyloc = this.lexer.yylloc;
  134. symbol = lex();
  135. }
  136. // try to recover from error
  137. while (1) {
  138. // check for error recovery rule in this state
  139. if ((TERROR.toString()) in table[state]) {
  140. break;
  141. }
  142. if (state == 0) {
  143. throw new Error(errStr || 'Parsing halted.');
  144. }
  145. popStack(1);
  146. state = stack[stack.length-1];
  147. }
  148. preErrorSymbol = symbol; // save the lookahead token
  149. symbol = TERROR; // insert generic error symbol as new lookahead
  150. state = stack[stack.length-1];
  151. action = table[state] && table[state][TERROR];
  152. recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
  153. }
  154. // this shouldn't happen, unless resolve defaults are off
  155. if (action[0] instanceof Array && action.length > 1) {
  156. throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
  157. }
  158. switch (action[0]) {
  159. case 1: // shift
  160. //this.shiftCount++;
  161. stack.push(symbol);
  162. vstack.push(this.lexer.yytext);
  163. lstack.push(this.lexer.yylloc);
  164. stack.push(action[1]); // push state
  165. symbol = null;
  166. if (!preErrorSymbol) { // normal execution/no error
  167. yyleng = this.lexer.yyleng;
  168. yytext = this.lexer.yytext;
  169. yylineno = this.lexer.yylineno;
  170. yyloc = this.lexer.yylloc;
  171. if (recovering > 0)
  172. recovering--;
  173. } else { // error just occurred, resume old lookahead f/ before error
  174. symbol = preErrorSymbol;
  175. preErrorSymbol = null;
  176. }
  177. break;
  178. case 2: // reduce
  179. //this.reductionCount++;
  180. len = this.productions_[action[1]][1];
  181. // perform semantic action
  182. yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
  183. // default location, uses first token for firsts, last for lasts
  184. yyval._$ = {
  185. first_line: lstack[lstack.length-(len||1)].first_line,
  186. last_line: lstack[lstack.length-1].last_line,
  187. first_column: lstack[lstack.length-(len||1)].first_column,
  188. last_column: lstack[lstack.length-1].last_column
  189. };
  190. r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
  191. if (typeof r !== 'undefined') {
  192. return r;
  193. }
  194. // pop off stack
  195. if (len) {
  196. stack = stack.slice(0,-1*len*2);
  197. vstack = vstack.slice(0, -1*len);
  198. lstack = lstack.slice(0, -1*len);
  199. }
  200. stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce)
  201. vstack.push(yyval.$);
  202. lstack.push(yyval._$);
  203. // goto new state = table[STATE][NONTERMINAL]
  204. newState = table[stack[stack.length-2]][stack[stack.length-1]];
  205. stack.push(newState);
  206. break;
  207. case 3: // accept
  208. return true;
  209. }
  210. }
  211. return true;
  212. }};
  213. /* Jison generated lexer */
  214. var lexer = (function(){
  215. var lexer = ({EOF:1,
  216. parseError:function parseError(str, hash) {
  217. if (this.yy.parseError) {
  218. this.yy.parseError(str, hash);
  219. } else {
  220. throw new Error(str);
  221. }
  222. },
  223. setInput:function (input) {
  224. this._input = input;
  225. this._more = this._less = this.done = false;
  226. this.yylineno = this.yyleng = 0;
  227. this.yytext = this.matched = this.match = '';
  228. this.conditionStack = ['INITIAL'];
  229. this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
  230. return this;
  231. },
  232. input:function () {
  233. var ch = this._input[0];
  234. this.yytext+=ch;
  235. this.yyleng++;
  236. this.match+=ch;
  237. this.matched+=ch;
  238. var lines = ch.match(/\n/);
  239. if (lines) this.yylineno++;
  240. this._input = this._input.slice(1);
  241. return ch;
  242. },
  243. unput:function (ch) {
  244. this._input = ch + this._input;
  245. return this;
  246. },
  247. more:function () {
  248. this._more = true;
  249. return this;
  250. },
  251. less:function (n) {
  252. this._input = this.match.slice(n) + this._input;
  253. },
  254. pastInput:function () {
  255. var past = this.matched.substr(0, this.matched.length - this.match.length);
  256. return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
  257. },
  258. upcomingInput:function () {
  259. var next = this.match;
  260. if (next.length < 20) {
  261. next += this._input.substr(0, 20-next.length);
  262. }
  263. return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
  264. },
  265. showPosition:function () {
  266. var pre = this.pastInput();
  267. var c = new Array(pre.length + 1).join("-");
  268. return pre + this.upcomingInput() + "\n" + c+"^";
  269. },
  270. next:function () {
  271. if (this.done) {
  272. return this.EOF;
  273. }
  274. if (!this._input) this.done = true;
  275. var token,
  276. match,
  277. tempMatch,
  278. index,
  279. col,
  280. lines;
  281. if (!this._more) {
  282. this.yytext = '';
  283. this.match = '';
  284. }
  285. var rules = this._currentRules();
  286. for (var i=0;i < rules.length; i++) {
  287. tempMatch = this._input.match(this.rules[rules[i]]);
  288. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  289. match = tempMatch;
  290. index = i;
  291. if (!this.options.flex) break;
  292. }
  293. }
  294. if (match) {
  295. lines = match[0].match(/\n.*/g);
  296. if (lines) this.yylineno += lines.length;
  297. this.yylloc = {first_line: this.yylloc.last_line,
  298. last_line: this.yylineno+1,
  299. first_column: this.yylloc.last_column,
  300. last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
  301. this.yytext += match[0];
  302. this.match += match[0];
  303. this.yyleng = this.yytext.length;
  304. this._more = false;
  305. this._input = this._input.slice(match[0].length);
  306. this.matched += match[0];
  307. token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
  308. if (this.done && this._input) this.done = false;
  309. if (token) return token;
  310. else return;
  311. }
  312. if (this._input === "") {
  313. return this.EOF;
  314. } else {
  315. this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
  316. {text: "", token: null, line: this.yylineno});
  317. }
  318. },
  319. lex:function lex() {
  320. var r = this.next();
  321. if (typeof r !== 'undefined') {
  322. return r;
  323. } else {
  324. return this.lex();
  325. }
  326. },
  327. begin:function begin(condition) {
  328. this.conditionStack.push(condition);
  329. },
  330. popState:function popState() {
  331. return this.conditionStack.pop();
  332. },
  333. _currentRules:function _currentRules() {
  334. return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
  335. },
  336. topState:function () {
  337. return this.conditionStack[this.conditionStack.length-2];
  338. },
  339. pushState:function begin(condition) {
  340. this.begin(condition);
  341. }});
  342. lexer.options = {};
  343. lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
  344. var YYSTATE=YY_START
  345. switch($avoiding_name_collisions) {
  346. case 0:/* skip whitespace */
  347. break;
  348. case 1:return 6
  349. break;
  350. case 2:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 4
  351. break;
  352. case 3:return 17
  353. break;
  354. case 4:return 18
  355. break;
  356. case 5:return 23
  357. break;
  358. case 6:return 24
  359. break;
  360. case 7:return 22
  361. break;
  362. case 8:return 21
  363. break;
  364. case 9:return 10
  365. break;
  366. case 10:return 11
  367. break;
  368. case 11:return 8
  369. break;
  370. case 12:return 14
  371. break;
  372. case 13:return 'INVALID'
  373. break;
  374. }
  375. };
  376. 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)/,/^(?:$)/,/^(?:.)/];
  377. lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}};
  378. ;
  379. return lexer;})()
  380. parser.lexer = lexer;
  381. return parser;
  382. })();
  383. if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
  384. exports.parser = jsonlint;
  385. exports.parse = function () { return jsonlint.parse.apply(jsonlint, arguments); }
  386. exports.main = function commonjsMain(args) {
  387. if (!args[1])
  388. throw new Error('Usage: '+args[0]+' FILE');
  389. if (typeof process !== 'undefined') {
  390. var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
  391. } else {
  392. var cwd = require("file").path(require("file").cwd());
  393. var source = cwd.join(args[1]).read({charset: "utf-8"});
  394. }
  395. return exports.parser.parse(source);
  396. }
  397. if (typeof module !== 'undefined' && require.main === module) {
  398. exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
  399. }
  400. }