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