0
|
1 /* PEG.js 0.6.2 (http://pegjs.majda.cz/) */
|
|
2
|
|
3 (function() {
|
|
4
|
|
5 var undefined;
|
|
6
|
|
7 var PEG = {
|
|
8 /* PEG.js version. */
|
|
9 VERSION: "0.6.2",
|
|
10
|
|
11 /*
|
|
12 * Generates a parser from a specified grammar and returns it.
|
|
13 *
|
|
14 * The grammar must be a string in the format described by the metagramar in
|
|
15 * the parser.pegjs file.
|
|
16 *
|
|
17 * Throws |PEG.parser.SyntaxError| if the grammar contains a syntax error or
|
|
18 * |PEG.GrammarError| if it contains a semantic error. Note that not all
|
|
19 * errors are detected during the generation and some may protrude to the
|
|
20 * generated parser and cause its malfunction.
|
|
21 */
|
|
22 buildParser: function(grammar) {
|
|
23 return PEG.compiler.compile(PEG.parser.parse(grammar));
|
|
24 }
|
|
25 };
|
|
26
|
|
27 /* Thrown when the grammar contains an error. */
|
|
28
|
|
29 PEG.GrammarError = function(message) {
|
|
30 this.name = "PEG.GrammarError";
|
|
31 this.message = message;
|
|
32 };
|
|
33
|
|
34 PEG.GrammarError.prototype = Error.prototype;
|
|
35
|
|
36 function contains(array, value) {
|
|
37 /*
|
|
38 * Stupid IE does not have Array.prototype.indexOf, otherwise this function
|
|
39 * would be a one-liner.
|
|
40 */
|
|
41 var length = array.length;
|
|
42 for (var i = 0; i < length; i++) {
|
|
43 if (array[i] === value) {
|
|
44 return true;
|
|
45 }
|
|
46 }
|
|
47 return false;
|
|
48 }
|
|
49
|
|
50 function each(array, callback) {
|
|
51 var length = array.length;
|
|
52 for (var i = 0; i < length; i++) {
|
|
53 callback(array[i]);
|
|
54 }
|
|
55 }
|
|
56
|
|
57 function map(array, callback) {
|
|
58 var result = [];
|
|
59 var length = array.length;
|
|
60 for (var i = 0; i < length; i++) {
|
|
61 result[i] = callback(array[i]);
|
|
62 }
|
|
63 return result;
|
|
64 }
|
|
65
|
|
66 /*
|
|
67 * Returns a string padded on the left to a desired length with a character.
|
|
68 *
|
|
69 * The code needs to be in sync with th code template in the compilation
|
|
70 * function for "action" nodes.
|
|
71 */
|
|
72 function padLeft(input, padding, length) {
|
|
73 var result = input;
|
|
74
|
|
75 var padLength = length - input.length;
|
|
76 for (var i = 0; i < padLength; i++) {
|
|
77 result = padding + result;
|
|
78 }
|
|
79
|
|
80 return result;
|
|
81 }
|
|
82
|
|
83 /*
|
|
84 * Returns an escape sequence for given character. Uses \x for characters <=
|
|
85 * 0xFF to save space, \u for the rest.
|
|
86 *
|
|
87 * The code needs to be in sync with th code template in the compilation
|
|
88 * function for "action" nodes.
|
|
89 */
|
|
90 function escape(ch) {
|
|
91 var charCode = ch.charCodeAt(0);
|
|
92
|
|
93 if (charCode <= 0xFF) {
|
|
94 var escapeChar = 'x';
|
|
95 var length = 2;
|
|
96 } else {
|
|
97 var escapeChar = 'u';
|
|
98 var length = 4;
|
|
99 }
|
|
100
|
|
101 return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
|
|
102 }
|
|
103
|
|
104 /*
|
|
105 * Surrounds the string with quotes and escapes characters inside so that the
|
|
106 * result is a valid JavaScript string.
|
|
107 *
|
|
108 * The code needs to be in sync with th code template in the compilation
|
|
109 * function for "action" nodes.
|
|
110 */
|
|
111 function quote(s) {
|
|
112 /*
|
|
113 * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a string
|
|
114 * literal except for the closing quote character, backslash, carriage return,
|
|
115 * line separator, paragraph separator, and line feed. Any character may
|
|
116 * appear in the form of an escape sequence.
|
|
117 *
|
|
118 * For portability, we also escape escape all non-ASCII characters.
|
|
119 */
|
|
120 return '"' + s
|
|
121 .replace(/\\/g, '\\\\') // backslash
|
|
122 .replace(/"/g, '\\"') // closing quote character
|
|
123 .replace(/\r/g, '\\r') // carriage return
|
|
124 .replace(/\n/g, '\\n') // line feed
|
|
125 .replace(/[\x80-\uFFFF]/g, escape) // non-ASCII characters
|
|
126 + '"';
|
|
127 };
|
|
128
|
|
129 /*
|
|
130 * Escapes characters inside the string so that it can be used as a list of
|
|
131 * characters in a character class of a regular expression.
|
|
132 */
|
|
133 function quoteForRegexpClass(s) {
|
|
134 /*
|
|
135 * Based on ECMA-262, 5th ed., 7.8.5 & 15.10.1.
|
|
136 *
|
|
137 * For portability, we also escape escape all non-ASCII characters.
|
|
138 */
|
|
139 return s
|
|
140 .replace(/\\/g, '\\\\') // backslash
|
|
141 .replace(/\0/g, '\\0') // null, IE needs this
|
|
142 .replace(/\//g, '\\/') // closing slash
|
|
143 .replace(/]/g, '\\]') // closing bracket
|
|
144 .replace(/-/g, '\\-') // dash
|
|
145 .replace(/\r/g, '\\r') // carriage return
|
|
146 .replace(/\n/g, '\\n') // line feed
|
|
147 .replace(/[\x80-\uFFFF]/g, escape) // non-ASCII characters
|
|
148 }
|
|
149
|
|
150 /*
|
|
151 * Builds a node visitor -- a function which takes a node and any number of
|
|
152 * other parameters, calls an appropriate function according to the node type,
|
|
153 * passes it all its parameters and returns its value. The functions for various
|
|
154 * node types are passed in a parameter to |buildNodeVisitor| as a hash.
|
|
155 */
|
|
156 function buildNodeVisitor(functions) {
|
|
157 return function(node) {
|
|
158 return functions[node.type].apply(null, arguments);
|
|
159 }
|
|
160 }
|
|
161 PEG.parser = (function(){
|
|
162 /* Generated by PEG.js 0.6.2 (http://pegjs.majda.cz/). */
|
|
163
|
|
164 var result = {
|
|
165 /*
|
|
166 * Parses the input with a generated parser. If the parsing is successfull,
|
|
167 * returns a value explicitly or implicitly specified by the grammar from
|
|
168 * which the parser was generated (see |PEG.buildParser|). If the parsing is
|
|
169 * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
|
|
170 */
|
|
171 parse: function(input, startRule) {
|
|
172 var parseFunctions = {
|
|
173 "__": parse___,
|
|
174 "action": parse_action,
|
|
175 "and": parse_and,
|
|
176 "braced": parse_braced,
|
|
177 "bracketDelimitedCharacter": parse_bracketDelimitedCharacter,
|
|
178 "choice": parse_choice,
|
|
179 "class": parse_class,
|
|
180 "classCharacter": parse_classCharacter,
|
|
181 "classCharacterRange": parse_classCharacterRange,
|
|
182 "colon": parse_colon,
|
|
183 "comment": parse_comment,
|
|
184 "digit": parse_digit,
|
|
185 "dot": parse_dot,
|
|
186 "doubleQuotedCharacter": parse_doubleQuotedCharacter,
|
|
187 "doubleQuotedLiteral": parse_doubleQuotedLiteral,
|
|
188 "eol": parse_eol,
|
|
189 "eolChar": parse_eolChar,
|
|
190 "eolEscapeSequence": parse_eolEscapeSequence,
|
|
191 "equals": parse_equals,
|
|
192 "grammar": parse_grammar,
|
|
193 "hexDigit": parse_hexDigit,
|
|
194 "hexEscapeSequence": parse_hexEscapeSequence,
|
|
195 "identifier": parse_identifier,
|
|
196 "initializer": parse_initializer,
|
|
197 "labeled": parse_labeled,
|
|
198 "letter": parse_letter,
|
|
199 "literal": parse_literal,
|
|
200 "lowerCaseLetter": parse_lowerCaseLetter,
|
|
201 "lparen": parse_lparen,
|
|
202 "multiLineComment": parse_multiLineComment,
|
|
203 "nonBraceCharacter": parse_nonBraceCharacter,
|
|
204 "nonBraceCharacters": parse_nonBraceCharacters,
|
|
205 "not": parse_not,
|
|
206 "plus": parse_plus,
|
|
207 "prefixed": parse_prefixed,
|
|
208 "primary": parse_primary,
|
|
209 "question": parse_question,
|
|
210 "rparen": parse_rparen,
|
|
211 "rule": parse_rule,
|
|
212 "semicolon": parse_semicolon,
|
|
213 "sequence": parse_sequence,
|
|
214 "simpleBracketDelimitedCharacter": parse_simpleBracketDelimitedCharacter,
|
|
215 "simpleDoubleQuotedCharacter": parse_simpleDoubleQuotedCharacter,
|
|
216 "simpleEscapeSequence": parse_simpleEscapeSequence,
|
|
217 "simpleSingleQuotedCharacter": parse_simpleSingleQuotedCharacter,
|
|
218 "singleLineComment": parse_singleLineComment,
|
|
219 "singleQuotedCharacter": parse_singleQuotedCharacter,
|
|
220 "singleQuotedLiteral": parse_singleQuotedLiteral,
|
|
221 "slash": parse_slash,
|
|
222 "star": parse_star,
|
|
223 "suffixed": parse_suffixed,
|
|
224 "unicodeEscapeSequence": parse_unicodeEscapeSequence,
|
|
225 "upperCaseLetter": parse_upperCaseLetter,
|
|
226 "whitespace": parse_whitespace,
|
|
227 "zeroEscapeSequence": parse_zeroEscapeSequence
|
|
228 };
|
|
229
|
|
230 if (startRule !== undefined) {
|
|
231 if (parseFunctions[startRule] === undefined) {
|
|
232 throw new Error("Invalid rule name: " + quote(startRule) + ".");
|
|
233 }
|
|
234 } else {
|
|
235 startRule = "grammar";
|
|
236 }
|
|
237
|
|
238 var pos = 0;
|
|
239 var reportMatchFailures = true;
|
|
240 var rightmostMatchFailuresPos = 0;
|
|
241 var rightmostMatchFailuresExpected = [];
|
|
242 var cache = {};
|
|
243
|
|
244 function padLeft(input, padding, length) {
|
|
245 var result = input;
|
|
246
|
|
247 var padLength = length - input.length;
|
|
248 for (var i = 0; i < padLength; i++) {
|
|
249 result = padding + result;
|
|
250 }
|
|
251
|
|
252 return result;
|
|
253 }
|
|
254
|
|
255 function escape(ch) {
|
|
256 var charCode = ch.charCodeAt(0);
|
|
257
|
|
258 if (charCode <= 0xFF) {
|
|
259 var escapeChar = 'x';
|
|
260 var length = 2;
|
|
261 } else {
|
|
262 var escapeChar = 'u';
|
|
263 var length = 4;
|
|
264 }
|
|
265
|
|
266 return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
|
|
267 }
|
|
268
|
|
269 function quote(s) {
|
|
270 /*
|
|
271 * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
|
|
272 * string literal except for the closing quote character, backslash,
|
|
273 * carriage return, line separator, paragraph separator, and line feed.
|
|
274 * Any character may appear in the form of an escape sequence.
|
|
275 */
|
|
276 return '"' + s
|
|
277 .replace(/\\/g, '\\\\') // backslash
|
|
278 .replace(/"/g, '\\"') // closing quote character
|
|
279 .replace(/\r/g, '\\r') // carriage return
|
|
280 .replace(/\n/g, '\\n') // line feed
|
|
281 .replace(/[\x80-\uFFFF]/g, escape) // non-ASCII characters
|
|
282 + '"';
|
|
283 }
|
|
284
|
|
285 function matchFailed(failure) {
|
|
286 if (pos < rightmostMatchFailuresPos) {
|
|
287 return;
|
|
288 }
|
|
289
|
|
290 if (pos > rightmostMatchFailuresPos) {
|
|
291 rightmostMatchFailuresPos = pos;
|
|
292 rightmostMatchFailuresExpected = [];
|
|
293 }
|
|
294
|
|
295 rightmostMatchFailuresExpected.push(failure);
|
|
296 }
|
|
297
|
|
298 function parse_grammar() {
|
|
299 var cacheKey = 'grammar@' + pos;
|
|
300 var cachedResult = cache[cacheKey];
|
|
301 if (cachedResult) {
|
|
302 pos = cachedResult.nextPos;
|
|
303 return cachedResult.result;
|
|
304 }
|
|
305
|
|
306
|
|
307 var savedPos0 = pos;
|
|
308 var savedPos1 = pos;
|
|
309 var result3 = parse___();
|
|
310 if (result3 !== null) {
|
|
311 var result7 = parse_initializer();
|
|
312 var result4 = result7 !== null ? result7 : '';
|
|
313 if (result4 !== null) {
|
|
314 var result6 = parse_rule();
|
|
315 if (result6 !== null) {
|
|
316 var result5 = [];
|
|
317 while (result6 !== null) {
|
|
318 result5.push(result6);
|
|
319 var result6 = parse_rule();
|
|
320 }
|
|
321 } else {
|
|
322 var result5 = null;
|
|
323 }
|
|
324 if (result5 !== null) {
|
|
325 var result1 = [result3, result4, result5];
|
|
326 } else {
|
|
327 var result1 = null;
|
|
328 pos = savedPos1;
|
|
329 }
|
|
330 } else {
|
|
331 var result1 = null;
|
|
332 pos = savedPos1;
|
|
333 }
|
|
334 } else {
|
|
335 var result1 = null;
|
|
336 pos = savedPos1;
|
|
337 }
|
|
338 var result2 = result1 !== null
|
|
339 ? (function(initializer, rules) {
|
|
340 var rulesConverted = {};
|
|
341 each(rules, function(rule) { rulesConverted[rule.name] = rule; });
|
|
342
|
|
343 return {
|
|
344 type: "grammar",
|
|
345 initializer: initializer !== "" ? initializer : null,
|
|
346 rules: rulesConverted,
|
|
347 startRule: rules[0].name
|
|
348 }
|
|
349 })(result1[1], result1[2])
|
|
350 : null;
|
|
351 if (result2 !== null) {
|
|
352 var result0 = result2;
|
|
353 } else {
|
|
354 var result0 = null;
|
|
355 pos = savedPos0;
|
|
356 }
|
|
357
|
|
358
|
|
359
|
|
360 cache[cacheKey] = {
|
|
361 nextPos: pos,
|
|
362 result: result0
|
|
363 };
|
|
364 return result0;
|
|
365 }
|
|
366
|
|
367 function parse_initializer() {
|
|
368 var cacheKey = 'initializer@' + pos;
|
|
369 var cachedResult = cache[cacheKey];
|
|
370 if (cachedResult) {
|
|
371 pos = cachedResult.nextPos;
|
|
372 return cachedResult.result;
|
|
373 }
|
|
374
|
|
375
|
|
376 var savedPos0 = pos;
|
|
377 var savedPos1 = pos;
|
|
378 var result3 = parse_action();
|
|
379 if (result3 !== null) {
|
|
380 var result5 = parse_semicolon();
|
|
381 var result4 = result5 !== null ? result5 : '';
|
|
382 if (result4 !== null) {
|
|
383 var result1 = [result3, result4];
|
|
384 } else {
|
|
385 var result1 = null;
|
|
386 pos = savedPos1;
|
|
387 }
|
|
388 } else {
|
|
389 var result1 = null;
|
|
390 pos = savedPos1;
|
|
391 }
|
|
392 var result2 = result1 !== null
|
|
393 ? (function(code) {
|
|
394 return {
|
|
395 type: "initializer",
|
|
396 code: code
|
|
397 };
|
|
398 })(result1[0])
|
|
399 : null;
|
|
400 if (result2 !== null) {
|
|
401 var result0 = result2;
|
|
402 } else {
|
|
403 var result0 = null;
|
|
404 pos = savedPos0;
|
|
405 }
|
|
406
|
|
407
|
|
408
|
|
409 cache[cacheKey] = {
|
|
410 nextPos: pos,
|
|
411 result: result0
|
|
412 };
|
|
413 return result0;
|
|
414 }
|
|
415
|
|
416 function parse_rule() {
|
|
417 var cacheKey = 'rule@' + pos;
|
|
418 var cachedResult = cache[cacheKey];
|
|
419 if (cachedResult) {
|
|
420 pos = cachedResult.nextPos;
|
|
421 return cachedResult.result;
|
|
422 }
|
|
423
|
|
424
|
|
425 var savedPos0 = pos;
|
|
426 var savedPos1 = pos;
|
|
427 var result3 = parse_identifier();
|
|
428 if (result3 !== null) {
|
|
429 var result10 = parse_literal();
|
|
430 if (result10 !== null) {
|
|
431 var result4 = result10;
|
|
432 } else {
|
|
433 if (input.substr(pos, 0) === "") {
|
|
434 var result9 = "";
|
|
435 pos += 0;
|
|
436 } else {
|
|
437 var result9 = null;
|
|
438 if (reportMatchFailures) {
|
|
439 matchFailed("\"\"");
|
|
440 }
|
|
441 }
|
|
442 if (result9 !== null) {
|
|
443 var result4 = result9;
|
|
444 } else {
|
|
445 var result4 = null;;
|
|
446 };
|
|
447 }
|
|
448 if (result4 !== null) {
|
|
449 var result5 = parse_equals();
|
|
450 if (result5 !== null) {
|
|
451 var result6 = parse_choice();
|
|
452 if (result6 !== null) {
|
|
453 var result8 = parse_semicolon();
|
|
454 var result7 = result8 !== null ? result8 : '';
|
|
455 if (result7 !== null) {
|
|
456 var result1 = [result3, result4, result5, result6, result7];
|
|
457 } else {
|
|
458 var result1 = null;
|
|
459 pos = savedPos1;
|
|
460 }
|
|
461 } else {
|
|
462 var result1 = null;
|
|
463 pos = savedPos1;
|
|
464 }
|
|
465 } else {
|
|
466 var result1 = null;
|
|
467 pos = savedPos1;
|
|
468 }
|
|
469 } else {
|
|
470 var result1 = null;
|
|
471 pos = savedPos1;
|
|
472 }
|
|
473 } else {
|
|
474 var result1 = null;
|
|
475 pos = savedPos1;
|
|
476 }
|
|
477 var result2 = result1 !== null
|
|
478 ? (function(name, displayName, expression) {
|
|
479 return {
|
|
480 type: "rule",
|
|
481 name: name,
|
|
482 displayName: displayName !== "" ? displayName : null,
|
|
483 expression: expression
|
|
484 };
|
|
485 })(result1[0], result1[1], result1[3])
|
|
486 : null;
|
|
487 if (result2 !== null) {
|
|
488 var result0 = result2;
|
|
489 } else {
|
|
490 var result0 = null;
|
|
491 pos = savedPos0;
|
|
492 }
|
|
493
|
|
494
|
|
495
|
|
496 cache[cacheKey] = {
|
|
497 nextPos: pos,
|
|
498 result: result0
|
|
499 };
|
|
500 return result0;
|
|
501 }
|
|
502
|
|
503 function parse_choice() {
|
|
504 var cacheKey = 'choice@' + pos;
|
|
505 var cachedResult = cache[cacheKey];
|
|
506 if (cachedResult) {
|
|
507 pos = cachedResult.nextPos;
|
|
508 return cachedResult.result;
|
|
509 }
|
|
510
|
|
511
|
|
512 var savedPos0 = pos;
|
|
513 var savedPos1 = pos;
|
|
514 var result3 = parse_sequence();
|
|
515 if (result3 !== null) {
|
|
516 var result4 = [];
|
|
517 var savedPos2 = pos;
|
|
518 var result6 = parse_slash();
|
|
519 if (result6 !== null) {
|
|
520 var result7 = parse_sequence();
|
|
521 if (result7 !== null) {
|
|
522 var result5 = [result6, result7];
|
|
523 } else {
|
|
524 var result5 = null;
|
|
525 pos = savedPos2;
|
|
526 }
|
|
527 } else {
|
|
528 var result5 = null;
|
|
529 pos = savedPos2;
|
|
530 }
|
|
531 while (result5 !== null) {
|
|
532 result4.push(result5);
|
|
533 var savedPos2 = pos;
|
|
534 var result6 = parse_slash();
|
|
535 if (result6 !== null) {
|
|
536 var result7 = parse_sequence();
|
|
537 if (result7 !== null) {
|
|
538 var result5 = [result6, result7];
|
|
539 } else {
|
|
540 var result5 = null;
|
|
541 pos = savedPos2;
|
|
542 }
|
|
543 } else {
|
|
544 var result5 = null;
|
|
545 pos = savedPos2;
|
|
546 }
|
|
547 }
|
|
548 if (result4 !== null) {
|
|
549 var result1 = [result3, result4];
|
|
550 } else {
|
|
551 var result1 = null;
|
|
552 pos = savedPos1;
|
|
553 }
|
|
554 } else {
|
|
555 var result1 = null;
|
|
556 pos = savedPos1;
|
|
557 }
|
|
558 var result2 = result1 !== null
|
|
559 ? (function(head, tail) {
|
|
560 if (tail.length > 0) {
|
|
561 var alternatives = [head].concat(map(
|
|
562 tail,
|
|
563 function(element) { return element[1]; }
|
|
564 ));
|
|
565 return {
|
|
566 type: "choice",
|
|
567 alternatives: alternatives
|
|
568 }
|
|
569 } else {
|
|
570 return head;
|
|
571 }
|
|
572 })(result1[0], result1[1])
|
|
573 : null;
|
|
574 if (result2 !== null) {
|
|
575 var result0 = result2;
|
|
576 } else {
|
|
577 var result0 = null;
|
|
578 pos = savedPos0;
|
|
579 }
|
|
580
|
|
581
|
|
582
|
|
583 cache[cacheKey] = {
|
|
584 nextPos: pos,
|
|
585 result: result0
|
|
586 };
|
|
587 return result0;
|
|
588 }
|
|
589
|
|
590 function parse_sequence() {
|
|
591 var cacheKey = 'sequence@' + pos;
|
|
592 var cachedResult = cache[cacheKey];
|
|
593 if (cachedResult) {
|
|
594 pos = cachedResult.nextPos;
|
|
595 return cachedResult.result;
|
|
596 }
|
|
597
|
|
598
|
|
599 var savedPos1 = pos;
|
|
600 var savedPos2 = pos;
|
|
601 var result8 = [];
|
|
602 var result10 = parse_labeled();
|
|
603 while (result10 !== null) {
|
|
604 result8.push(result10);
|
|
605 var result10 = parse_labeled();
|
|
606 }
|
|
607 if (result8 !== null) {
|
|
608 var result9 = parse_action();
|
|
609 if (result9 !== null) {
|
|
610 var result6 = [result8, result9];
|
|
611 } else {
|
|
612 var result6 = null;
|
|
613 pos = savedPos2;
|
|
614 }
|
|
615 } else {
|
|
616 var result6 = null;
|
|
617 pos = savedPos2;
|
|
618 }
|
|
619 var result7 = result6 !== null
|
|
620 ? (function(elements, code) {
|
|
621 var expression = elements.length != 1
|
|
622 ? {
|
|
623 type: "sequence",
|
|
624 elements: elements
|
|
625 }
|
|
626 : elements[0];
|
|
627 return {
|
|
628 type: "action",
|
|
629 expression: expression,
|
|
630 code: code
|
|
631 };
|
|
632 })(result6[0], result6[1])
|
|
633 : null;
|
|
634 if (result7 !== null) {
|
|
635 var result5 = result7;
|
|
636 } else {
|
|
637 var result5 = null;
|
|
638 pos = savedPos1;
|
|
639 }
|
|
640 if (result5 !== null) {
|
|
641 var result0 = result5;
|
|
642 } else {
|
|
643 var savedPos0 = pos;
|
|
644 var result2 = [];
|
|
645 var result4 = parse_labeled();
|
|
646 while (result4 !== null) {
|
|
647 result2.push(result4);
|
|
648 var result4 = parse_labeled();
|
|
649 }
|
|
650 var result3 = result2 !== null
|
|
651 ? (function(elements) {
|
|
652 return elements.length != 1
|
|
653 ? {
|
|
654 type: "sequence",
|
|
655 elements: elements
|
|
656 }
|
|
657 : elements[0];
|
|
658 })(result2)
|
|
659 : null;
|
|
660 if (result3 !== null) {
|
|
661 var result1 = result3;
|
|
662 } else {
|
|
663 var result1 = null;
|
|
664 pos = savedPos0;
|
|
665 }
|
|
666 if (result1 !== null) {
|
|
667 var result0 = result1;
|
|
668 } else {
|
|
669 var result0 = null;;
|
|
670 };
|
|
671 }
|
|
672
|
|
673
|
|
674
|
|
675 cache[cacheKey] = {
|
|
676 nextPos: pos,
|
|
677 result: result0
|
|
678 };
|
|
679 return result0;
|
|
680 }
|
|
681
|
|
682 function parse_labeled() {
|
|
683 var cacheKey = 'labeled@' + pos;
|
|
684 var cachedResult = cache[cacheKey];
|
|
685 if (cachedResult) {
|
|
686 pos = cachedResult.nextPos;
|
|
687 return cachedResult.result;
|
|
688 }
|
|
689
|
|
690
|
|
691 var savedPos0 = pos;
|
|
692 var savedPos1 = pos;
|
|
693 var result5 = parse_identifier();
|
|
694 if (result5 !== null) {
|
|
695 var result6 = parse_colon();
|
|
696 if (result6 !== null) {
|
|
697 var result7 = parse_prefixed();
|
|
698 if (result7 !== null) {
|
|
699 var result3 = [result5, result6, result7];
|
|
700 } else {
|
|
701 var result3 = null;
|
|
702 pos = savedPos1;
|
|
703 }
|
|
704 } else {
|
|
705 var result3 = null;
|
|
706 pos = savedPos1;
|
|
707 }
|
|
708 } else {
|
|
709 var result3 = null;
|
|
710 pos = savedPos1;
|
|
711 }
|
|
712 var result4 = result3 !== null
|
|
713 ? (function(label, expression) {
|
|
714 return {
|
|
715 type: "labeled",
|
|
716 label: label,
|
|
717 expression: expression
|
|
718 };
|
|
719 })(result3[0], result3[2])
|
|
720 : null;
|
|
721 if (result4 !== null) {
|
|
722 var result2 = result4;
|
|
723 } else {
|
|
724 var result2 = null;
|
|
725 pos = savedPos0;
|
|
726 }
|
|
727 if (result2 !== null) {
|
|
728 var result0 = result2;
|
|
729 } else {
|
|
730 var result1 = parse_prefixed();
|
|
731 if (result1 !== null) {
|
|
732 var result0 = result1;
|
|
733 } else {
|
|
734 var result0 = null;;
|
|
735 };
|
|
736 }
|
|
737
|
|
738
|
|
739
|
|
740 cache[cacheKey] = {
|
|
741 nextPos: pos,
|
|
742 result: result0
|
|
743 };
|
|
744 return result0;
|
|
745 }
|
|
746
|
|
747 function parse_prefixed() {
|
|
748 var cacheKey = 'prefixed@' + pos;
|
|
749 var cachedResult = cache[cacheKey];
|
|
750 if (cachedResult) {
|
|
751 pos = cachedResult.nextPos;
|
|
752 return cachedResult.result;
|
|
753 }
|
|
754
|
|
755
|
|
756 var savedPos6 = pos;
|
|
757 var savedPos7 = pos;
|
|
758 var result20 = parse_and();
|
|
759 if (result20 !== null) {
|
|
760 var result21 = parse_action();
|
|
761 if (result21 !== null) {
|
|
762 var result18 = [result20, result21];
|
|
763 } else {
|
|
764 var result18 = null;
|
|
765 pos = savedPos7;
|
|
766 }
|
|
767 } else {
|
|
768 var result18 = null;
|
|
769 pos = savedPos7;
|
|
770 }
|
|
771 var result19 = result18 !== null
|
|
772 ? (function(code) {
|
|
773 return {
|
|
774 type: "semantic_and",
|
|
775 code: code
|
|
776 };
|
|
777 })(result18[1])
|
|
778 : null;
|
|
779 if (result19 !== null) {
|
|
780 var result17 = result19;
|
|
781 } else {
|
|
782 var result17 = null;
|
|
783 pos = savedPos6;
|
|
784 }
|
|
785 if (result17 !== null) {
|
|
786 var result0 = result17;
|
|
787 } else {
|
|
788 var savedPos4 = pos;
|
|
789 var savedPos5 = pos;
|
|
790 var result15 = parse_and();
|
|
791 if (result15 !== null) {
|
|
792 var result16 = parse_suffixed();
|
|
793 if (result16 !== null) {
|
|
794 var result13 = [result15, result16];
|
|
795 } else {
|
|
796 var result13 = null;
|
|
797 pos = savedPos5;
|
|
798 }
|
|
799 } else {
|
|
800 var result13 = null;
|
|
801 pos = savedPos5;
|
|
802 }
|
|
803 var result14 = result13 !== null
|
|
804 ? (function(expression) {
|
|
805 return {
|
|
806 type: "simple_and",
|
|
807 expression: expression
|
|
808 };
|
|
809 })(result13[1])
|
|
810 : null;
|
|
811 if (result14 !== null) {
|
|
812 var result12 = result14;
|
|
813 } else {
|
|
814 var result12 = null;
|
|
815 pos = savedPos4;
|
|
816 }
|
|
817 if (result12 !== null) {
|
|
818 var result0 = result12;
|
|
819 } else {
|
|
820 var savedPos2 = pos;
|
|
821 var savedPos3 = pos;
|
|
822 var result10 = parse_not();
|
|
823 if (result10 !== null) {
|
|
824 var result11 = parse_action();
|
|
825 if (result11 !== null) {
|
|
826 var result8 = [result10, result11];
|
|
827 } else {
|
|
828 var result8 = null;
|
|
829 pos = savedPos3;
|
|
830 }
|
|
831 } else {
|
|
832 var result8 = null;
|
|
833 pos = savedPos3;
|
|
834 }
|
|
835 var result9 = result8 !== null
|
|
836 ? (function(code) {
|
|
837 return {
|
|
838 type: "semantic_not",
|
|
839 code: code
|
|
840 };
|
|
841 })(result8[1])
|
|
842 : null;
|
|
843 if (result9 !== null) {
|
|
844 var result7 = result9;
|
|
845 } else {
|
|
846 var result7 = null;
|
|
847 pos = savedPos2;
|
|
848 }
|
|
849 if (result7 !== null) {
|
|
850 var result0 = result7;
|
|
851 } else {
|
|
852 var savedPos0 = pos;
|
|
853 var savedPos1 = pos;
|
|
854 var result5 = parse_not();
|
|
855 if (result5 !== null) {
|
|
856 var result6 = parse_suffixed();
|
|
857 if (result6 !== null) {
|
|
858 var result3 = [result5, result6];
|
|
859 } else {
|
|
860 var result3 = null;
|
|
861 pos = savedPos1;
|
|
862 }
|
|
863 } else {
|
|
864 var result3 = null;
|
|
865 pos = savedPos1;
|
|
866 }
|
|
867 var result4 = result3 !== null
|
|
868 ? (function(expression) {
|
|
869 return {
|
|
870 type: "simple_not",
|
|
871 expression: expression
|
|
872 };
|
|
873 })(result3[1])
|
|
874 : null;
|
|
875 if (result4 !== null) {
|
|
876 var result2 = result4;
|
|
877 } else {
|
|
878 var result2 = null;
|
|
879 pos = savedPos0;
|
|
880 }
|
|
881 if (result2 !== null) {
|
|
882 var result0 = result2;
|
|
883 } else {
|
|
884 var result1 = parse_suffixed();
|
|
885 if (result1 !== null) {
|
|
886 var result0 = result1;
|
|
887 } else {
|
|
888 var result0 = null;;
|
|
889 };
|
|
890 };
|
|
891 };
|
|
892 };
|
|
893 }
|
|
894
|
|
895
|
|
896
|
|
897 cache[cacheKey] = {
|
|
898 nextPos: pos,
|
|
899 result: result0
|
|
900 };
|
|
901 return result0;
|
|
902 }
|
|
903
|
|
904 function parse_suffixed() {
|
|
905 var cacheKey = 'suffixed@' + pos;
|
|
906 var cachedResult = cache[cacheKey];
|
|
907 if (cachedResult) {
|
|
908 pos = cachedResult.nextPos;
|
|
909 return cachedResult.result;
|
|
910 }
|
|
911
|
|
912
|
|
913 var savedPos4 = pos;
|
|
914 var savedPos5 = pos;
|
|
915 var result15 = parse_primary();
|
|
916 if (result15 !== null) {
|
|
917 var result16 = parse_question();
|
|
918 if (result16 !== null) {
|
|
919 var result13 = [result15, result16];
|
|
920 } else {
|
|
921 var result13 = null;
|
|
922 pos = savedPos5;
|
|
923 }
|
|
924 } else {
|
|
925 var result13 = null;
|
|
926 pos = savedPos5;
|
|
927 }
|
|
928 var result14 = result13 !== null
|
|
929 ? (function(expression) {
|
|
930 return {
|
|
931 type: "optional",
|
|
932 expression: expression
|
|
933 };
|
|
934 })(result13[0])
|
|
935 : null;
|
|
936 if (result14 !== null) {
|
|
937 var result12 = result14;
|
|
938 } else {
|
|
939 var result12 = null;
|
|
940 pos = savedPos4;
|
|
941 }
|
|
942 if (result12 !== null) {
|
|
943 var result0 = result12;
|
|
944 } else {
|
|
945 var savedPos2 = pos;
|
|
946 var savedPos3 = pos;
|
|
947 var result10 = parse_primary();
|
|
948 if (result10 !== null) {
|
|
949 var result11 = parse_star();
|
|
950 if (result11 !== null) {
|
|
951 var result8 = [result10, result11];
|
|
952 } else {
|
|
953 var result8 = null;
|
|
954 pos = savedPos3;
|
|
955 }
|
|
956 } else {
|
|
957 var result8 = null;
|
|
958 pos = savedPos3;
|
|
959 }
|
|
960 var result9 = result8 !== null
|
|
961 ? (function(expression) {
|
|
962 return {
|
|
963 type: "zero_or_more",
|
|
964 expression: expression
|
|
965 };
|
|
966 })(result8[0])
|
|
967 : null;
|
|
968 if (result9 !== null) {
|
|
969 var result7 = result9;
|
|
970 } else {
|
|
971 var result7 = null;
|
|
972 pos = savedPos2;
|
|
973 }
|
|
974 if (result7 !== null) {
|
|
975 var result0 = result7;
|
|
976 } else {
|
|
977 var savedPos0 = pos;
|
|
978 var savedPos1 = pos;
|
|
979 var result5 = parse_primary();
|
|
980 if (result5 !== null) {
|
|
981 var result6 = parse_plus();
|
|
982 if (result6 !== null) {
|
|
983 var result3 = [result5, result6];
|
|
984 } else {
|
|
985 var result3 = null;
|
|
986 pos = savedPos1;
|
|
987 }
|
|
988 } else {
|
|
989 var result3 = null;
|
|
990 pos = savedPos1;
|
|
991 }
|
|
992 var result4 = result3 !== null
|
|
993 ? (function(expression) {
|
|
994 return {
|
|
995 type: "one_or_more",
|
|
996 expression: expression
|
|
997 };
|
|
998 })(result3[0])
|
|
999 : null;
|
|
1000 if (result4 !== null) {
|
|
1001 var result2 = result4;
|
|
1002 } else {
|
|
1003 var result2 = null;
|
|
1004 pos = savedPos0;
|
|
1005 }
|
|
1006 if (result2 !== null) {
|
|
1007 var result0 = result2;
|
|
1008 } else {
|
|
1009 var result1 = parse_primary();
|
|
1010 if (result1 !== null) {
|
|
1011 var result0 = result1;
|
|
1012 } else {
|
|
1013 var result0 = null;;
|
|
1014 };
|
|
1015 };
|
|
1016 };
|
|
1017 }
|
|
1018
|
|
1019
|
|
1020
|
|
1021 cache[cacheKey] = {
|
|
1022 nextPos: pos,
|
|
1023 result: result0
|
|
1024 };
|
|
1025 return result0;
|
|
1026 }
|
|
1027
|
|
1028 function parse_primary() {
|
|
1029 var cacheKey = 'primary@' + pos;
|
|
1030 var cachedResult = cache[cacheKey];
|
|
1031 if (cachedResult) {
|
|
1032 pos = cachedResult.nextPos;
|
|
1033 return cachedResult.result;
|
|
1034 }
|
|
1035
|
|
1036
|
|
1037 var savedPos4 = pos;
|
|
1038 var savedPos5 = pos;
|
|
1039 var result17 = parse_identifier();
|
|
1040 if (result17 !== null) {
|
|
1041 var savedPos6 = pos;
|
|
1042 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
1043 reportMatchFailures = false;
|
|
1044 var savedPos7 = pos;
|
|
1045 var result23 = parse_literal();
|
|
1046 if (result23 !== null) {
|
|
1047 var result20 = result23;
|
|
1048 } else {
|
|
1049 if (input.substr(pos, 0) === "") {
|
|
1050 var result22 = "";
|
|
1051 pos += 0;
|
|
1052 } else {
|
|
1053 var result22 = null;
|
|
1054 if (reportMatchFailures) {
|
|
1055 matchFailed("\"\"");
|
|
1056 }
|
|
1057 }
|
|
1058 if (result22 !== null) {
|
|
1059 var result20 = result22;
|
|
1060 } else {
|
|
1061 var result20 = null;;
|
|
1062 };
|
|
1063 }
|
|
1064 if (result20 !== null) {
|
|
1065 var result21 = parse_equals();
|
|
1066 if (result21 !== null) {
|
|
1067 var result19 = [result20, result21];
|
|
1068 } else {
|
|
1069 var result19 = null;
|
|
1070 pos = savedPos7;
|
|
1071 }
|
|
1072 } else {
|
|
1073 var result19 = null;
|
|
1074 pos = savedPos7;
|
|
1075 }
|
|
1076 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
1077 if (result19 === null) {
|
|
1078 var result18 = '';
|
|
1079 } else {
|
|
1080 var result18 = null;
|
|
1081 pos = savedPos6;
|
|
1082 }
|
|
1083 if (result18 !== null) {
|
|
1084 var result15 = [result17, result18];
|
|
1085 } else {
|
|
1086 var result15 = null;
|
|
1087 pos = savedPos5;
|
|
1088 }
|
|
1089 } else {
|
|
1090 var result15 = null;
|
|
1091 pos = savedPos5;
|
|
1092 }
|
|
1093 var result16 = result15 !== null
|
|
1094 ? (function(name) {
|
|
1095 return {
|
|
1096 type: "rule_ref",
|
|
1097 name: name
|
|
1098 };
|
|
1099 })(result15[0])
|
|
1100 : null;
|
|
1101 if (result16 !== null) {
|
|
1102 var result14 = result16;
|
|
1103 } else {
|
|
1104 var result14 = null;
|
|
1105 pos = savedPos4;
|
|
1106 }
|
|
1107 if (result14 !== null) {
|
|
1108 var result0 = result14;
|
|
1109 } else {
|
|
1110 var savedPos3 = pos;
|
|
1111 var result12 = parse_literal();
|
|
1112 var result13 = result12 !== null
|
|
1113 ? (function(value) {
|
|
1114 return {
|
|
1115 type: "literal",
|
|
1116 value: value
|
|
1117 };
|
|
1118 })(result12)
|
|
1119 : null;
|
|
1120 if (result13 !== null) {
|
|
1121 var result11 = result13;
|
|
1122 } else {
|
|
1123 var result11 = null;
|
|
1124 pos = savedPos3;
|
|
1125 }
|
|
1126 if (result11 !== null) {
|
|
1127 var result0 = result11;
|
|
1128 } else {
|
|
1129 var savedPos2 = pos;
|
|
1130 var result9 = parse_dot();
|
|
1131 var result10 = result9 !== null
|
|
1132 ? (function() { return { type: "any" }; })()
|
|
1133 : null;
|
|
1134 if (result10 !== null) {
|
|
1135 var result8 = result10;
|
|
1136 } else {
|
|
1137 var result8 = null;
|
|
1138 pos = savedPos2;
|
|
1139 }
|
|
1140 if (result8 !== null) {
|
|
1141 var result0 = result8;
|
|
1142 } else {
|
|
1143 var result7 = parse_class();
|
|
1144 if (result7 !== null) {
|
|
1145 var result0 = result7;
|
|
1146 } else {
|
|
1147 var savedPos0 = pos;
|
|
1148 var savedPos1 = pos;
|
|
1149 var result4 = parse_lparen();
|
|
1150 if (result4 !== null) {
|
|
1151 var result5 = parse_choice();
|
|
1152 if (result5 !== null) {
|
|
1153 var result6 = parse_rparen();
|
|
1154 if (result6 !== null) {
|
|
1155 var result2 = [result4, result5, result6];
|
|
1156 } else {
|
|
1157 var result2 = null;
|
|
1158 pos = savedPos1;
|
|
1159 }
|
|
1160 } else {
|
|
1161 var result2 = null;
|
|
1162 pos = savedPos1;
|
|
1163 }
|
|
1164 } else {
|
|
1165 var result2 = null;
|
|
1166 pos = savedPos1;
|
|
1167 }
|
|
1168 var result3 = result2 !== null
|
|
1169 ? (function(expression) { return expression; })(result2[1])
|
|
1170 : null;
|
|
1171 if (result3 !== null) {
|
|
1172 var result1 = result3;
|
|
1173 } else {
|
|
1174 var result1 = null;
|
|
1175 pos = savedPos0;
|
|
1176 }
|
|
1177 if (result1 !== null) {
|
|
1178 var result0 = result1;
|
|
1179 } else {
|
|
1180 var result0 = null;;
|
|
1181 };
|
|
1182 };
|
|
1183 };
|
|
1184 };
|
|
1185 }
|
|
1186
|
|
1187
|
|
1188
|
|
1189 cache[cacheKey] = {
|
|
1190 nextPos: pos,
|
|
1191 result: result0
|
|
1192 };
|
|
1193 return result0;
|
|
1194 }
|
|
1195
|
|
1196 function parse_action() {
|
|
1197 var cacheKey = 'action@' + pos;
|
|
1198 var cachedResult = cache[cacheKey];
|
|
1199 if (cachedResult) {
|
|
1200 pos = cachedResult.nextPos;
|
|
1201 return cachedResult.result;
|
|
1202 }
|
|
1203
|
|
1204 var savedReportMatchFailures = reportMatchFailures;
|
|
1205 reportMatchFailures = false;
|
|
1206 var savedPos0 = pos;
|
|
1207 var savedPos1 = pos;
|
|
1208 var result3 = parse_braced();
|
|
1209 if (result3 !== null) {
|
|
1210 var result4 = parse___();
|
|
1211 if (result4 !== null) {
|
|
1212 var result1 = [result3, result4];
|
|
1213 } else {
|
|
1214 var result1 = null;
|
|
1215 pos = savedPos1;
|
|
1216 }
|
|
1217 } else {
|
|
1218 var result1 = null;
|
|
1219 pos = savedPos1;
|
|
1220 }
|
|
1221 var result2 = result1 !== null
|
|
1222 ? (function(braced) { return braced.substr(1, braced.length - 2); })(result1[0])
|
|
1223 : null;
|
|
1224 if (result2 !== null) {
|
|
1225 var result0 = result2;
|
|
1226 } else {
|
|
1227 var result0 = null;
|
|
1228 pos = savedPos0;
|
|
1229 }
|
|
1230 reportMatchFailures = savedReportMatchFailures;
|
|
1231 if (reportMatchFailures && result0 === null) {
|
|
1232 matchFailed("action");
|
|
1233 }
|
|
1234
|
|
1235 cache[cacheKey] = {
|
|
1236 nextPos: pos,
|
|
1237 result: result0
|
|
1238 };
|
|
1239 return result0;
|
|
1240 }
|
|
1241
|
|
1242 function parse_braced() {
|
|
1243 var cacheKey = 'braced@' + pos;
|
|
1244 var cachedResult = cache[cacheKey];
|
|
1245 if (cachedResult) {
|
|
1246 pos = cachedResult.nextPos;
|
|
1247 return cachedResult.result;
|
|
1248 }
|
|
1249
|
|
1250
|
|
1251 var savedPos0 = pos;
|
|
1252 var savedPos1 = pos;
|
|
1253 if (input.substr(pos, 1) === "{") {
|
|
1254 var result3 = "{";
|
|
1255 pos += 1;
|
|
1256 } else {
|
|
1257 var result3 = null;
|
|
1258 if (reportMatchFailures) {
|
|
1259 matchFailed("\"{\"");
|
|
1260 }
|
|
1261 }
|
|
1262 if (result3 !== null) {
|
|
1263 var result4 = [];
|
|
1264 var result8 = parse_braced();
|
|
1265 if (result8 !== null) {
|
|
1266 var result6 = result8;
|
|
1267 } else {
|
|
1268 var result7 = parse_nonBraceCharacter();
|
|
1269 if (result7 !== null) {
|
|
1270 var result6 = result7;
|
|
1271 } else {
|
|
1272 var result6 = null;;
|
|
1273 };
|
|
1274 }
|
|
1275 while (result6 !== null) {
|
|
1276 result4.push(result6);
|
|
1277 var result8 = parse_braced();
|
|
1278 if (result8 !== null) {
|
|
1279 var result6 = result8;
|
|
1280 } else {
|
|
1281 var result7 = parse_nonBraceCharacter();
|
|
1282 if (result7 !== null) {
|
|
1283 var result6 = result7;
|
|
1284 } else {
|
|
1285 var result6 = null;;
|
|
1286 };
|
|
1287 }
|
|
1288 }
|
|
1289 if (result4 !== null) {
|
|
1290 if (input.substr(pos, 1) === "}") {
|
|
1291 var result5 = "}";
|
|
1292 pos += 1;
|
|
1293 } else {
|
|
1294 var result5 = null;
|
|
1295 if (reportMatchFailures) {
|
|
1296 matchFailed("\"}\"");
|
|
1297 }
|
|
1298 }
|
|
1299 if (result5 !== null) {
|
|
1300 var result1 = [result3, result4, result5];
|
|
1301 } else {
|
|
1302 var result1 = null;
|
|
1303 pos = savedPos1;
|
|
1304 }
|
|
1305 } else {
|
|
1306 var result1 = null;
|
|
1307 pos = savedPos1;
|
|
1308 }
|
|
1309 } else {
|
|
1310 var result1 = null;
|
|
1311 pos = savedPos1;
|
|
1312 }
|
|
1313 var result2 = result1 !== null
|
|
1314 ? (function(parts) {
|
|
1315 return "{" + parts.join("") + "}";
|
|
1316 })(result1[1])
|
|
1317 : null;
|
|
1318 if (result2 !== null) {
|
|
1319 var result0 = result2;
|
|
1320 } else {
|
|
1321 var result0 = null;
|
|
1322 pos = savedPos0;
|
|
1323 }
|
|
1324
|
|
1325
|
|
1326
|
|
1327 cache[cacheKey] = {
|
|
1328 nextPos: pos,
|
|
1329 result: result0
|
|
1330 };
|
|
1331 return result0;
|
|
1332 }
|
|
1333
|
|
1334 function parse_nonBraceCharacters() {
|
|
1335 var cacheKey = 'nonBraceCharacters@' + pos;
|
|
1336 var cachedResult = cache[cacheKey];
|
|
1337 if (cachedResult) {
|
|
1338 pos = cachedResult.nextPos;
|
|
1339 return cachedResult.result;
|
|
1340 }
|
|
1341
|
|
1342
|
|
1343 var savedPos0 = pos;
|
|
1344 var result3 = parse_nonBraceCharacter();
|
|
1345 if (result3 !== null) {
|
|
1346 var result1 = [];
|
|
1347 while (result3 !== null) {
|
|
1348 result1.push(result3);
|
|
1349 var result3 = parse_nonBraceCharacter();
|
|
1350 }
|
|
1351 } else {
|
|
1352 var result1 = null;
|
|
1353 }
|
|
1354 var result2 = result1 !== null
|
|
1355 ? (function(chars) { return chars.join(""); })(result1)
|
|
1356 : null;
|
|
1357 if (result2 !== null) {
|
|
1358 var result0 = result2;
|
|
1359 } else {
|
|
1360 var result0 = null;
|
|
1361 pos = savedPos0;
|
|
1362 }
|
|
1363
|
|
1364
|
|
1365
|
|
1366 cache[cacheKey] = {
|
|
1367 nextPos: pos,
|
|
1368 result: result0
|
|
1369 };
|
|
1370 return result0;
|
|
1371 }
|
|
1372
|
|
1373 function parse_nonBraceCharacter() {
|
|
1374 var cacheKey = 'nonBraceCharacter@' + pos;
|
|
1375 var cachedResult = cache[cacheKey];
|
|
1376 if (cachedResult) {
|
|
1377 pos = cachedResult.nextPos;
|
|
1378 return cachedResult.result;
|
|
1379 }
|
|
1380
|
|
1381
|
|
1382 if (input.substr(pos).match(/^[^{}]/) !== null) {
|
|
1383 var result0 = input.charAt(pos);
|
|
1384 pos++;
|
|
1385 } else {
|
|
1386 var result0 = null;
|
|
1387 if (reportMatchFailures) {
|
|
1388 matchFailed("[^{}]");
|
|
1389 }
|
|
1390 }
|
|
1391
|
|
1392
|
|
1393
|
|
1394 cache[cacheKey] = {
|
|
1395 nextPos: pos,
|
|
1396 result: result0
|
|
1397 };
|
|
1398 return result0;
|
|
1399 }
|
|
1400
|
|
1401 function parse_equals() {
|
|
1402 var cacheKey = 'equals@' + pos;
|
|
1403 var cachedResult = cache[cacheKey];
|
|
1404 if (cachedResult) {
|
|
1405 pos = cachedResult.nextPos;
|
|
1406 return cachedResult.result;
|
|
1407 }
|
|
1408
|
|
1409
|
|
1410 var savedPos0 = pos;
|
|
1411 var savedPos1 = pos;
|
|
1412 if (input.substr(pos, 1) === "=") {
|
|
1413 var result3 = "=";
|
|
1414 pos += 1;
|
|
1415 } else {
|
|
1416 var result3 = null;
|
|
1417 if (reportMatchFailures) {
|
|
1418 matchFailed("\"=\"");
|
|
1419 }
|
|
1420 }
|
|
1421 if (result3 !== null) {
|
|
1422 var result4 = parse___();
|
|
1423 if (result4 !== null) {
|
|
1424 var result1 = [result3, result4];
|
|
1425 } else {
|
|
1426 var result1 = null;
|
|
1427 pos = savedPos1;
|
|
1428 }
|
|
1429 } else {
|
|
1430 var result1 = null;
|
|
1431 pos = savedPos1;
|
|
1432 }
|
|
1433 var result2 = result1 !== null
|
|
1434 ? (function() { return "="; })()
|
|
1435 : null;
|
|
1436 if (result2 !== null) {
|
|
1437 var result0 = result2;
|
|
1438 } else {
|
|
1439 var result0 = null;
|
|
1440 pos = savedPos0;
|
|
1441 }
|
|
1442
|
|
1443
|
|
1444
|
|
1445 cache[cacheKey] = {
|
|
1446 nextPos: pos,
|
|
1447 result: result0
|
|
1448 };
|
|
1449 return result0;
|
|
1450 }
|
|
1451
|
|
1452 function parse_colon() {
|
|
1453 var cacheKey = 'colon@' + pos;
|
|
1454 var cachedResult = cache[cacheKey];
|
|
1455 if (cachedResult) {
|
|
1456 pos = cachedResult.nextPos;
|
|
1457 return cachedResult.result;
|
|
1458 }
|
|
1459
|
|
1460
|
|
1461 var savedPos0 = pos;
|
|
1462 var savedPos1 = pos;
|
|
1463 if (input.substr(pos, 1) === ":") {
|
|
1464 var result3 = ":";
|
|
1465 pos += 1;
|
|
1466 } else {
|
|
1467 var result3 = null;
|
|
1468 if (reportMatchFailures) {
|
|
1469 matchFailed("\":\"");
|
|
1470 }
|
|
1471 }
|
|
1472 if (result3 !== null) {
|
|
1473 var result4 = parse___();
|
|
1474 if (result4 !== null) {
|
|
1475 var result1 = [result3, result4];
|
|
1476 } else {
|
|
1477 var result1 = null;
|
|
1478 pos = savedPos1;
|
|
1479 }
|
|
1480 } else {
|
|
1481 var result1 = null;
|
|
1482 pos = savedPos1;
|
|
1483 }
|
|
1484 var result2 = result1 !== null
|
|
1485 ? (function() { return ":"; })()
|
|
1486 : null;
|
|
1487 if (result2 !== null) {
|
|
1488 var result0 = result2;
|
|
1489 } else {
|
|
1490 var result0 = null;
|
|
1491 pos = savedPos0;
|
|
1492 }
|
|
1493
|
|
1494
|
|
1495
|
|
1496 cache[cacheKey] = {
|
|
1497 nextPos: pos,
|
|
1498 result: result0
|
|
1499 };
|
|
1500 return result0;
|
|
1501 }
|
|
1502
|
|
1503 function parse_semicolon() {
|
|
1504 var cacheKey = 'semicolon@' + pos;
|
|
1505 var cachedResult = cache[cacheKey];
|
|
1506 if (cachedResult) {
|
|
1507 pos = cachedResult.nextPos;
|
|
1508 return cachedResult.result;
|
|
1509 }
|
|
1510
|
|
1511
|
|
1512 var savedPos0 = pos;
|
|
1513 var savedPos1 = pos;
|
|
1514 if (input.substr(pos, 1) === ";") {
|
|
1515 var result3 = ";";
|
|
1516 pos += 1;
|
|
1517 } else {
|
|
1518 var result3 = null;
|
|
1519 if (reportMatchFailures) {
|
|
1520 matchFailed("\";\"");
|
|
1521 }
|
|
1522 }
|
|
1523 if (result3 !== null) {
|
|
1524 var result4 = parse___();
|
|
1525 if (result4 !== null) {
|
|
1526 var result1 = [result3, result4];
|
|
1527 } else {
|
|
1528 var result1 = null;
|
|
1529 pos = savedPos1;
|
|
1530 }
|
|
1531 } else {
|
|
1532 var result1 = null;
|
|
1533 pos = savedPos1;
|
|
1534 }
|
|
1535 var result2 = result1 !== null
|
|
1536 ? (function() { return ";"; })()
|
|
1537 : null;
|
|
1538 if (result2 !== null) {
|
|
1539 var result0 = result2;
|
|
1540 } else {
|
|
1541 var result0 = null;
|
|
1542 pos = savedPos0;
|
|
1543 }
|
|
1544
|
|
1545
|
|
1546
|
|
1547 cache[cacheKey] = {
|
|
1548 nextPos: pos,
|
|
1549 result: result0
|
|
1550 };
|
|
1551 return result0;
|
|
1552 }
|
|
1553
|
|
1554 function parse_slash() {
|
|
1555 var cacheKey = 'slash@' + pos;
|
|
1556 var cachedResult = cache[cacheKey];
|
|
1557 if (cachedResult) {
|
|
1558 pos = cachedResult.nextPos;
|
|
1559 return cachedResult.result;
|
|
1560 }
|
|
1561
|
|
1562
|
|
1563 var savedPos0 = pos;
|
|
1564 var savedPos1 = pos;
|
|
1565 if (input.substr(pos, 1) === "/") {
|
|
1566 var result3 = "/";
|
|
1567 pos += 1;
|
|
1568 } else {
|
|
1569 var result3 = null;
|
|
1570 if (reportMatchFailures) {
|
|
1571 matchFailed("\"/\"");
|
|
1572 }
|
|
1573 }
|
|
1574 if (result3 !== null) {
|
|
1575 var result4 = parse___();
|
|
1576 if (result4 !== null) {
|
|
1577 var result1 = [result3, result4];
|
|
1578 } else {
|
|
1579 var result1 = null;
|
|
1580 pos = savedPos1;
|
|
1581 }
|
|
1582 } else {
|
|
1583 var result1 = null;
|
|
1584 pos = savedPos1;
|
|
1585 }
|
|
1586 var result2 = result1 !== null
|
|
1587 ? (function() { return "/"; })()
|
|
1588 : null;
|
|
1589 if (result2 !== null) {
|
|
1590 var result0 = result2;
|
|
1591 } else {
|
|
1592 var result0 = null;
|
|
1593 pos = savedPos0;
|
|
1594 }
|
|
1595
|
|
1596
|
|
1597
|
|
1598 cache[cacheKey] = {
|
|
1599 nextPos: pos,
|
|
1600 result: result0
|
|
1601 };
|
|
1602 return result0;
|
|
1603 }
|
|
1604
|
|
1605 function parse_and() {
|
|
1606 var cacheKey = 'and@' + pos;
|
|
1607 var cachedResult = cache[cacheKey];
|
|
1608 if (cachedResult) {
|
|
1609 pos = cachedResult.nextPos;
|
|
1610 return cachedResult.result;
|
|
1611 }
|
|
1612
|
|
1613
|
|
1614 var savedPos0 = pos;
|
|
1615 var savedPos1 = pos;
|
|
1616 if (input.substr(pos, 1) === "&") {
|
|
1617 var result3 = "&";
|
|
1618 pos += 1;
|
|
1619 } else {
|
|
1620 var result3 = null;
|
|
1621 if (reportMatchFailures) {
|
|
1622 matchFailed("\"&\"");
|
|
1623 }
|
|
1624 }
|
|
1625 if (result3 !== null) {
|
|
1626 var result4 = parse___();
|
|
1627 if (result4 !== null) {
|
|
1628 var result1 = [result3, result4];
|
|
1629 } else {
|
|
1630 var result1 = null;
|
|
1631 pos = savedPos1;
|
|
1632 }
|
|
1633 } else {
|
|
1634 var result1 = null;
|
|
1635 pos = savedPos1;
|
|
1636 }
|
|
1637 var result2 = result1 !== null
|
|
1638 ? (function() { return "&"; })()
|
|
1639 : null;
|
|
1640 if (result2 !== null) {
|
|
1641 var result0 = result2;
|
|
1642 } else {
|
|
1643 var result0 = null;
|
|
1644 pos = savedPos0;
|
|
1645 }
|
|
1646
|
|
1647
|
|
1648
|
|
1649 cache[cacheKey] = {
|
|
1650 nextPos: pos,
|
|
1651 result: result0
|
|
1652 };
|
|
1653 return result0;
|
|
1654 }
|
|
1655
|
|
1656 function parse_not() {
|
|
1657 var cacheKey = 'not@' + pos;
|
|
1658 var cachedResult = cache[cacheKey];
|
|
1659 if (cachedResult) {
|
|
1660 pos = cachedResult.nextPos;
|
|
1661 return cachedResult.result;
|
|
1662 }
|
|
1663
|
|
1664
|
|
1665 var savedPos0 = pos;
|
|
1666 var savedPos1 = pos;
|
|
1667 if (input.substr(pos, 1) === "!") {
|
|
1668 var result3 = "!";
|
|
1669 pos += 1;
|
|
1670 } else {
|
|
1671 var result3 = null;
|
|
1672 if (reportMatchFailures) {
|
|
1673 matchFailed("\"!\"");
|
|
1674 }
|
|
1675 }
|
|
1676 if (result3 !== null) {
|
|
1677 var result4 = parse___();
|
|
1678 if (result4 !== null) {
|
|
1679 var result1 = [result3, result4];
|
|
1680 } else {
|
|
1681 var result1 = null;
|
|
1682 pos = savedPos1;
|
|
1683 }
|
|
1684 } else {
|
|
1685 var result1 = null;
|
|
1686 pos = savedPos1;
|
|
1687 }
|
|
1688 var result2 = result1 !== null
|
|
1689 ? (function() { return "!"; })()
|
|
1690 : null;
|
|
1691 if (result2 !== null) {
|
|
1692 var result0 = result2;
|
|
1693 } else {
|
|
1694 var result0 = null;
|
|
1695 pos = savedPos0;
|
|
1696 }
|
|
1697
|
|
1698
|
|
1699
|
|
1700 cache[cacheKey] = {
|
|
1701 nextPos: pos,
|
|
1702 result: result0
|
|
1703 };
|
|
1704 return result0;
|
|
1705 }
|
|
1706
|
|
1707 function parse_question() {
|
|
1708 var cacheKey = 'question@' + pos;
|
|
1709 var cachedResult = cache[cacheKey];
|
|
1710 if (cachedResult) {
|
|
1711 pos = cachedResult.nextPos;
|
|
1712 return cachedResult.result;
|
|
1713 }
|
|
1714
|
|
1715
|
|
1716 var savedPos0 = pos;
|
|
1717 var savedPos1 = pos;
|
|
1718 if (input.substr(pos, 1) === "?") {
|
|
1719 var result3 = "?";
|
|
1720 pos += 1;
|
|
1721 } else {
|
|
1722 var result3 = null;
|
|
1723 if (reportMatchFailures) {
|
|
1724 matchFailed("\"?\"");
|
|
1725 }
|
|
1726 }
|
|
1727 if (result3 !== null) {
|
|
1728 var result4 = parse___();
|
|
1729 if (result4 !== null) {
|
|
1730 var result1 = [result3, result4];
|
|
1731 } else {
|
|
1732 var result1 = null;
|
|
1733 pos = savedPos1;
|
|
1734 }
|
|
1735 } else {
|
|
1736 var result1 = null;
|
|
1737 pos = savedPos1;
|
|
1738 }
|
|
1739 var result2 = result1 !== null
|
|
1740 ? (function() { return "?"; })()
|
|
1741 : null;
|
|
1742 if (result2 !== null) {
|
|
1743 var result0 = result2;
|
|
1744 } else {
|
|
1745 var result0 = null;
|
|
1746 pos = savedPos0;
|
|
1747 }
|
|
1748
|
|
1749
|
|
1750
|
|
1751 cache[cacheKey] = {
|
|
1752 nextPos: pos,
|
|
1753 result: result0
|
|
1754 };
|
|
1755 return result0;
|
|
1756 }
|
|
1757
|
|
1758 function parse_star() {
|
|
1759 var cacheKey = 'star@' + pos;
|
|
1760 var cachedResult = cache[cacheKey];
|
|
1761 if (cachedResult) {
|
|
1762 pos = cachedResult.nextPos;
|
|
1763 return cachedResult.result;
|
|
1764 }
|
|
1765
|
|
1766
|
|
1767 var savedPos0 = pos;
|
|
1768 var savedPos1 = pos;
|
|
1769 if (input.substr(pos, 1) === "*") {
|
|
1770 var result3 = "*";
|
|
1771 pos += 1;
|
|
1772 } else {
|
|
1773 var result3 = null;
|
|
1774 if (reportMatchFailures) {
|
|
1775 matchFailed("\"*\"");
|
|
1776 }
|
|
1777 }
|
|
1778 if (result3 !== null) {
|
|
1779 var result4 = parse___();
|
|
1780 if (result4 !== null) {
|
|
1781 var result1 = [result3, result4];
|
|
1782 } else {
|
|
1783 var result1 = null;
|
|
1784 pos = savedPos1;
|
|
1785 }
|
|
1786 } else {
|
|
1787 var result1 = null;
|
|
1788 pos = savedPos1;
|
|
1789 }
|
|
1790 var result2 = result1 !== null
|
|
1791 ? (function() { return "*"; })()
|
|
1792 : null;
|
|
1793 if (result2 !== null) {
|
|
1794 var result0 = result2;
|
|
1795 } else {
|
|
1796 var result0 = null;
|
|
1797 pos = savedPos0;
|
|
1798 }
|
|
1799
|
|
1800
|
|
1801
|
|
1802 cache[cacheKey] = {
|
|
1803 nextPos: pos,
|
|
1804 result: result0
|
|
1805 };
|
|
1806 return result0;
|
|
1807 }
|
|
1808
|
|
1809 function parse_plus() {
|
|
1810 var cacheKey = 'plus@' + pos;
|
|
1811 var cachedResult = cache[cacheKey];
|
|
1812 if (cachedResult) {
|
|
1813 pos = cachedResult.nextPos;
|
|
1814 return cachedResult.result;
|
|
1815 }
|
|
1816
|
|
1817
|
|
1818 var savedPos0 = pos;
|
|
1819 var savedPos1 = pos;
|
|
1820 if (input.substr(pos, 1) === "+") {
|
|
1821 var result3 = "+";
|
|
1822 pos += 1;
|
|
1823 } else {
|
|
1824 var result3 = null;
|
|
1825 if (reportMatchFailures) {
|
|
1826 matchFailed("\"+\"");
|
|
1827 }
|
|
1828 }
|
|
1829 if (result3 !== null) {
|
|
1830 var result4 = parse___();
|
|
1831 if (result4 !== null) {
|
|
1832 var result1 = [result3, result4];
|
|
1833 } else {
|
|
1834 var result1 = null;
|
|
1835 pos = savedPos1;
|
|
1836 }
|
|
1837 } else {
|
|
1838 var result1 = null;
|
|
1839 pos = savedPos1;
|
|
1840 }
|
|
1841 var result2 = result1 !== null
|
|
1842 ? (function() { return "+"; })()
|
|
1843 : null;
|
|
1844 if (result2 !== null) {
|
|
1845 var result0 = result2;
|
|
1846 } else {
|
|
1847 var result0 = null;
|
|
1848 pos = savedPos0;
|
|
1849 }
|
|
1850
|
|
1851
|
|
1852
|
|
1853 cache[cacheKey] = {
|
|
1854 nextPos: pos,
|
|
1855 result: result0
|
|
1856 };
|
|
1857 return result0;
|
|
1858 }
|
|
1859
|
|
1860 function parse_lparen() {
|
|
1861 var cacheKey = 'lparen@' + pos;
|
|
1862 var cachedResult = cache[cacheKey];
|
|
1863 if (cachedResult) {
|
|
1864 pos = cachedResult.nextPos;
|
|
1865 return cachedResult.result;
|
|
1866 }
|
|
1867
|
|
1868
|
|
1869 var savedPos0 = pos;
|
|
1870 var savedPos1 = pos;
|
|
1871 if (input.substr(pos, 1) === "(") {
|
|
1872 var result3 = "(";
|
|
1873 pos += 1;
|
|
1874 } else {
|
|
1875 var result3 = null;
|
|
1876 if (reportMatchFailures) {
|
|
1877 matchFailed("\"(\"");
|
|
1878 }
|
|
1879 }
|
|
1880 if (result3 !== null) {
|
|
1881 var result4 = parse___();
|
|
1882 if (result4 !== null) {
|
|
1883 var result1 = [result3, result4];
|
|
1884 } else {
|
|
1885 var result1 = null;
|
|
1886 pos = savedPos1;
|
|
1887 }
|
|
1888 } else {
|
|
1889 var result1 = null;
|
|
1890 pos = savedPos1;
|
|
1891 }
|
|
1892 var result2 = result1 !== null
|
|
1893 ? (function() { return "("; })()
|
|
1894 : null;
|
|
1895 if (result2 !== null) {
|
|
1896 var result0 = result2;
|
|
1897 } else {
|
|
1898 var result0 = null;
|
|
1899 pos = savedPos0;
|
|
1900 }
|
|
1901
|
|
1902
|
|
1903
|
|
1904 cache[cacheKey] = {
|
|
1905 nextPos: pos,
|
|
1906 result: result0
|
|
1907 };
|
|
1908 return result0;
|
|
1909 }
|
|
1910
|
|
1911 function parse_rparen() {
|
|
1912 var cacheKey = 'rparen@' + pos;
|
|
1913 var cachedResult = cache[cacheKey];
|
|
1914 if (cachedResult) {
|
|
1915 pos = cachedResult.nextPos;
|
|
1916 return cachedResult.result;
|
|
1917 }
|
|
1918
|
|
1919
|
|
1920 var savedPos0 = pos;
|
|
1921 var savedPos1 = pos;
|
|
1922 if (input.substr(pos, 1) === ")") {
|
|
1923 var result3 = ")";
|
|
1924 pos += 1;
|
|
1925 } else {
|
|
1926 var result3 = null;
|
|
1927 if (reportMatchFailures) {
|
|
1928 matchFailed("\")\"");
|
|
1929 }
|
|
1930 }
|
|
1931 if (result3 !== null) {
|
|
1932 var result4 = parse___();
|
|
1933 if (result4 !== null) {
|
|
1934 var result1 = [result3, result4];
|
|
1935 } else {
|
|
1936 var result1 = null;
|
|
1937 pos = savedPos1;
|
|
1938 }
|
|
1939 } else {
|
|
1940 var result1 = null;
|
|
1941 pos = savedPos1;
|
|
1942 }
|
|
1943 var result2 = result1 !== null
|
|
1944 ? (function() { return ")"; })()
|
|
1945 : null;
|
|
1946 if (result2 !== null) {
|
|
1947 var result0 = result2;
|
|
1948 } else {
|
|
1949 var result0 = null;
|
|
1950 pos = savedPos0;
|
|
1951 }
|
|
1952
|
|
1953
|
|
1954
|
|
1955 cache[cacheKey] = {
|
|
1956 nextPos: pos,
|
|
1957 result: result0
|
|
1958 };
|
|
1959 return result0;
|
|
1960 }
|
|
1961
|
|
1962 function parse_dot() {
|
|
1963 var cacheKey = 'dot@' + pos;
|
|
1964 var cachedResult = cache[cacheKey];
|
|
1965 if (cachedResult) {
|
|
1966 pos = cachedResult.nextPos;
|
|
1967 return cachedResult.result;
|
|
1968 }
|
|
1969
|
|
1970
|
|
1971 var savedPos0 = pos;
|
|
1972 var savedPos1 = pos;
|
|
1973 if (input.substr(pos, 1) === ".") {
|
|
1974 var result3 = ".";
|
|
1975 pos += 1;
|
|
1976 } else {
|
|
1977 var result3 = null;
|
|
1978 if (reportMatchFailures) {
|
|
1979 matchFailed("\".\"");
|
|
1980 }
|
|
1981 }
|
|
1982 if (result3 !== null) {
|
|
1983 var result4 = parse___();
|
|
1984 if (result4 !== null) {
|
|
1985 var result1 = [result3, result4];
|
|
1986 } else {
|
|
1987 var result1 = null;
|
|
1988 pos = savedPos1;
|
|
1989 }
|
|
1990 } else {
|
|
1991 var result1 = null;
|
|
1992 pos = savedPos1;
|
|
1993 }
|
|
1994 var result2 = result1 !== null
|
|
1995 ? (function() { return "."; })()
|
|
1996 : null;
|
|
1997 if (result2 !== null) {
|
|
1998 var result0 = result2;
|
|
1999 } else {
|
|
2000 var result0 = null;
|
|
2001 pos = savedPos0;
|
|
2002 }
|
|
2003
|
|
2004
|
|
2005
|
|
2006 cache[cacheKey] = {
|
|
2007 nextPos: pos,
|
|
2008 result: result0
|
|
2009 };
|
|
2010 return result0;
|
|
2011 }
|
|
2012
|
|
2013 function parse_identifier() {
|
|
2014 var cacheKey = 'identifier@' + pos;
|
|
2015 var cachedResult = cache[cacheKey];
|
|
2016 if (cachedResult) {
|
|
2017 pos = cachedResult.nextPos;
|
|
2018 return cachedResult.result;
|
|
2019 }
|
|
2020
|
|
2021 var savedReportMatchFailures = reportMatchFailures;
|
|
2022 reportMatchFailures = false;
|
|
2023 var savedPos0 = pos;
|
|
2024 var savedPos1 = pos;
|
|
2025 var result13 = parse_letter();
|
|
2026 if (result13 !== null) {
|
|
2027 var result3 = result13;
|
|
2028 } else {
|
|
2029 if (input.substr(pos, 1) === "_") {
|
|
2030 var result12 = "_";
|
|
2031 pos += 1;
|
|
2032 } else {
|
|
2033 var result12 = null;
|
|
2034 if (reportMatchFailures) {
|
|
2035 matchFailed("\"_\"");
|
|
2036 }
|
|
2037 }
|
|
2038 if (result12 !== null) {
|
|
2039 var result3 = result12;
|
|
2040 } else {
|
|
2041 if (input.substr(pos, 1) === "$") {
|
|
2042 var result11 = "$";
|
|
2043 pos += 1;
|
|
2044 } else {
|
|
2045 var result11 = null;
|
|
2046 if (reportMatchFailures) {
|
|
2047 matchFailed("\"$\"");
|
|
2048 }
|
|
2049 }
|
|
2050 if (result11 !== null) {
|
|
2051 var result3 = result11;
|
|
2052 } else {
|
|
2053 var result3 = null;;
|
|
2054 };
|
|
2055 };
|
|
2056 }
|
|
2057 if (result3 !== null) {
|
|
2058 var result4 = [];
|
|
2059 var result10 = parse_letter();
|
|
2060 if (result10 !== null) {
|
|
2061 var result6 = result10;
|
|
2062 } else {
|
|
2063 var result9 = parse_digit();
|
|
2064 if (result9 !== null) {
|
|
2065 var result6 = result9;
|
|
2066 } else {
|
|
2067 if (input.substr(pos, 1) === "_") {
|
|
2068 var result8 = "_";
|
|
2069 pos += 1;
|
|
2070 } else {
|
|
2071 var result8 = null;
|
|
2072 if (reportMatchFailures) {
|
|
2073 matchFailed("\"_\"");
|
|
2074 }
|
|
2075 }
|
|
2076 if (result8 !== null) {
|
|
2077 var result6 = result8;
|
|
2078 } else {
|
|
2079 if (input.substr(pos, 1) === "$") {
|
|
2080 var result7 = "$";
|
|
2081 pos += 1;
|
|
2082 } else {
|
|
2083 var result7 = null;
|
|
2084 if (reportMatchFailures) {
|
|
2085 matchFailed("\"$\"");
|
|
2086 }
|
|
2087 }
|
|
2088 if (result7 !== null) {
|
|
2089 var result6 = result7;
|
|
2090 } else {
|
|
2091 var result6 = null;;
|
|
2092 };
|
|
2093 };
|
|
2094 };
|
|
2095 }
|
|
2096 while (result6 !== null) {
|
|
2097 result4.push(result6);
|
|
2098 var result10 = parse_letter();
|
|
2099 if (result10 !== null) {
|
|
2100 var result6 = result10;
|
|
2101 } else {
|
|
2102 var result9 = parse_digit();
|
|
2103 if (result9 !== null) {
|
|
2104 var result6 = result9;
|
|
2105 } else {
|
|
2106 if (input.substr(pos, 1) === "_") {
|
|
2107 var result8 = "_";
|
|
2108 pos += 1;
|
|
2109 } else {
|
|
2110 var result8 = null;
|
|
2111 if (reportMatchFailures) {
|
|
2112 matchFailed("\"_\"");
|
|
2113 }
|
|
2114 }
|
|
2115 if (result8 !== null) {
|
|
2116 var result6 = result8;
|
|
2117 } else {
|
|
2118 if (input.substr(pos, 1) === "$") {
|
|
2119 var result7 = "$";
|
|
2120 pos += 1;
|
|
2121 } else {
|
|
2122 var result7 = null;
|
|
2123 if (reportMatchFailures) {
|
|
2124 matchFailed("\"$\"");
|
|
2125 }
|
|
2126 }
|
|
2127 if (result7 !== null) {
|
|
2128 var result6 = result7;
|
|
2129 } else {
|
|
2130 var result6 = null;;
|
|
2131 };
|
|
2132 };
|
|
2133 };
|
|
2134 }
|
|
2135 }
|
|
2136 if (result4 !== null) {
|
|
2137 var result5 = parse___();
|
|
2138 if (result5 !== null) {
|
|
2139 var result1 = [result3, result4, result5];
|
|
2140 } else {
|
|
2141 var result1 = null;
|
|
2142 pos = savedPos1;
|
|
2143 }
|
|
2144 } else {
|
|
2145 var result1 = null;
|
|
2146 pos = savedPos1;
|
|
2147 }
|
|
2148 } else {
|
|
2149 var result1 = null;
|
|
2150 pos = savedPos1;
|
|
2151 }
|
|
2152 var result2 = result1 !== null
|
|
2153 ? (function(head, tail) {
|
|
2154 return head + tail.join("");
|
|
2155 })(result1[0], result1[1])
|
|
2156 : null;
|
|
2157 if (result2 !== null) {
|
|
2158 var result0 = result2;
|
|
2159 } else {
|
|
2160 var result0 = null;
|
|
2161 pos = savedPos0;
|
|
2162 }
|
|
2163 reportMatchFailures = savedReportMatchFailures;
|
|
2164 if (reportMatchFailures && result0 === null) {
|
|
2165 matchFailed("identifier");
|
|
2166 }
|
|
2167
|
|
2168 cache[cacheKey] = {
|
|
2169 nextPos: pos,
|
|
2170 result: result0
|
|
2171 };
|
|
2172 return result0;
|
|
2173 }
|
|
2174
|
|
2175 function parse_literal() {
|
|
2176 var cacheKey = 'literal@' + pos;
|
|
2177 var cachedResult = cache[cacheKey];
|
|
2178 if (cachedResult) {
|
|
2179 pos = cachedResult.nextPos;
|
|
2180 return cachedResult.result;
|
|
2181 }
|
|
2182
|
|
2183 var savedReportMatchFailures = reportMatchFailures;
|
|
2184 reportMatchFailures = false;
|
|
2185 var savedPos0 = pos;
|
|
2186 var savedPos1 = pos;
|
|
2187 var result6 = parse_doubleQuotedLiteral();
|
|
2188 if (result6 !== null) {
|
|
2189 var result3 = result6;
|
|
2190 } else {
|
|
2191 var result5 = parse_singleQuotedLiteral();
|
|
2192 if (result5 !== null) {
|
|
2193 var result3 = result5;
|
|
2194 } else {
|
|
2195 var result3 = null;;
|
|
2196 };
|
|
2197 }
|
|
2198 if (result3 !== null) {
|
|
2199 var result4 = parse___();
|
|
2200 if (result4 !== null) {
|
|
2201 var result1 = [result3, result4];
|
|
2202 } else {
|
|
2203 var result1 = null;
|
|
2204 pos = savedPos1;
|
|
2205 }
|
|
2206 } else {
|
|
2207 var result1 = null;
|
|
2208 pos = savedPos1;
|
|
2209 }
|
|
2210 var result2 = result1 !== null
|
|
2211 ? (function(literal) { return literal; })(result1[0])
|
|
2212 : null;
|
|
2213 if (result2 !== null) {
|
|
2214 var result0 = result2;
|
|
2215 } else {
|
|
2216 var result0 = null;
|
|
2217 pos = savedPos0;
|
|
2218 }
|
|
2219 reportMatchFailures = savedReportMatchFailures;
|
|
2220 if (reportMatchFailures && result0 === null) {
|
|
2221 matchFailed("literal");
|
|
2222 }
|
|
2223
|
|
2224 cache[cacheKey] = {
|
|
2225 nextPos: pos,
|
|
2226 result: result0
|
|
2227 };
|
|
2228 return result0;
|
|
2229 }
|
|
2230
|
|
2231 function parse_doubleQuotedLiteral() {
|
|
2232 var cacheKey = 'doubleQuotedLiteral@' + pos;
|
|
2233 var cachedResult = cache[cacheKey];
|
|
2234 if (cachedResult) {
|
|
2235 pos = cachedResult.nextPos;
|
|
2236 return cachedResult.result;
|
|
2237 }
|
|
2238
|
|
2239
|
|
2240 var savedPos0 = pos;
|
|
2241 var savedPos1 = pos;
|
|
2242 if (input.substr(pos, 1) === "\"") {
|
|
2243 var result3 = "\"";
|
|
2244 pos += 1;
|
|
2245 } else {
|
|
2246 var result3 = null;
|
|
2247 if (reportMatchFailures) {
|
|
2248 matchFailed("\"\\\"\"");
|
|
2249 }
|
|
2250 }
|
|
2251 if (result3 !== null) {
|
|
2252 var result4 = [];
|
|
2253 var result6 = parse_doubleQuotedCharacter();
|
|
2254 while (result6 !== null) {
|
|
2255 result4.push(result6);
|
|
2256 var result6 = parse_doubleQuotedCharacter();
|
|
2257 }
|
|
2258 if (result4 !== null) {
|
|
2259 if (input.substr(pos, 1) === "\"") {
|
|
2260 var result5 = "\"";
|
|
2261 pos += 1;
|
|
2262 } else {
|
|
2263 var result5 = null;
|
|
2264 if (reportMatchFailures) {
|
|
2265 matchFailed("\"\\\"\"");
|
|
2266 }
|
|
2267 }
|
|
2268 if (result5 !== null) {
|
|
2269 var result1 = [result3, result4, result5];
|
|
2270 } else {
|
|
2271 var result1 = null;
|
|
2272 pos = savedPos1;
|
|
2273 }
|
|
2274 } else {
|
|
2275 var result1 = null;
|
|
2276 pos = savedPos1;
|
|
2277 }
|
|
2278 } else {
|
|
2279 var result1 = null;
|
|
2280 pos = savedPos1;
|
|
2281 }
|
|
2282 var result2 = result1 !== null
|
|
2283 ? (function(chars) { return chars.join(""); })(result1[1])
|
|
2284 : null;
|
|
2285 if (result2 !== null) {
|
|
2286 var result0 = result2;
|
|
2287 } else {
|
|
2288 var result0 = null;
|
|
2289 pos = savedPos0;
|
|
2290 }
|
|
2291
|
|
2292
|
|
2293
|
|
2294 cache[cacheKey] = {
|
|
2295 nextPos: pos,
|
|
2296 result: result0
|
|
2297 };
|
|
2298 return result0;
|
|
2299 }
|
|
2300
|
|
2301 function parse_doubleQuotedCharacter() {
|
|
2302 var cacheKey = 'doubleQuotedCharacter@' + pos;
|
|
2303 var cachedResult = cache[cacheKey];
|
|
2304 if (cachedResult) {
|
|
2305 pos = cachedResult.nextPos;
|
|
2306 return cachedResult.result;
|
|
2307 }
|
|
2308
|
|
2309
|
|
2310 var result6 = parse_simpleDoubleQuotedCharacter();
|
|
2311 if (result6 !== null) {
|
|
2312 var result0 = result6;
|
|
2313 } else {
|
|
2314 var result5 = parse_simpleEscapeSequence();
|
|
2315 if (result5 !== null) {
|
|
2316 var result0 = result5;
|
|
2317 } else {
|
|
2318 var result4 = parse_zeroEscapeSequence();
|
|
2319 if (result4 !== null) {
|
|
2320 var result0 = result4;
|
|
2321 } else {
|
|
2322 var result3 = parse_hexEscapeSequence();
|
|
2323 if (result3 !== null) {
|
|
2324 var result0 = result3;
|
|
2325 } else {
|
|
2326 var result2 = parse_unicodeEscapeSequence();
|
|
2327 if (result2 !== null) {
|
|
2328 var result0 = result2;
|
|
2329 } else {
|
|
2330 var result1 = parse_eolEscapeSequence();
|
|
2331 if (result1 !== null) {
|
|
2332 var result0 = result1;
|
|
2333 } else {
|
|
2334 var result0 = null;;
|
|
2335 };
|
|
2336 };
|
|
2337 };
|
|
2338 };
|
|
2339 };
|
|
2340 }
|
|
2341
|
|
2342
|
|
2343
|
|
2344 cache[cacheKey] = {
|
|
2345 nextPos: pos,
|
|
2346 result: result0
|
|
2347 };
|
|
2348 return result0;
|
|
2349 }
|
|
2350
|
|
2351 function parse_simpleDoubleQuotedCharacter() {
|
|
2352 var cacheKey = 'simpleDoubleQuotedCharacter@' + pos;
|
|
2353 var cachedResult = cache[cacheKey];
|
|
2354 if (cachedResult) {
|
|
2355 pos = cachedResult.nextPos;
|
|
2356 return cachedResult.result;
|
|
2357 }
|
|
2358
|
|
2359
|
|
2360 var savedPos0 = pos;
|
|
2361 var savedPos1 = pos;
|
|
2362 var savedPos2 = pos;
|
|
2363 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
2364 reportMatchFailures = false;
|
|
2365 if (input.substr(pos, 1) === "\"") {
|
|
2366 var result8 = "\"";
|
|
2367 pos += 1;
|
|
2368 } else {
|
|
2369 var result8 = null;
|
|
2370 if (reportMatchFailures) {
|
|
2371 matchFailed("\"\\\"\"");
|
|
2372 }
|
|
2373 }
|
|
2374 if (result8 !== null) {
|
|
2375 var result5 = result8;
|
|
2376 } else {
|
|
2377 if (input.substr(pos, 1) === "\\") {
|
|
2378 var result7 = "\\";
|
|
2379 pos += 1;
|
|
2380 } else {
|
|
2381 var result7 = null;
|
|
2382 if (reportMatchFailures) {
|
|
2383 matchFailed("\"\\\\\"");
|
|
2384 }
|
|
2385 }
|
|
2386 if (result7 !== null) {
|
|
2387 var result5 = result7;
|
|
2388 } else {
|
|
2389 var result6 = parse_eolChar();
|
|
2390 if (result6 !== null) {
|
|
2391 var result5 = result6;
|
|
2392 } else {
|
|
2393 var result5 = null;;
|
|
2394 };
|
|
2395 };
|
|
2396 }
|
|
2397 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
2398 if (result5 === null) {
|
|
2399 var result3 = '';
|
|
2400 } else {
|
|
2401 var result3 = null;
|
|
2402 pos = savedPos2;
|
|
2403 }
|
|
2404 if (result3 !== null) {
|
|
2405 if (input.length > pos) {
|
|
2406 var result4 = input.charAt(pos);
|
|
2407 pos++;
|
|
2408 } else {
|
|
2409 var result4 = null;
|
|
2410 if (reportMatchFailures) {
|
|
2411 matchFailed('any character');
|
|
2412 }
|
|
2413 }
|
|
2414 if (result4 !== null) {
|
|
2415 var result1 = [result3, result4];
|
|
2416 } else {
|
|
2417 var result1 = null;
|
|
2418 pos = savedPos1;
|
|
2419 }
|
|
2420 } else {
|
|
2421 var result1 = null;
|
|
2422 pos = savedPos1;
|
|
2423 }
|
|
2424 var result2 = result1 !== null
|
|
2425 ? (function(char_) { return char_; })(result1[1])
|
|
2426 : null;
|
|
2427 if (result2 !== null) {
|
|
2428 var result0 = result2;
|
|
2429 } else {
|
|
2430 var result0 = null;
|
|
2431 pos = savedPos0;
|
|
2432 }
|
|
2433
|
|
2434
|
|
2435
|
|
2436 cache[cacheKey] = {
|
|
2437 nextPos: pos,
|
|
2438 result: result0
|
|
2439 };
|
|
2440 return result0;
|
|
2441 }
|
|
2442
|
|
2443 function parse_singleQuotedLiteral() {
|
|
2444 var cacheKey = 'singleQuotedLiteral@' + pos;
|
|
2445 var cachedResult = cache[cacheKey];
|
|
2446 if (cachedResult) {
|
|
2447 pos = cachedResult.nextPos;
|
|
2448 return cachedResult.result;
|
|
2449 }
|
|
2450
|
|
2451
|
|
2452 var savedPos0 = pos;
|
|
2453 var savedPos1 = pos;
|
|
2454 if (input.substr(pos, 1) === "'") {
|
|
2455 var result3 = "'";
|
|
2456 pos += 1;
|
|
2457 } else {
|
|
2458 var result3 = null;
|
|
2459 if (reportMatchFailures) {
|
|
2460 matchFailed("\"'\"");
|
|
2461 }
|
|
2462 }
|
|
2463 if (result3 !== null) {
|
|
2464 var result4 = [];
|
|
2465 var result6 = parse_singleQuotedCharacter();
|
|
2466 while (result6 !== null) {
|
|
2467 result4.push(result6);
|
|
2468 var result6 = parse_singleQuotedCharacter();
|
|
2469 }
|
|
2470 if (result4 !== null) {
|
|
2471 if (input.substr(pos, 1) === "'") {
|
|
2472 var result5 = "'";
|
|
2473 pos += 1;
|
|
2474 } else {
|
|
2475 var result5 = null;
|
|
2476 if (reportMatchFailures) {
|
|
2477 matchFailed("\"'\"");
|
|
2478 }
|
|
2479 }
|
|
2480 if (result5 !== null) {
|
|
2481 var result1 = [result3, result4, result5];
|
|
2482 } else {
|
|
2483 var result1 = null;
|
|
2484 pos = savedPos1;
|
|
2485 }
|
|
2486 } else {
|
|
2487 var result1 = null;
|
|
2488 pos = savedPos1;
|
|
2489 }
|
|
2490 } else {
|
|
2491 var result1 = null;
|
|
2492 pos = savedPos1;
|
|
2493 }
|
|
2494 var result2 = result1 !== null
|
|
2495 ? (function(chars) { return chars.join(""); })(result1[1])
|
|
2496 : null;
|
|
2497 if (result2 !== null) {
|
|
2498 var result0 = result2;
|
|
2499 } else {
|
|
2500 var result0 = null;
|
|
2501 pos = savedPos0;
|
|
2502 }
|
|
2503
|
|
2504
|
|
2505
|
|
2506 cache[cacheKey] = {
|
|
2507 nextPos: pos,
|
|
2508 result: result0
|
|
2509 };
|
|
2510 return result0;
|
|
2511 }
|
|
2512
|
|
2513 function parse_singleQuotedCharacter() {
|
|
2514 var cacheKey = 'singleQuotedCharacter@' + pos;
|
|
2515 var cachedResult = cache[cacheKey];
|
|
2516 if (cachedResult) {
|
|
2517 pos = cachedResult.nextPos;
|
|
2518 return cachedResult.result;
|
|
2519 }
|
|
2520
|
|
2521
|
|
2522 var result6 = parse_simpleSingleQuotedCharacter();
|
|
2523 if (result6 !== null) {
|
|
2524 var result0 = result6;
|
|
2525 } else {
|
|
2526 var result5 = parse_simpleEscapeSequence();
|
|
2527 if (result5 !== null) {
|
|
2528 var result0 = result5;
|
|
2529 } else {
|
|
2530 var result4 = parse_zeroEscapeSequence();
|
|
2531 if (result4 !== null) {
|
|
2532 var result0 = result4;
|
|
2533 } else {
|
|
2534 var result3 = parse_hexEscapeSequence();
|
|
2535 if (result3 !== null) {
|
|
2536 var result0 = result3;
|
|
2537 } else {
|
|
2538 var result2 = parse_unicodeEscapeSequence();
|
|
2539 if (result2 !== null) {
|
|
2540 var result0 = result2;
|
|
2541 } else {
|
|
2542 var result1 = parse_eolEscapeSequence();
|
|
2543 if (result1 !== null) {
|
|
2544 var result0 = result1;
|
|
2545 } else {
|
|
2546 var result0 = null;;
|
|
2547 };
|
|
2548 };
|
|
2549 };
|
|
2550 };
|
|
2551 };
|
|
2552 }
|
|
2553
|
|
2554
|
|
2555
|
|
2556 cache[cacheKey] = {
|
|
2557 nextPos: pos,
|
|
2558 result: result0
|
|
2559 };
|
|
2560 return result0;
|
|
2561 }
|
|
2562
|
|
2563 function parse_simpleSingleQuotedCharacter() {
|
|
2564 var cacheKey = 'simpleSingleQuotedCharacter@' + pos;
|
|
2565 var cachedResult = cache[cacheKey];
|
|
2566 if (cachedResult) {
|
|
2567 pos = cachedResult.nextPos;
|
|
2568 return cachedResult.result;
|
|
2569 }
|
|
2570
|
|
2571
|
|
2572 var savedPos0 = pos;
|
|
2573 var savedPos1 = pos;
|
|
2574 var savedPos2 = pos;
|
|
2575 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
2576 reportMatchFailures = false;
|
|
2577 if (input.substr(pos, 1) === "'") {
|
|
2578 var result8 = "'";
|
|
2579 pos += 1;
|
|
2580 } else {
|
|
2581 var result8 = null;
|
|
2582 if (reportMatchFailures) {
|
|
2583 matchFailed("\"'\"");
|
|
2584 }
|
|
2585 }
|
|
2586 if (result8 !== null) {
|
|
2587 var result5 = result8;
|
|
2588 } else {
|
|
2589 if (input.substr(pos, 1) === "\\") {
|
|
2590 var result7 = "\\";
|
|
2591 pos += 1;
|
|
2592 } else {
|
|
2593 var result7 = null;
|
|
2594 if (reportMatchFailures) {
|
|
2595 matchFailed("\"\\\\\"");
|
|
2596 }
|
|
2597 }
|
|
2598 if (result7 !== null) {
|
|
2599 var result5 = result7;
|
|
2600 } else {
|
|
2601 var result6 = parse_eolChar();
|
|
2602 if (result6 !== null) {
|
|
2603 var result5 = result6;
|
|
2604 } else {
|
|
2605 var result5 = null;;
|
|
2606 };
|
|
2607 };
|
|
2608 }
|
|
2609 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
2610 if (result5 === null) {
|
|
2611 var result3 = '';
|
|
2612 } else {
|
|
2613 var result3 = null;
|
|
2614 pos = savedPos2;
|
|
2615 }
|
|
2616 if (result3 !== null) {
|
|
2617 if (input.length > pos) {
|
|
2618 var result4 = input.charAt(pos);
|
|
2619 pos++;
|
|
2620 } else {
|
|
2621 var result4 = null;
|
|
2622 if (reportMatchFailures) {
|
|
2623 matchFailed('any character');
|
|
2624 }
|
|
2625 }
|
|
2626 if (result4 !== null) {
|
|
2627 var result1 = [result3, result4];
|
|
2628 } else {
|
|
2629 var result1 = null;
|
|
2630 pos = savedPos1;
|
|
2631 }
|
|
2632 } else {
|
|
2633 var result1 = null;
|
|
2634 pos = savedPos1;
|
|
2635 }
|
|
2636 var result2 = result1 !== null
|
|
2637 ? (function(char_) { return char_; })(result1[1])
|
|
2638 : null;
|
|
2639 if (result2 !== null) {
|
|
2640 var result0 = result2;
|
|
2641 } else {
|
|
2642 var result0 = null;
|
|
2643 pos = savedPos0;
|
|
2644 }
|
|
2645
|
|
2646
|
|
2647
|
|
2648 cache[cacheKey] = {
|
|
2649 nextPos: pos,
|
|
2650 result: result0
|
|
2651 };
|
|
2652 return result0;
|
|
2653 }
|
|
2654
|
|
2655 function parse_class() {
|
|
2656 var cacheKey = 'class@' + pos;
|
|
2657 var cachedResult = cache[cacheKey];
|
|
2658 if (cachedResult) {
|
|
2659 pos = cachedResult.nextPos;
|
|
2660 return cachedResult.result;
|
|
2661 }
|
|
2662
|
|
2663 var savedReportMatchFailures = reportMatchFailures;
|
|
2664 reportMatchFailures = false;
|
|
2665 var savedPos0 = pos;
|
|
2666 var savedPos1 = pos;
|
|
2667 if (input.substr(pos, 1) === "[") {
|
|
2668 var result3 = "[";
|
|
2669 pos += 1;
|
|
2670 } else {
|
|
2671 var result3 = null;
|
|
2672 if (reportMatchFailures) {
|
|
2673 matchFailed("\"[\"");
|
|
2674 }
|
|
2675 }
|
|
2676 if (result3 !== null) {
|
|
2677 if (input.substr(pos, 1) === "^") {
|
|
2678 var result11 = "^";
|
|
2679 pos += 1;
|
|
2680 } else {
|
|
2681 var result11 = null;
|
|
2682 if (reportMatchFailures) {
|
|
2683 matchFailed("\"^\"");
|
|
2684 }
|
|
2685 }
|
|
2686 var result4 = result11 !== null ? result11 : '';
|
|
2687 if (result4 !== null) {
|
|
2688 var result5 = [];
|
|
2689 var result10 = parse_classCharacterRange();
|
|
2690 if (result10 !== null) {
|
|
2691 var result8 = result10;
|
|
2692 } else {
|
|
2693 var result9 = parse_classCharacter();
|
|
2694 if (result9 !== null) {
|
|
2695 var result8 = result9;
|
|
2696 } else {
|
|
2697 var result8 = null;;
|
|
2698 };
|
|
2699 }
|
|
2700 while (result8 !== null) {
|
|
2701 result5.push(result8);
|
|
2702 var result10 = parse_classCharacterRange();
|
|
2703 if (result10 !== null) {
|
|
2704 var result8 = result10;
|
|
2705 } else {
|
|
2706 var result9 = parse_classCharacter();
|
|
2707 if (result9 !== null) {
|
|
2708 var result8 = result9;
|
|
2709 } else {
|
|
2710 var result8 = null;;
|
|
2711 };
|
|
2712 }
|
|
2713 }
|
|
2714 if (result5 !== null) {
|
|
2715 if (input.substr(pos, 1) === "]") {
|
|
2716 var result6 = "]";
|
|
2717 pos += 1;
|
|
2718 } else {
|
|
2719 var result6 = null;
|
|
2720 if (reportMatchFailures) {
|
|
2721 matchFailed("\"]\"");
|
|
2722 }
|
|
2723 }
|
|
2724 if (result6 !== null) {
|
|
2725 var result7 = parse___();
|
|
2726 if (result7 !== null) {
|
|
2727 var result1 = [result3, result4, result5, result6, result7];
|
|
2728 } else {
|
|
2729 var result1 = null;
|
|
2730 pos = savedPos1;
|
|
2731 }
|
|
2732 } else {
|
|
2733 var result1 = null;
|
|
2734 pos = savedPos1;
|
|
2735 }
|
|
2736 } else {
|
|
2737 var result1 = null;
|
|
2738 pos = savedPos1;
|
|
2739 }
|
|
2740 } else {
|
|
2741 var result1 = null;
|
|
2742 pos = savedPos1;
|
|
2743 }
|
|
2744 } else {
|
|
2745 var result1 = null;
|
|
2746 pos = savedPos1;
|
|
2747 }
|
|
2748 var result2 = result1 !== null
|
|
2749 ? (function(inverted, parts) {
|
|
2750 var partsConverted = map(parts, function(part) { return part.data; });
|
|
2751 var rawText = "["
|
|
2752 + inverted
|
|
2753 + map(parts, function(part) { return part.rawText; }).join("")
|
|
2754 + "]";
|
|
2755
|
|
2756 return {
|
|
2757 type: "class",
|
|
2758 inverted: inverted === "^",
|
|
2759 parts: partsConverted,
|
|
2760 // FIXME: Get the raw text from the input directly.
|
|
2761 rawText: rawText
|
|
2762 };
|
|
2763 })(result1[1], result1[2])
|
|
2764 : null;
|
|
2765 if (result2 !== null) {
|
|
2766 var result0 = result2;
|
|
2767 } else {
|
|
2768 var result0 = null;
|
|
2769 pos = savedPos0;
|
|
2770 }
|
|
2771 reportMatchFailures = savedReportMatchFailures;
|
|
2772 if (reportMatchFailures && result0 === null) {
|
|
2773 matchFailed("character class");
|
|
2774 }
|
|
2775
|
|
2776 cache[cacheKey] = {
|
|
2777 nextPos: pos,
|
|
2778 result: result0
|
|
2779 };
|
|
2780 return result0;
|
|
2781 }
|
|
2782
|
|
2783 function parse_classCharacterRange() {
|
|
2784 var cacheKey = 'classCharacterRange@' + pos;
|
|
2785 var cachedResult = cache[cacheKey];
|
|
2786 if (cachedResult) {
|
|
2787 pos = cachedResult.nextPos;
|
|
2788 return cachedResult.result;
|
|
2789 }
|
|
2790
|
|
2791
|
|
2792 var savedPos0 = pos;
|
|
2793 var savedPos1 = pos;
|
|
2794 var result3 = parse_classCharacter();
|
|
2795 if (result3 !== null) {
|
|
2796 if (input.substr(pos, 1) === "-") {
|
|
2797 var result4 = "-";
|
|
2798 pos += 1;
|
|
2799 } else {
|
|
2800 var result4 = null;
|
|
2801 if (reportMatchFailures) {
|
|
2802 matchFailed("\"-\"");
|
|
2803 }
|
|
2804 }
|
|
2805 if (result4 !== null) {
|
|
2806 var result5 = parse_classCharacter();
|
|
2807 if (result5 !== null) {
|
|
2808 var result1 = [result3, result4, result5];
|
|
2809 } else {
|
|
2810 var result1 = null;
|
|
2811 pos = savedPos1;
|
|
2812 }
|
|
2813 } else {
|
|
2814 var result1 = null;
|
|
2815 pos = savedPos1;
|
|
2816 }
|
|
2817 } else {
|
|
2818 var result1 = null;
|
|
2819 pos = savedPos1;
|
|
2820 }
|
|
2821 var result2 = result1 !== null
|
|
2822 ? (function(begin, end) {
|
|
2823 if (begin.data.charCodeAt(0) > end.data.charCodeAt(0)) {
|
|
2824 throw new this.SyntaxError(
|
|
2825 "Invalid character range: " + begin.rawText + "-" + end.rawText + "."
|
|
2826 );
|
|
2827 }
|
|
2828
|
|
2829 return {
|
|
2830 data: [begin.data, end.data],
|
|
2831 // FIXME: Get the raw text from the input directly.
|
|
2832 rawText: begin.rawText + "-" + end.rawText
|
|
2833 }
|
|
2834 })(result1[0], result1[2])
|
|
2835 : null;
|
|
2836 if (result2 !== null) {
|
|
2837 var result0 = result2;
|
|
2838 } else {
|
|
2839 var result0 = null;
|
|
2840 pos = savedPos0;
|
|
2841 }
|
|
2842
|
|
2843
|
|
2844
|
|
2845 cache[cacheKey] = {
|
|
2846 nextPos: pos,
|
|
2847 result: result0
|
|
2848 };
|
|
2849 return result0;
|
|
2850 }
|
|
2851
|
|
2852 function parse_classCharacter() {
|
|
2853 var cacheKey = 'classCharacter@' + pos;
|
|
2854 var cachedResult = cache[cacheKey];
|
|
2855 if (cachedResult) {
|
|
2856 pos = cachedResult.nextPos;
|
|
2857 return cachedResult.result;
|
|
2858 }
|
|
2859
|
|
2860
|
|
2861 var savedPos0 = pos;
|
|
2862 var result1 = parse_bracketDelimitedCharacter();
|
|
2863 var result2 = result1 !== null
|
|
2864 ? (function(char_) {
|
|
2865 return {
|
|
2866 data: char_,
|
|
2867 // FIXME: Get the raw text from the input directly.
|
|
2868 rawText: quoteForRegexpClass(char_)
|
|
2869 };
|
|
2870 })(result1)
|
|
2871 : null;
|
|
2872 if (result2 !== null) {
|
|
2873 var result0 = result2;
|
|
2874 } else {
|
|
2875 var result0 = null;
|
|
2876 pos = savedPos0;
|
|
2877 }
|
|
2878
|
|
2879
|
|
2880
|
|
2881 cache[cacheKey] = {
|
|
2882 nextPos: pos,
|
|
2883 result: result0
|
|
2884 };
|
|
2885 return result0;
|
|
2886 }
|
|
2887
|
|
2888 function parse_bracketDelimitedCharacter() {
|
|
2889 var cacheKey = 'bracketDelimitedCharacter@' + pos;
|
|
2890 var cachedResult = cache[cacheKey];
|
|
2891 if (cachedResult) {
|
|
2892 pos = cachedResult.nextPos;
|
|
2893 return cachedResult.result;
|
|
2894 }
|
|
2895
|
|
2896
|
|
2897 var result6 = parse_simpleBracketDelimitedCharacter();
|
|
2898 if (result6 !== null) {
|
|
2899 var result0 = result6;
|
|
2900 } else {
|
|
2901 var result5 = parse_simpleEscapeSequence();
|
|
2902 if (result5 !== null) {
|
|
2903 var result0 = result5;
|
|
2904 } else {
|
|
2905 var result4 = parse_zeroEscapeSequence();
|
|
2906 if (result4 !== null) {
|
|
2907 var result0 = result4;
|
|
2908 } else {
|
|
2909 var result3 = parse_hexEscapeSequence();
|
|
2910 if (result3 !== null) {
|
|
2911 var result0 = result3;
|
|
2912 } else {
|
|
2913 var result2 = parse_unicodeEscapeSequence();
|
|
2914 if (result2 !== null) {
|
|
2915 var result0 = result2;
|
|
2916 } else {
|
|
2917 var result1 = parse_eolEscapeSequence();
|
|
2918 if (result1 !== null) {
|
|
2919 var result0 = result1;
|
|
2920 } else {
|
|
2921 var result0 = null;;
|
|
2922 };
|
|
2923 };
|
|
2924 };
|
|
2925 };
|
|
2926 };
|
|
2927 }
|
|
2928
|
|
2929
|
|
2930
|
|
2931 cache[cacheKey] = {
|
|
2932 nextPos: pos,
|
|
2933 result: result0
|
|
2934 };
|
|
2935 return result0;
|
|
2936 }
|
|
2937
|
|
2938 function parse_simpleBracketDelimitedCharacter() {
|
|
2939 var cacheKey = 'simpleBracketDelimitedCharacter@' + pos;
|
|
2940 var cachedResult = cache[cacheKey];
|
|
2941 if (cachedResult) {
|
|
2942 pos = cachedResult.nextPos;
|
|
2943 return cachedResult.result;
|
|
2944 }
|
|
2945
|
|
2946
|
|
2947 var savedPos0 = pos;
|
|
2948 var savedPos1 = pos;
|
|
2949 var savedPos2 = pos;
|
|
2950 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
2951 reportMatchFailures = false;
|
|
2952 if (input.substr(pos, 1) === "]") {
|
|
2953 var result8 = "]";
|
|
2954 pos += 1;
|
|
2955 } else {
|
|
2956 var result8 = null;
|
|
2957 if (reportMatchFailures) {
|
|
2958 matchFailed("\"]\"");
|
|
2959 }
|
|
2960 }
|
|
2961 if (result8 !== null) {
|
|
2962 var result5 = result8;
|
|
2963 } else {
|
|
2964 if (input.substr(pos, 1) === "\\") {
|
|
2965 var result7 = "\\";
|
|
2966 pos += 1;
|
|
2967 } else {
|
|
2968 var result7 = null;
|
|
2969 if (reportMatchFailures) {
|
|
2970 matchFailed("\"\\\\\"");
|
|
2971 }
|
|
2972 }
|
|
2973 if (result7 !== null) {
|
|
2974 var result5 = result7;
|
|
2975 } else {
|
|
2976 var result6 = parse_eolChar();
|
|
2977 if (result6 !== null) {
|
|
2978 var result5 = result6;
|
|
2979 } else {
|
|
2980 var result5 = null;;
|
|
2981 };
|
|
2982 };
|
|
2983 }
|
|
2984 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
2985 if (result5 === null) {
|
|
2986 var result3 = '';
|
|
2987 } else {
|
|
2988 var result3 = null;
|
|
2989 pos = savedPos2;
|
|
2990 }
|
|
2991 if (result3 !== null) {
|
|
2992 if (input.length > pos) {
|
|
2993 var result4 = input.charAt(pos);
|
|
2994 pos++;
|
|
2995 } else {
|
|
2996 var result4 = null;
|
|
2997 if (reportMatchFailures) {
|
|
2998 matchFailed('any character');
|
|
2999 }
|
|
3000 }
|
|
3001 if (result4 !== null) {
|
|
3002 var result1 = [result3, result4];
|
|
3003 } else {
|
|
3004 var result1 = null;
|
|
3005 pos = savedPos1;
|
|
3006 }
|
|
3007 } else {
|
|
3008 var result1 = null;
|
|
3009 pos = savedPos1;
|
|
3010 }
|
|
3011 var result2 = result1 !== null
|
|
3012 ? (function(char_) { return char_; })(result1[1])
|
|
3013 : null;
|
|
3014 if (result2 !== null) {
|
|
3015 var result0 = result2;
|
|
3016 } else {
|
|
3017 var result0 = null;
|
|
3018 pos = savedPos0;
|
|
3019 }
|
|
3020
|
|
3021
|
|
3022
|
|
3023 cache[cacheKey] = {
|
|
3024 nextPos: pos,
|
|
3025 result: result0
|
|
3026 };
|
|
3027 return result0;
|
|
3028 }
|
|
3029
|
|
3030 function parse_simpleEscapeSequence() {
|
|
3031 var cacheKey = 'simpleEscapeSequence@' + pos;
|
|
3032 var cachedResult = cache[cacheKey];
|
|
3033 if (cachedResult) {
|
|
3034 pos = cachedResult.nextPos;
|
|
3035 return cachedResult.result;
|
|
3036 }
|
|
3037
|
|
3038
|
|
3039 var savedPos0 = pos;
|
|
3040 var savedPos1 = pos;
|
|
3041 if (input.substr(pos, 1) === "\\") {
|
|
3042 var result3 = "\\";
|
|
3043 pos += 1;
|
|
3044 } else {
|
|
3045 var result3 = null;
|
|
3046 if (reportMatchFailures) {
|
|
3047 matchFailed("\"\\\\\"");
|
|
3048 }
|
|
3049 }
|
|
3050 if (result3 !== null) {
|
|
3051 var savedPos2 = pos;
|
|
3052 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
3053 reportMatchFailures = false;
|
|
3054 var result10 = parse_digit();
|
|
3055 if (result10 !== null) {
|
|
3056 var result6 = result10;
|
|
3057 } else {
|
|
3058 if (input.substr(pos, 1) === "x") {
|
|
3059 var result9 = "x";
|
|
3060 pos += 1;
|
|
3061 } else {
|
|
3062 var result9 = null;
|
|
3063 if (reportMatchFailures) {
|
|
3064 matchFailed("\"x\"");
|
|
3065 }
|
|
3066 }
|
|
3067 if (result9 !== null) {
|
|
3068 var result6 = result9;
|
|
3069 } else {
|
|
3070 if (input.substr(pos, 1) === "u") {
|
|
3071 var result8 = "u";
|
|
3072 pos += 1;
|
|
3073 } else {
|
|
3074 var result8 = null;
|
|
3075 if (reportMatchFailures) {
|
|
3076 matchFailed("\"u\"");
|
|
3077 }
|
|
3078 }
|
|
3079 if (result8 !== null) {
|
|
3080 var result6 = result8;
|
|
3081 } else {
|
|
3082 var result7 = parse_eolChar();
|
|
3083 if (result7 !== null) {
|
|
3084 var result6 = result7;
|
|
3085 } else {
|
|
3086 var result6 = null;;
|
|
3087 };
|
|
3088 };
|
|
3089 };
|
|
3090 }
|
|
3091 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
3092 if (result6 === null) {
|
|
3093 var result4 = '';
|
|
3094 } else {
|
|
3095 var result4 = null;
|
|
3096 pos = savedPos2;
|
|
3097 }
|
|
3098 if (result4 !== null) {
|
|
3099 if (input.length > pos) {
|
|
3100 var result5 = input.charAt(pos);
|
|
3101 pos++;
|
|
3102 } else {
|
|
3103 var result5 = null;
|
|
3104 if (reportMatchFailures) {
|
|
3105 matchFailed('any character');
|
|
3106 }
|
|
3107 }
|
|
3108 if (result5 !== null) {
|
|
3109 var result1 = [result3, result4, result5];
|
|
3110 } else {
|
|
3111 var result1 = null;
|
|
3112 pos = savedPos1;
|
|
3113 }
|
|
3114 } else {
|
|
3115 var result1 = null;
|
|
3116 pos = savedPos1;
|
|
3117 }
|
|
3118 } else {
|
|
3119 var result1 = null;
|
|
3120 pos = savedPos1;
|
|
3121 }
|
|
3122 var result2 = result1 !== null
|
|
3123 ? (function(char_) {
|
|
3124 return char_
|
|
3125 .replace("b", "\b")
|
|
3126 .replace("f", "\f")
|
|
3127 .replace("n", "\n")
|
|
3128 .replace("r", "\r")
|
|
3129 .replace("t", "\t")
|
|
3130 .replace("v", "\x0B") // IE does not recognize "\v".
|
|
3131 })(result1[2])
|
|
3132 : null;
|
|
3133 if (result2 !== null) {
|
|
3134 var result0 = result2;
|
|
3135 } else {
|
|
3136 var result0 = null;
|
|
3137 pos = savedPos0;
|
|
3138 }
|
|
3139
|
|
3140
|
|
3141
|
|
3142 cache[cacheKey] = {
|
|
3143 nextPos: pos,
|
|
3144 result: result0
|
|
3145 };
|
|
3146 return result0;
|
|
3147 }
|
|
3148
|
|
3149 function parse_zeroEscapeSequence() {
|
|
3150 var cacheKey = 'zeroEscapeSequence@' + pos;
|
|
3151 var cachedResult = cache[cacheKey];
|
|
3152 if (cachedResult) {
|
|
3153 pos = cachedResult.nextPos;
|
|
3154 return cachedResult.result;
|
|
3155 }
|
|
3156
|
|
3157
|
|
3158 var savedPos0 = pos;
|
|
3159 var savedPos1 = pos;
|
|
3160 if (input.substr(pos, 2) === "\\0") {
|
|
3161 var result3 = "\\0";
|
|
3162 pos += 2;
|
|
3163 } else {
|
|
3164 var result3 = null;
|
|
3165 if (reportMatchFailures) {
|
|
3166 matchFailed("\"\\\\0\"");
|
|
3167 }
|
|
3168 }
|
|
3169 if (result3 !== null) {
|
|
3170 var savedPos2 = pos;
|
|
3171 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
3172 reportMatchFailures = false;
|
|
3173 var result5 = parse_digit();
|
|
3174 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
3175 if (result5 === null) {
|
|
3176 var result4 = '';
|
|
3177 } else {
|
|
3178 var result4 = null;
|
|
3179 pos = savedPos2;
|
|
3180 }
|
|
3181 if (result4 !== null) {
|
|
3182 var result1 = [result3, result4];
|
|
3183 } else {
|
|
3184 var result1 = null;
|
|
3185 pos = savedPos1;
|
|
3186 }
|
|
3187 } else {
|
|
3188 var result1 = null;
|
|
3189 pos = savedPos1;
|
|
3190 }
|
|
3191 var result2 = result1 !== null
|
|
3192 ? (function() { return "\0"; })()
|
|
3193 : null;
|
|
3194 if (result2 !== null) {
|
|
3195 var result0 = result2;
|
|
3196 } else {
|
|
3197 var result0 = null;
|
|
3198 pos = savedPos0;
|
|
3199 }
|
|
3200
|
|
3201
|
|
3202
|
|
3203 cache[cacheKey] = {
|
|
3204 nextPos: pos,
|
|
3205 result: result0
|
|
3206 };
|
|
3207 return result0;
|
|
3208 }
|
|
3209
|
|
3210 function parse_hexEscapeSequence() {
|
|
3211 var cacheKey = 'hexEscapeSequence@' + pos;
|
|
3212 var cachedResult = cache[cacheKey];
|
|
3213 if (cachedResult) {
|
|
3214 pos = cachedResult.nextPos;
|
|
3215 return cachedResult.result;
|
|
3216 }
|
|
3217
|
|
3218
|
|
3219 var savedPos0 = pos;
|
|
3220 var savedPos1 = pos;
|
|
3221 if (input.substr(pos, 2) === "\\x") {
|
|
3222 var result3 = "\\x";
|
|
3223 pos += 2;
|
|
3224 } else {
|
|
3225 var result3 = null;
|
|
3226 if (reportMatchFailures) {
|
|
3227 matchFailed("\"\\\\x\"");
|
|
3228 }
|
|
3229 }
|
|
3230 if (result3 !== null) {
|
|
3231 var result4 = parse_hexDigit();
|
|
3232 if (result4 !== null) {
|
|
3233 var result5 = parse_hexDigit();
|
|
3234 if (result5 !== null) {
|
|
3235 var result1 = [result3, result4, result5];
|
|
3236 } else {
|
|
3237 var result1 = null;
|
|
3238 pos = savedPos1;
|
|
3239 }
|
|
3240 } else {
|
|
3241 var result1 = null;
|
|
3242 pos = savedPos1;
|
|
3243 }
|
|
3244 } else {
|
|
3245 var result1 = null;
|
|
3246 pos = savedPos1;
|
|
3247 }
|
|
3248 var result2 = result1 !== null
|
|
3249 ? (function(h1, h2) {
|
|
3250 return String.fromCharCode(parseInt("0x" + h1 + h2));
|
|
3251 })(result1[1], result1[2])
|
|
3252 : null;
|
|
3253 if (result2 !== null) {
|
|
3254 var result0 = result2;
|
|
3255 } else {
|
|
3256 var result0 = null;
|
|
3257 pos = savedPos0;
|
|
3258 }
|
|
3259
|
|
3260
|
|
3261
|
|
3262 cache[cacheKey] = {
|
|
3263 nextPos: pos,
|
|
3264 result: result0
|
|
3265 };
|
|
3266 return result0;
|
|
3267 }
|
|
3268
|
|
3269 function parse_unicodeEscapeSequence() {
|
|
3270 var cacheKey = 'unicodeEscapeSequence@' + pos;
|
|
3271 var cachedResult = cache[cacheKey];
|
|
3272 if (cachedResult) {
|
|
3273 pos = cachedResult.nextPos;
|
|
3274 return cachedResult.result;
|
|
3275 }
|
|
3276
|
|
3277
|
|
3278 var savedPos0 = pos;
|
|
3279 var savedPos1 = pos;
|
|
3280 if (input.substr(pos, 2) === "\\u") {
|
|
3281 var result3 = "\\u";
|
|
3282 pos += 2;
|
|
3283 } else {
|
|
3284 var result3 = null;
|
|
3285 if (reportMatchFailures) {
|
|
3286 matchFailed("\"\\\\u\"");
|
|
3287 }
|
|
3288 }
|
|
3289 if (result3 !== null) {
|
|
3290 var result4 = parse_hexDigit();
|
|
3291 if (result4 !== null) {
|
|
3292 var result5 = parse_hexDigit();
|
|
3293 if (result5 !== null) {
|
|
3294 var result6 = parse_hexDigit();
|
|
3295 if (result6 !== null) {
|
|
3296 var result7 = parse_hexDigit();
|
|
3297 if (result7 !== null) {
|
|
3298 var result1 = [result3, result4, result5, result6, result7];
|
|
3299 } else {
|
|
3300 var result1 = null;
|
|
3301 pos = savedPos1;
|
|
3302 }
|
|
3303 } else {
|
|
3304 var result1 = null;
|
|
3305 pos = savedPos1;
|
|
3306 }
|
|
3307 } else {
|
|
3308 var result1 = null;
|
|
3309 pos = savedPos1;
|
|
3310 }
|
|
3311 } else {
|
|
3312 var result1 = null;
|
|
3313 pos = savedPos1;
|
|
3314 }
|
|
3315 } else {
|
|
3316 var result1 = null;
|
|
3317 pos = savedPos1;
|
|
3318 }
|
|
3319 var result2 = result1 !== null
|
|
3320 ? (function(h1, h2, h3, h4) {
|
|
3321 return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
|
|
3322 })(result1[1], result1[2], result1[3], result1[4])
|
|
3323 : null;
|
|
3324 if (result2 !== null) {
|
|
3325 var result0 = result2;
|
|
3326 } else {
|
|
3327 var result0 = null;
|
|
3328 pos = savedPos0;
|
|
3329 }
|
|
3330
|
|
3331
|
|
3332
|
|
3333 cache[cacheKey] = {
|
|
3334 nextPos: pos,
|
|
3335 result: result0
|
|
3336 };
|
|
3337 return result0;
|
|
3338 }
|
|
3339
|
|
3340 function parse_eolEscapeSequence() {
|
|
3341 var cacheKey = 'eolEscapeSequence@' + pos;
|
|
3342 var cachedResult = cache[cacheKey];
|
|
3343 if (cachedResult) {
|
|
3344 pos = cachedResult.nextPos;
|
|
3345 return cachedResult.result;
|
|
3346 }
|
|
3347
|
|
3348
|
|
3349 var savedPos0 = pos;
|
|
3350 var savedPos1 = pos;
|
|
3351 if (input.substr(pos, 1) === "\\") {
|
|
3352 var result3 = "\\";
|
|
3353 pos += 1;
|
|
3354 } else {
|
|
3355 var result3 = null;
|
|
3356 if (reportMatchFailures) {
|
|
3357 matchFailed("\"\\\\\"");
|
|
3358 }
|
|
3359 }
|
|
3360 if (result3 !== null) {
|
|
3361 var result4 = parse_eol();
|
|
3362 if (result4 !== null) {
|
|
3363 var result1 = [result3, result4];
|
|
3364 } else {
|
|
3365 var result1 = null;
|
|
3366 pos = savedPos1;
|
|
3367 }
|
|
3368 } else {
|
|
3369 var result1 = null;
|
|
3370 pos = savedPos1;
|
|
3371 }
|
|
3372 var result2 = result1 !== null
|
|
3373 ? (function(eol) { return eol; })(result1[1])
|
|
3374 : null;
|
|
3375 if (result2 !== null) {
|
|
3376 var result0 = result2;
|
|
3377 } else {
|
|
3378 var result0 = null;
|
|
3379 pos = savedPos0;
|
|
3380 }
|
|
3381
|
|
3382
|
|
3383
|
|
3384 cache[cacheKey] = {
|
|
3385 nextPos: pos,
|
|
3386 result: result0
|
|
3387 };
|
|
3388 return result0;
|
|
3389 }
|
|
3390
|
|
3391 function parse_digit() {
|
|
3392 var cacheKey = 'digit@' + pos;
|
|
3393 var cachedResult = cache[cacheKey];
|
|
3394 if (cachedResult) {
|
|
3395 pos = cachedResult.nextPos;
|
|
3396 return cachedResult.result;
|
|
3397 }
|
|
3398
|
|
3399
|
|
3400 if (input.substr(pos).match(/^[0-9]/) !== null) {
|
|
3401 var result0 = input.charAt(pos);
|
|
3402 pos++;
|
|
3403 } else {
|
|
3404 var result0 = null;
|
|
3405 if (reportMatchFailures) {
|
|
3406 matchFailed("[0-9]");
|
|
3407 }
|
|
3408 }
|
|
3409
|
|
3410
|
|
3411
|
|
3412 cache[cacheKey] = {
|
|
3413 nextPos: pos,
|
|
3414 result: result0
|
|
3415 };
|
|
3416 return result0;
|
|
3417 }
|
|
3418
|
|
3419 function parse_hexDigit() {
|
|
3420 var cacheKey = 'hexDigit@' + pos;
|
|
3421 var cachedResult = cache[cacheKey];
|
|
3422 if (cachedResult) {
|
|
3423 pos = cachedResult.nextPos;
|
|
3424 return cachedResult.result;
|
|
3425 }
|
|
3426
|
|
3427
|
|
3428 if (input.substr(pos).match(/^[0-9a-fA-F]/) !== null) {
|
|
3429 var result0 = input.charAt(pos);
|
|
3430 pos++;
|
|
3431 } else {
|
|
3432 var result0 = null;
|
|
3433 if (reportMatchFailures) {
|
|
3434 matchFailed("[0-9a-fA-F]");
|
|
3435 }
|
|
3436 }
|
|
3437
|
|
3438
|
|
3439
|
|
3440 cache[cacheKey] = {
|
|
3441 nextPos: pos,
|
|
3442 result: result0
|
|
3443 };
|
|
3444 return result0;
|
|
3445 }
|
|
3446
|
|
3447 function parse_letter() {
|
|
3448 var cacheKey = 'letter@' + pos;
|
|
3449 var cachedResult = cache[cacheKey];
|
|
3450 if (cachedResult) {
|
|
3451 pos = cachedResult.nextPos;
|
|
3452 return cachedResult.result;
|
|
3453 }
|
|
3454
|
|
3455
|
|
3456 var result2 = parse_lowerCaseLetter();
|
|
3457 if (result2 !== null) {
|
|
3458 var result0 = result2;
|
|
3459 } else {
|
|
3460 var result1 = parse_upperCaseLetter();
|
|
3461 if (result1 !== null) {
|
|
3462 var result0 = result1;
|
|
3463 } else {
|
|
3464 var result0 = null;;
|
|
3465 };
|
|
3466 }
|
|
3467
|
|
3468
|
|
3469
|
|
3470 cache[cacheKey] = {
|
|
3471 nextPos: pos,
|
|
3472 result: result0
|
|
3473 };
|
|
3474 return result0;
|
|
3475 }
|
|
3476
|
|
3477 function parse_lowerCaseLetter() {
|
|
3478 var cacheKey = 'lowerCaseLetter@' + pos;
|
|
3479 var cachedResult = cache[cacheKey];
|
|
3480 if (cachedResult) {
|
|
3481 pos = cachedResult.nextPos;
|
|
3482 return cachedResult.result;
|
|
3483 }
|
|
3484
|
|
3485
|
|
3486 if (input.substr(pos).match(/^[a-z]/) !== null) {
|
|
3487 var result0 = input.charAt(pos);
|
|
3488 pos++;
|
|
3489 } else {
|
|
3490 var result0 = null;
|
|
3491 if (reportMatchFailures) {
|
|
3492 matchFailed("[a-z]");
|
|
3493 }
|
|
3494 }
|
|
3495
|
|
3496
|
|
3497
|
|
3498 cache[cacheKey] = {
|
|
3499 nextPos: pos,
|
|
3500 result: result0
|
|
3501 };
|
|
3502 return result0;
|
|
3503 }
|
|
3504
|
|
3505 function parse_upperCaseLetter() {
|
|
3506 var cacheKey = 'upperCaseLetter@' + pos;
|
|
3507 var cachedResult = cache[cacheKey];
|
|
3508 if (cachedResult) {
|
|
3509 pos = cachedResult.nextPos;
|
|
3510 return cachedResult.result;
|
|
3511 }
|
|
3512
|
|
3513
|
|
3514 if (input.substr(pos).match(/^[A-Z]/) !== null) {
|
|
3515 var result0 = input.charAt(pos);
|
|
3516 pos++;
|
|
3517 } else {
|
|
3518 var result0 = null;
|
|
3519 if (reportMatchFailures) {
|
|
3520 matchFailed("[A-Z]");
|
|
3521 }
|
|
3522 }
|
|
3523
|
|
3524
|
|
3525
|
|
3526 cache[cacheKey] = {
|
|
3527 nextPos: pos,
|
|
3528 result: result0
|
|
3529 };
|
|
3530 return result0;
|
|
3531 }
|
|
3532
|
|
3533 function parse___() {
|
|
3534 var cacheKey = '__@' + pos;
|
|
3535 var cachedResult = cache[cacheKey];
|
|
3536 if (cachedResult) {
|
|
3537 pos = cachedResult.nextPos;
|
|
3538 return cachedResult.result;
|
|
3539 }
|
|
3540
|
|
3541
|
|
3542 var result0 = [];
|
|
3543 var result4 = parse_whitespace();
|
|
3544 if (result4 !== null) {
|
|
3545 var result1 = result4;
|
|
3546 } else {
|
|
3547 var result3 = parse_eol();
|
|
3548 if (result3 !== null) {
|
|
3549 var result1 = result3;
|
|
3550 } else {
|
|
3551 var result2 = parse_comment();
|
|
3552 if (result2 !== null) {
|
|
3553 var result1 = result2;
|
|
3554 } else {
|
|
3555 var result1 = null;;
|
|
3556 };
|
|
3557 };
|
|
3558 }
|
|
3559 while (result1 !== null) {
|
|
3560 result0.push(result1);
|
|
3561 var result4 = parse_whitespace();
|
|
3562 if (result4 !== null) {
|
|
3563 var result1 = result4;
|
|
3564 } else {
|
|
3565 var result3 = parse_eol();
|
|
3566 if (result3 !== null) {
|
|
3567 var result1 = result3;
|
|
3568 } else {
|
|
3569 var result2 = parse_comment();
|
|
3570 if (result2 !== null) {
|
|
3571 var result1 = result2;
|
|
3572 } else {
|
|
3573 var result1 = null;;
|
|
3574 };
|
|
3575 };
|
|
3576 }
|
|
3577 }
|
|
3578
|
|
3579
|
|
3580
|
|
3581 cache[cacheKey] = {
|
|
3582 nextPos: pos,
|
|
3583 result: result0
|
|
3584 };
|
|
3585 return result0;
|
|
3586 }
|
|
3587
|
|
3588 function parse_comment() {
|
|
3589 var cacheKey = 'comment@' + pos;
|
|
3590 var cachedResult = cache[cacheKey];
|
|
3591 if (cachedResult) {
|
|
3592 pos = cachedResult.nextPos;
|
|
3593 return cachedResult.result;
|
|
3594 }
|
|
3595
|
|
3596 var savedReportMatchFailures = reportMatchFailures;
|
|
3597 reportMatchFailures = false;
|
|
3598 var result2 = parse_singleLineComment();
|
|
3599 if (result2 !== null) {
|
|
3600 var result0 = result2;
|
|
3601 } else {
|
|
3602 var result1 = parse_multiLineComment();
|
|
3603 if (result1 !== null) {
|
|
3604 var result0 = result1;
|
|
3605 } else {
|
|
3606 var result0 = null;;
|
|
3607 };
|
|
3608 }
|
|
3609 reportMatchFailures = savedReportMatchFailures;
|
|
3610 if (reportMatchFailures && result0 === null) {
|
|
3611 matchFailed("comment");
|
|
3612 }
|
|
3613
|
|
3614 cache[cacheKey] = {
|
|
3615 nextPos: pos,
|
|
3616 result: result0
|
|
3617 };
|
|
3618 return result0;
|
|
3619 }
|
|
3620
|
|
3621 function parse_singleLineComment() {
|
|
3622 var cacheKey = 'singleLineComment@' + pos;
|
|
3623 var cachedResult = cache[cacheKey];
|
|
3624 if (cachedResult) {
|
|
3625 pos = cachedResult.nextPos;
|
|
3626 return cachedResult.result;
|
|
3627 }
|
|
3628
|
|
3629
|
|
3630 var savedPos0 = pos;
|
|
3631 if (input.substr(pos, 2) === "//") {
|
|
3632 var result1 = "//";
|
|
3633 pos += 2;
|
|
3634 } else {
|
|
3635 var result1 = null;
|
|
3636 if (reportMatchFailures) {
|
|
3637 matchFailed("\"//\"");
|
|
3638 }
|
|
3639 }
|
|
3640 if (result1 !== null) {
|
|
3641 var result2 = [];
|
|
3642 var savedPos1 = pos;
|
|
3643 var savedPos2 = pos;
|
|
3644 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
3645 reportMatchFailures = false;
|
|
3646 var result6 = parse_eolChar();
|
|
3647 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
3648 if (result6 === null) {
|
|
3649 var result4 = '';
|
|
3650 } else {
|
|
3651 var result4 = null;
|
|
3652 pos = savedPos2;
|
|
3653 }
|
|
3654 if (result4 !== null) {
|
|
3655 if (input.length > pos) {
|
|
3656 var result5 = input.charAt(pos);
|
|
3657 pos++;
|
|
3658 } else {
|
|
3659 var result5 = null;
|
|
3660 if (reportMatchFailures) {
|
|
3661 matchFailed('any character');
|
|
3662 }
|
|
3663 }
|
|
3664 if (result5 !== null) {
|
|
3665 var result3 = [result4, result5];
|
|
3666 } else {
|
|
3667 var result3 = null;
|
|
3668 pos = savedPos1;
|
|
3669 }
|
|
3670 } else {
|
|
3671 var result3 = null;
|
|
3672 pos = savedPos1;
|
|
3673 }
|
|
3674 while (result3 !== null) {
|
|
3675 result2.push(result3);
|
|
3676 var savedPos1 = pos;
|
|
3677 var savedPos2 = pos;
|
|
3678 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
3679 reportMatchFailures = false;
|
|
3680 var result6 = parse_eolChar();
|
|
3681 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
3682 if (result6 === null) {
|
|
3683 var result4 = '';
|
|
3684 } else {
|
|
3685 var result4 = null;
|
|
3686 pos = savedPos2;
|
|
3687 }
|
|
3688 if (result4 !== null) {
|
|
3689 if (input.length > pos) {
|
|
3690 var result5 = input.charAt(pos);
|
|
3691 pos++;
|
|
3692 } else {
|
|
3693 var result5 = null;
|
|
3694 if (reportMatchFailures) {
|
|
3695 matchFailed('any character');
|
|
3696 }
|
|
3697 }
|
|
3698 if (result5 !== null) {
|
|
3699 var result3 = [result4, result5];
|
|
3700 } else {
|
|
3701 var result3 = null;
|
|
3702 pos = savedPos1;
|
|
3703 }
|
|
3704 } else {
|
|
3705 var result3 = null;
|
|
3706 pos = savedPos1;
|
|
3707 }
|
|
3708 }
|
|
3709 if (result2 !== null) {
|
|
3710 var result0 = [result1, result2];
|
|
3711 } else {
|
|
3712 var result0 = null;
|
|
3713 pos = savedPos0;
|
|
3714 }
|
|
3715 } else {
|
|
3716 var result0 = null;
|
|
3717 pos = savedPos0;
|
|
3718 }
|
|
3719
|
|
3720
|
|
3721
|
|
3722 cache[cacheKey] = {
|
|
3723 nextPos: pos,
|
|
3724 result: result0
|
|
3725 };
|
|
3726 return result0;
|
|
3727 }
|
|
3728
|
|
3729 function parse_multiLineComment() {
|
|
3730 var cacheKey = 'multiLineComment@' + pos;
|
|
3731 var cachedResult = cache[cacheKey];
|
|
3732 if (cachedResult) {
|
|
3733 pos = cachedResult.nextPos;
|
|
3734 return cachedResult.result;
|
|
3735 }
|
|
3736
|
|
3737
|
|
3738 var savedPos0 = pos;
|
|
3739 if (input.substr(pos, 2) === "/*") {
|
|
3740 var result1 = "/*";
|
|
3741 pos += 2;
|
|
3742 } else {
|
|
3743 var result1 = null;
|
|
3744 if (reportMatchFailures) {
|
|
3745 matchFailed("\"/*\"");
|
|
3746 }
|
|
3747 }
|
|
3748 if (result1 !== null) {
|
|
3749 var result2 = [];
|
|
3750 var savedPos1 = pos;
|
|
3751 var savedPos2 = pos;
|
|
3752 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
3753 reportMatchFailures = false;
|
|
3754 if (input.substr(pos, 2) === "*/") {
|
|
3755 var result7 = "*/";
|
|
3756 pos += 2;
|
|
3757 } else {
|
|
3758 var result7 = null;
|
|
3759 if (reportMatchFailures) {
|
|
3760 matchFailed("\"*/\"");
|
|
3761 }
|
|
3762 }
|
|
3763 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
3764 if (result7 === null) {
|
|
3765 var result5 = '';
|
|
3766 } else {
|
|
3767 var result5 = null;
|
|
3768 pos = savedPos2;
|
|
3769 }
|
|
3770 if (result5 !== null) {
|
|
3771 if (input.length > pos) {
|
|
3772 var result6 = input.charAt(pos);
|
|
3773 pos++;
|
|
3774 } else {
|
|
3775 var result6 = null;
|
|
3776 if (reportMatchFailures) {
|
|
3777 matchFailed('any character');
|
|
3778 }
|
|
3779 }
|
|
3780 if (result6 !== null) {
|
|
3781 var result4 = [result5, result6];
|
|
3782 } else {
|
|
3783 var result4 = null;
|
|
3784 pos = savedPos1;
|
|
3785 }
|
|
3786 } else {
|
|
3787 var result4 = null;
|
|
3788 pos = savedPos1;
|
|
3789 }
|
|
3790 while (result4 !== null) {
|
|
3791 result2.push(result4);
|
|
3792 var savedPos1 = pos;
|
|
3793 var savedPos2 = pos;
|
|
3794 var savedReportMatchFailuresVar0 = reportMatchFailures;
|
|
3795 reportMatchFailures = false;
|
|
3796 if (input.substr(pos, 2) === "*/") {
|
|
3797 var result7 = "*/";
|
|
3798 pos += 2;
|
|
3799 } else {
|
|
3800 var result7 = null;
|
|
3801 if (reportMatchFailures) {
|
|
3802 matchFailed("\"*/\"");
|
|
3803 }
|
|
3804 }
|
|
3805 reportMatchFailures = savedReportMatchFailuresVar0;
|
|
3806 if (result7 === null) {
|
|
3807 var result5 = '';
|
|
3808 } else {
|
|
3809 var result5 = null;
|
|
3810 pos = savedPos2;
|
|
3811 }
|
|
3812 if (result5 !== null) {
|
|
3813 if (input.length > pos) {
|
|
3814 var result6 = input.charAt(pos);
|
|
3815 pos++;
|
|
3816 } else {
|
|
3817 var result6 = null;
|
|
3818 if (reportMatchFailures) {
|
|
3819 matchFailed('any character');
|
|
3820 }
|
|
3821 }
|
|
3822 if (result6 !== null) {
|
|
3823 var result4 = [result5, result6];
|
|
3824 } else {
|
|
3825 var result4 = null;
|
|
3826 pos = savedPos1;
|
|
3827 }
|
|
3828 } else {
|
|
3829 var result4 = null;
|
|
3830 pos = savedPos1;
|
|
3831 }
|
|
3832 }
|
|
3833 if (result2 !== null) {
|
|
3834 if (input.substr(pos, 2) === "*/") {
|
|
3835 var result3 = "*/";
|
|
3836 pos += 2;
|
|
3837 } else {
|
|
3838 var result3 = null;
|
|
3839 if (reportMatchFailures) {
|
|
3840 matchFailed("\"*/\"");
|
|
3841 }
|
|
3842 }
|
|
3843 if (result3 !== null) {
|
|
3844 var result0 = [result1, result2, result3];
|
|
3845 } else {
|
|
3846 var result0 = null;
|
|
3847 pos = savedPos0;
|
|
3848 }
|
|
3849 } else {
|
|
3850 var result0 = null;
|
|
3851 pos = savedPos0;
|
|
3852 }
|
|
3853 } else {
|
|
3854 var result0 = null;
|
|
3855 pos = savedPos0;
|
|
3856 }
|
|
3857
|
|
3858
|
|
3859
|
|
3860 cache[cacheKey] = {
|
|
3861 nextPos: pos,
|
|
3862 result: result0
|
|
3863 };
|
|
3864 return result0;
|
|
3865 }
|
|
3866
|
|
3867 function parse_eol() {
|
|
3868 var cacheKey = 'eol@' + pos;
|
|
3869 var cachedResult = cache[cacheKey];
|
|
3870 if (cachedResult) {
|
|
3871 pos = cachedResult.nextPos;
|
|
3872 return cachedResult.result;
|
|
3873 }
|
|
3874
|
|
3875 var savedReportMatchFailures = reportMatchFailures;
|
|
3876 reportMatchFailures = false;
|
|
3877 if (input.substr(pos, 1) === "\n") {
|
|
3878 var result5 = "\n";
|
|
3879 pos += 1;
|
|
3880 } else {
|
|
3881 var result5 = null;
|
|
3882 if (reportMatchFailures) {
|
|
3883 matchFailed("\"\\n\"");
|
|
3884 }
|
|
3885 }
|
|
3886 if (result5 !== null) {
|
|
3887 var result0 = result5;
|
|
3888 } else {
|
|
3889 if (input.substr(pos, 2) === "\r\n") {
|
|
3890 var result4 = "\r\n";
|
|
3891 pos += 2;
|
|
3892 } else {
|
|
3893 var result4 = null;
|
|
3894 if (reportMatchFailures) {
|
|
3895 matchFailed("\"\\r\\n\"");
|
|
3896 }
|
|
3897 }
|
|
3898 if (result4 !== null) {
|
|
3899 var result0 = result4;
|
|
3900 } else {
|
|
3901 if (input.substr(pos, 1) === "\r") {
|
|
3902 var result3 = "\r";
|
|
3903 pos += 1;
|
|
3904 } else {
|
|
3905 var result3 = null;
|
|
3906 if (reportMatchFailures) {
|
|
3907 matchFailed("\"\\r\"");
|
|
3908 }
|
|
3909 }
|
|
3910 if (result3 !== null) {
|
|
3911 var result0 = result3;
|
|
3912 } else {
|
|
3913 if (input.substr(pos, 1) === "\u2028") {
|
|
3914 var result2 = "\u2028";
|
|
3915 pos += 1;
|
|
3916 } else {
|
|
3917 var result2 = null;
|
|
3918 if (reportMatchFailures) {
|
|
3919 matchFailed("\"\\u2028\"");
|
|
3920 }
|
|
3921 }
|
|
3922 if (result2 !== null) {
|
|
3923 var result0 = result2;
|
|
3924 } else {
|
|
3925 if (input.substr(pos, 1) === "\u2029") {
|
|
3926 var result1 = "\u2029";
|
|
3927 pos += 1;
|
|
3928 } else {
|
|
3929 var result1 = null;
|
|
3930 if (reportMatchFailures) {
|
|
3931 matchFailed("\"\\u2029\"");
|
|
3932 }
|
|
3933 }
|
|
3934 if (result1 !== null) {
|
|
3935 var result0 = result1;
|
|
3936 } else {
|
|
3937 var result0 = null;;
|
|
3938 };
|
|
3939 };
|
|
3940 };
|
|
3941 };
|
|
3942 }
|
|
3943 reportMatchFailures = savedReportMatchFailures;
|
|
3944 if (reportMatchFailures && result0 === null) {
|
|
3945 matchFailed("end of line");
|
|
3946 }
|
|
3947
|
|
3948 cache[cacheKey] = {
|
|
3949 nextPos: pos,
|
|
3950 result: result0
|
|
3951 };
|
|
3952 return result0;
|
|
3953 }
|
|
3954
|
|
3955 function parse_eolChar() {
|
|
3956 var cacheKey = 'eolChar@' + pos;
|
|
3957 var cachedResult = cache[cacheKey];
|
|
3958 if (cachedResult) {
|
|
3959 pos = cachedResult.nextPos;
|
|
3960 return cachedResult.result;
|
|
3961 }
|
|
3962
|
|
3963
|
|
3964 if (input.substr(pos).match(/^[\n\r\u2028\u2029]/) !== null) {
|
|
3965 var result0 = input.charAt(pos);
|
|
3966 pos++;
|
|
3967 } else {
|
|
3968 var result0 = null;
|
|
3969 if (reportMatchFailures) {
|
|
3970 matchFailed("[\\n\\r\\u2028\\u2029]");
|
|
3971 }
|
|
3972 }
|
|
3973
|
|
3974
|
|
3975
|
|
3976 cache[cacheKey] = {
|
|
3977 nextPos: pos,
|
|
3978 result: result0
|
|
3979 };
|
|
3980 return result0;
|
|
3981 }
|
|
3982
|
|
3983 function parse_whitespace() {
|
|
3984 var cacheKey = 'whitespace@' + pos;
|
|
3985 var cachedResult = cache[cacheKey];
|
|
3986 if (cachedResult) {
|
|
3987 pos = cachedResult.nextPos;
|
|
3988 return cachedResult.result;
|
|
3989 }
|
|
3990
|
|
3991 var savedReportMatchFailures = reportMatchFailures;
|
|
3992 reportMatchFailures = false;
|
|
3993 if (input.substr(pos).match(/^[ \xA0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]/) !== null) {
|
|
3994 var result0 = input.charAt(pos);
|
|
3995 pos++;
|
|
3996 } else {
|
|
3997 var result0 = null;
|
|
3998 if (reportMatchFailures) {
|
|
3999 matchFailed("[ \\xA0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]");
|
|
4000 }
|
|
4001 }
|
|
4002 reportMatchFailures = savedReportMatchFailures;
|
|
4003 if (reportMatchFailures && result0 === null) {
|
|
4004 matchFailed("whitespace");
|
|
4005 }
|
|
4006
|
|
4007 cache[cacheKey] = {
|
|
4008 nextPos: pos,
|
|
4009 result: result0
|
|
4010 };
|
|
4011 return result0;
|
|
4012 }
|
|
4013
|
|
4014 function buildErrorMessage() {
|
|
4015 function buildExpected(failuresExpected) {
|
|
4016 failuresExpected.sort();
|
|
4017
|
|
4018 var lastFailure = null;
|
|
4019 var failuresExpectedUnique = [];
|
|
4020 for (var i = 0; i < failuresExpected.length; i++) {
|
|
4021 if (failuresExpected[i] !== lastFailure) {
|
|
4022 failuresExpectedUnique.push(failuresExpected[i]);
|
|
4023 lastFailure = failuresExpected[i];
|
|
4024 }
|
|
4025 }
|
|
4026
|
|
4027 switch (failuresExpectedUnique.length) {
|
|
4028 case 0:
|
|
4029 return 'end of input';
|
|
4030 case 1:
|
|
4031 return failuresExpectedUnique[0];
|
|
4032 default:
|
|
4033 return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(', ')
|
|
4034 + ' or '
|
|
4035 + failuresExpectedUnique[failuresExpectedUnique.length - 1];
|
|
4036 }
|
|
4037 }
|
|
4038
|
|
4039 var expected = buildExpected(rightmostMatchFailuresExpected);
|
|
4040 var actualPos = Math.max(pos, rightmostMatchFailuresPos);
|
|
4041 var actual = actualPos < input.length
|
|
4042 ? quote(input.charAt(actualPos))
|
|
4043 : 'end of input';
|
|
4044
|
|
4045 return 'Expected ' + expected + ' but ' + actual + ' found.';
|
|
4046 }
|
|
4047
|
|
4048 function computeErrorPosition() {
|
|
4049 /*
|
|
4050 * The first idea was to use |String.split| to break the input up to the
|
|
4051 * error position along newlines and derive the line and column from
|
|
4052 * there. However IE's |split| implementation is so broken that it was
|
|
4053 * enough to prevent it.
|
|
4054 */
|
|
4055
|
|
4056 var line = 1;
|
|
4057 var column = 1;
|
|
4058 var seenCR = false;
|
|
4059
|
|
4060 for (var i = 0; i < rightmostMatchFailuresPos; i++) {
|
|
4061 var ch = input.charAt(i);
|
|
4062 if (ch === '\n') {
|
|
4063 if (!seenCR) { line++; }
|
|
4064 column = 1;
|
|
4065 seenCR = false;
|
|
4066 } else if (ch === '\r' | ch === '\u2028' || ch === '\u2029') {
|
|
4067 line++;
|
|
4068 column = 1;
|
|
4069 seenCR = true;
|
|
4070 } else {
|
|
4071 column++;
|
|
4072 seenCR = false;
|
|
4073 }
|
|
4074 }
|
|
4075
|
|
4076 return { line: line, column: column };
|
|
4077 }
|
|
4078
|
|
4079
|
|
4080
|
|
4081 var result = parseFunctions[startRule]();
|
|
4082
|
|
4083 /*
|
|
4084 * The parser is now in one of the following three states:
|
|
4085 *
|
|
4086 * 1. The parser successfully parsed the whole input.
|
|
4087 *
|
|
4088 * - |result !== null|
|
|
4089 * - |pos === input.length|
|
|
4090 * - |rightmostMatchFailuresExpected| may or may not contain something
|
|
4091 *
|
|
4092 * 2. The parser successfully parsed only a part of the input.
|
|
4093 *
|
|
4094 * - |result !== null|
|
|
4095 * - |pos < input.length|
|
|
4096 * - |rightmostMatchFailuresExpected| may or may not contain something
|
|
4097 *
|
|
4098 * 3. The parser did not successfully parse any part of the input.
|
|
4099 *
|
|
4100 * - |result === null|
|
|
4101 * - |pos === 0|
|
|
4102 * - |rightmostMatchFailuresExpected| contains at least one failure
|
|
4103 *
|
|
4104 * All code following this comment (including called functions) must
|
|
4105 * handle these states.
|
|
4106 */
|
|
4107 if (result === null || pos !== input.length) {
|
|
4108 var errorPosition = computeErrorPosition();
|
|
4109 throw new this.SyntaxError(
|
|
4110 buildErrorMessage(),
|
|
4111 errorPosition.line,
|
|
4112 errorPosition.column
|
|
4113 );
|
|
4114 }
|
|
4115
|
|
4116 return result;
|
|
4117 },
|
|
4118
|
|
4119 /* Returns the parser source code. */
|
|
4120 toSource: function() { return this._source; }
|
|
4121 };
|
|
4122
|
|
4123 /* Thrown when a parser encounters a syntax error. */
|
|
4124
|
|
4125 result.SyntaxError = function(message, line, column) {
|
|
4126 this.name = 'SyntaxError';
|
|
4127 this.message = message;
|
|
4128 this.line = line;
|
|
4129 this.column = column;
|
|
4130 };
|
|
4131
|
|
4132 result.SyntaxError.prototype = Error.prototype;
|
|
4133
|
|
4134 return result;
|
|
4135 })();
|
|
4136 PEG.compiler = {
|
|
4137 /*
|
|
4138 * Generates a parser from a specified grammar AST. Throws |PEG.GrammarError|
|
|
4139 * if the AST contains a semantic error. Note that not all errors are detected
|
|
4140 * during the generation and some may protrude to the generated parser and
|
|
4141 * cause its malfunction.
|
|
4142 */
|
|
4143 compile: function(ast) {
|
|
4144 var CHECK_NAMES = [
|
|
4145 "missingReferencedRules",
|
|
4146 "leftRecursion"
|
|
4147 ];
|
|
4148
|
|
4149 var PASS_NAMES = [
|
|
4150 "proxyRules"
|
|
4151 ];
|
|
4152
|
|
4153 for (var i = 0; i < CHECK_NAMES.length; i++) {
|
|
4154 this.checks[CHECK_NAMES[i]](ast);
|
|
4155 }
|
|
4156
|
|
4157 for (var i = 0; i < PASS_NAMES.length; i++) {
|
|
4158 ast = this.passes[PASS_NAMES[i]](ast);
|
|
4159 }
|
|
4160
|
|
4161 var source = this.emitter(ast);
|
|
4162 var result = eval(source);
|
|
4163 result._source = source;
|
|
4164
|
|
4165 return result;
|
|
4166 }
|
|
4167 };
|
|
4168
|
|
4169 /*
|
|
4170 * Checks made on the grammar AST before compilation. Each check is a function
|
|
4171 * that is passed the AST and does not return anything. If the check passes, the
|
|
4172 * function does not do anything special, otherwise it throws
|
|
4173 * |PEG.GrammarError|. The order in which the checks are run is specified in
|
|
4174 * |PEG.compiler.compile| and should be the same as the order of definitions
|
|
4175 * here.
|
|
4176 */
|
|
4177 PEG.compiler.checks = {
|
|
4178 /* Checks that all referenced rules exist. */
|
|
4179 missingReferencedRules: function(ast) {
|
|
4180 function nop() {}
|
|
4181
|
|
4182 function checkExpression(node) { check(node.expression); }
|
|
4183
|
|
4184 function checkSubnodes(propertyName) {
|
|
4185 return function(node) { each(node[propertyName], check); };
|
|
4186 }
|
|
4187
|
|
4188 var check = buildNodeVisitor({
|
|
4189 grammar:
|
|
4190 function(node) {
|
|
4191 for (var name in node.rules) {
|
|
4192 check(node.rules[name]);
|
|
4193 }
|
|
4194 },
|
|
4195
|
|
4196 rule: checkExpression,
|
|
4197 choice: checkSubnodes("alternatives"),
|
|
4198 sequence: checkSubnodes("elements"),
|
|
4199 labeled: checkExpression,
|
|
4200 simple_and: checkExpression,
|
|
4201 simple_not: checkExpression,
|
|
4202 semantic_and: nop,
|
|
4203 semantic_not: nop,
|
|
4204 optional: checkExpression,
|
|
4205 zero_or_more: checkExpression,
|
|
4206 one_or_more: checkExpression,
|
|
4207 action: checkExpression,
|
|
4208
|
|
4209 rule_ref:
|
|
4210 function(node) {
|
|
4211 if (ast.rules[node.name] === undefined) {
|
|
4212 throw new PEG.GrammarError(
|
|
4213 "Referenced rule \"" + node.name + "\" does not exist."
|
|
4214 );
|
|
4215 }
|
|
4216 },
|
|
4217
|
|
4218 literal: nop,
|
|
4219 any: nop,
|
|
4220 "class": nop
|
|
4221 });
|
|
4222
|
|
4223 check(ast);
|
|
4224 },
|
|
4225
|
|
4226 /* Checks that no left recursion is present. */
|
|
4227 leftRecursion: function(ast) {
|
|
4228 function nop() {}
|
|
4229
|
|
4230 function checkExpression(node, appliedRules) {
|
|
4231 check(node.expression, appliedRules);
|
|
4232 }
|
|
4233
|
|
4234 var check = buildNodeVisitor({
|
|
4235 grammar:
|
|
4236 function(node, appliedRules) {
|
|
4237 for (var name in node.rules) {
|
|
4238 check(node.rules[name], appliedRules);
|
|
4239 }
|
|
4240 },
|
|
4241
|
|
4242 rule:
|
|
4243 function(node, appliedRules) {
|
|
4244 check(node.expression, appliedRules.concat(node.name));
|
|
4245 },
|
|
4246
|
|
4247 choice:
|
|
4248 function(node, appliedRules) {
|
|
4249 each(node.alternatives, function(alternative) {
|
|
4250 check(alternative, appliedRules);
|
|
4251 });
|
|
4252 },
|
|
4253
|
|
4254 sequence:
|
|
4255 function(node, appliedRules) {
|
|
4256 if (node.elements.length > 0) {
|
|
4257 check(node.elements[0], appliedRules);
|
|
4258 }
|
|
4259 },
|
|
4260
|
|
4261 labeled: checkExpression,
|
|
4262 simple_and: checkExpression,
|
|
4263 simple_not: checkExpression,
|
|
4264 semantic_and: nop,
|
|
4265 semantic_not: nop,
|
|
4266 optional: checkExpression,
|
|
4267 zero_or_more: checkExpression,
|
|
4268 one_or_more: checkExpression,
|
|
4269 action: checkExpression,
|
|
4270
|
|
4271 rule_ref:
|
|
4272 function(node, appliedRules) {
|
|
4273 if (contains(appliedRules, node.name)) {
|
|
4274 throw new PEG.GrammarError(
|
|
4275 "Left recursion detected for rule \"" + node.name + "\"."
|
|
4276 );
|
|
4277 }
|
|
4278 check(ast.rules[node.name], appliedRules);
|
|
4279 },
|
|
4280
|
|
4281 literal: nop,
|
|
4282 any: nop,
|
|
4283 "class": nop
|
|
4284 });
|
|
4285
|
|
4286 check(ast, []);
|
|
4287 }
|
|
4288 };
|
|
4289 /*
|
|
4290 * Optimalization passes made on the grammar AST before compilation. Each pass
|
|
4291 * is a function that is passed the AST and returns a new AST. The AST can be
|
|
4292 * modified in-place by the pass. The order in which the passes are run is
|
|
4293 * specified in |PEG.compiler.compile| and should be the same as the order of
|
|
4294 * definitions here.
|
|
4295 */
|
|
4296 PEG.compiler.passes = {
|
|
4297 /*
|
|
4298 * Removes proxy rules -- that is, rules that only delegate to other rule.
|
|
4299 */
|
|
4300 proxyRules: function(ast) {
|
|
4301 function isProxyRule(node) {
|
|
4302 return node.type === "rule" && node.expression.type === "rule_ref";
|
|
4303 }
|
|
4304
|
|
4305 function replaceRuleRefs(ast, from, to) {
|
|
4306 function nop() {}
|
|
4307
|
|
4308 function replaceInExpression(node, from, to) {
|
|
4309 replace(node.expression, from, to);
|
|
4310 }
|
|
4311
|
|
4312 function replaceInSubnodes(propertyName) {
|
|
4313 return function(node, from, to) {
|
|
4314 each(node[propertyName], function(subnode) {
|
|
4315 replace(subnode, from, to);
|
|
4316 });
|
|
4317 };
|
|
4318 }
|
|
4319
|
|
4320 var replace = buildNodeVisitor({
|
|
4321 grammar:
|
|
4322 function(node, from, to) {
|
|
4323 for (var name in node.rules) {
|
|
4324 replace(node.rules[name], from, to);
|
|
4325 }
|
|
4326 },
|
|
4327
|
|
4328 rule: replaceInExpression,
|
|
4329 choice: replaceInSubnodes("alternatives"),
|
|
4330 sequence: replaceInSubnodes("elements"),
|
|
4331 labeled: replaceInExpression,
|
|
4332 simple_and: replaceInExpression,
|
|
4333 simple_not: replaceInExpression,
|
|
4334 semantic_and: nop,
|
|
4335 semantic_not: nop,
|
|
4336 optional: replaceInExpression,
|
|
4337 zero_or_more: replaceInExpression,
|
|
4338 one_or_more: replaceInExpression,
|
|
4339 action: replaceInExpression,
|
|
4340
|
|
4341 rule_ref:
|
|
4342 function(node, from, to) {
|
|
4343 if (node.name === from) {
|
|
4344 node.name = to;
|
|
4345 }
|
|
4346 },
|
|
4347
|
|
4348 literal: nop,
|
|
4349 any: nop,
|
|
4350 "class": nop
|
|
4351 });
|
|
4352
|
|
4353 replace(ast, from, to);
|
|
4354 }
|
|
4355
|
|
4356 for (var name in ast.rules) {
|
|
4357 if (isProxyRule(ast.rules[name])) {
|
|
4358 replaceRuleRefs(ast, ast.rules[name].name, ast.rules[name].expression.name);
|
|
4359 if (name === ast.startRule) {
|
|
4360 ast.startRule = ast.rules[name].expression.name;
|
|
4361 }
|
|
4362 delete ast.rules[name];
|
|
4363 }
|
|
4364 }
|
|
4365
|
|
4366 return ast;
|
|
4367 }
|
|
4368 };
|
|
4369 /* Emits the generated code for the AST. */
|
|
4370 PEG.compiler.emitter = function(ast) {
|
|
4371 /*
|
|
4372 * Takes parts of code, interpolates variables inside them and joins them with
|
|
4373 * a newline.
|
|
4374 *
|
|
4375 * Variables are delimited with "${" and "}" and their names must be valid
|
|
4376 * identifiers (i.e. they must match [a-zA-Z_][a-zA-Z0-9_]*). Variable values
|
|
4377 * are specified as properties of the last parameter (if this is an object,
|
|
4378 * otherwise empty variable set is assumed). Undefined variables result in
|
|
4379 * throwing |Error|.
|
|
4380 *
|
|
4381 * There can be a filter specified after the variable name, prefixed with "|".
|
|
4382 * The filter name must be a valid identifier. The only recognized filter
|
|
4383 * right now is "string", which quotes the variable value as a JavaScript
|
|
4384 * string. Unrecognized filters result in throwing |Error|.
|
|
4385 *
|
|
4386 * If any part has multiple lines and the first line is indented by some
|
|
4387 * amount of whitespace (as defined by the /\s+/ JavaScript regular
|
|
4388 * expression), second to last lines are indented by the same amount of
|
|
4389 * whitespace. This results in nicely indented multiline code in variables
|
|
4390 * without making the templates look ugly.
|
|
4391 *
|
|
4392 * Examples:
|
|
4393 *
|
|
4394 * formatCode("foo", "bar"); // "foo\nbar"
|
|
4395 * formatCode("foo", "${bar}", { bar: "baz" }); // "foo\nbaz"
|
|
4396 * formatCode("foo", "${bar}"); // throws Error
|
|
4397 * formatCode("foo", "${bar|string}", { bar: "baz" }); // "foo\n\"baz\""
|
|
4398 * formatCode("foo", "${bar|eeek}", { bar: "baz" }); // throws Error
|
|
4399 * formatCode("foo", "${bar}", { bar: " baz\nqux" }); // "foo\n baz\n qux"
|
|
4400 */
|
|
4401 function formatCode() {
|
|
4402 function interpolateVariablesInParts(parts) {
|
|
4403 return map(parts, function(part) {
|
|
4404 return part.replace(
|
|
4405 /\$\{([a-zA-Z_][a-zA-Z0-9_]*)(\|([a-zA-Z_][a-zA-Z0-9_]*))?\}/g,
|
|
4406 function(match, name, dummy, filter) {
|
|
4407 var value = vars[name];
|
|
4408 if (value === undefined) {
|
|
4409 throw new Error("Undefined variable: \"" + name + "\".");
|
|
4410 }
|
|
4411
|
|
4412 if (filter !== undefined && filter != "") { // JavaScript engines differ here.
|
|
4413 if (filter === "string") {
|
|
4414 return quote(value);
|
|
4415 } else {
|
|
4416 throw new Error("Unrecognized filter: \"" + filter + "\".");
|
|
4417 }
|
|
4418 } else {
|
|
4419 return value;
|
|
4420 }
|
|
4421 }
|
|
4422 );
|
|
4423 });
|
|
4424 }
|
|
4425
|
|
4426 function indentMultilineParts(parts) {
|
|
4427 return map(parts, function(part) {
|
|
4428 if (!/\n/.test(part)) { return part; }
|
|
4429
|
|
4430 var firstLineWhitespacePrefix = part.match(/^\s*/)[0];
|
|
4431 var lines = part.split("\n");
|
|
4432 var linesIndented = [lines[0]].concat(
|
|
4433 map(lines.slice(1), function(line) {
|
|
4434 return firstLineWhitespacePrefix + line;
|
|
4435 })
|
|
4436 );
|
|
4437 return linesIndented.join("\n");
|
|
4438 });
|
|
4439 }
|
|
4440
|
|
4441 var args = Array.prototype.slice.call(arguments);
|
|
4442 var vars = args[args.length - 1] instanceof Object ? args.pop() : {};
|
|
4443
|
|
4444 return indentMultilineParts(interpolateVariablesInParts(args)).join("\n");
|
|
4445 };
|
|
4446
|
|
4447 /* Unique ID generator. */
|
|
4448 var UID = {
|
|
4449 _counters: {},
|
|
4450
|
|
4451 next: function(prefix) {
|
|
4452 this._counters[prefix] = this._counters[prefix] || 0;
|
|
4453 return prefix + this._counters[prefix]++;
|
|
4454 },
|
|
4455
|
|
4456 reset: function() {
|
|
4457 this._counters = {};
|
|
4458 }
|
|
4459 };
|
|
4460
|
|
4461 var emit = buildNodeVisitor({
|
|
4462 grammar: function(node) {
|
|
4463 var initializerCode = node.initializer !== null
|
|
4464 ? emit(node.initializer)
|
|
4465 : "";
|
|
4466
|
|
4467 var parseFunctionTableItems = [];
|
|
4468 for (var name in node.rules) {
|
|
4469 parseFunctionTableItems.push(quote(name) + ": parse_" + name);
|
|
4470 }
|
|
4471 parseFunctionTableItems.sort();
|
|
4472
|
|
4473 var parseFunctionDefinitions = [];
|
|
4474 for (var name in node.rules) {
|
|
4475 parseFunctionDefinitions.push(emit(node.rules[name]));
|
|
4476 }
|
|
4477
|
|
4478 return formatCode(
|
|
4479 "(function(){",
|
|
4480 " /* Generated by PEG.js 0.6.2 (http://pegjs.majda.cz/). */",
|
|
4481 " ",
|
|
4482 " var result = {",
|
|
4483 " /*",
|
|
4484 " * Parses the input with a generated parser. If the parsing is successfull,",
|
|
4485 " * returns a value explicitly or implicitly specified by the grammar from",
|
|
4486 " * which the parser was generated (see |PEG.buildParser|). If the parsing is",
|
|
4487 " * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.",
|
|
4488 " */",
|
|
4489 " parse: function(input, startRule) {",
|
|
4490 " var parseFunctions = {",
|
|
4491 " ${parseFunctionTableItems}",
|
|
4492 " };",
|
|
4493 " ",
|
|
4494 " if (startRule !== undefined) {",
|
|
4495 " if (parseFunctions[startRule] === undefined) {",
|
|
4496 " throw new Error(\"Invalid rule name: \" + quote(startRule) + \".\");",
|
|
4497 " }",
|
|
4498 " } else {",
|
|
4499 " startRule = ${startRule|string};",
|
|
4500 " }",
|
|
4501 " ",
|
|
4502 " var pos = 0;",
|
|
4503 " var reportMatchFailures = true;",
|
|
4504 " var rightmostMatchFailuresPos = 0;",
|
|
4505 " var rightmostMatchFailuresExpected = [];",
|
|
4506 " var cache = {};",
|
|
4507 " ",
|
|
4508 /* This needs to be in sync with |padLeft| in utils.js. */
|
|
4509 " function padLeft(input, padding, length) {",
|
|
4510 " var result = input;",
|
|
4511 " ",
|
|
4512 " var padLength = length - input.length;",
|
|
4513 " for (var i = 0; i < padLength; i++) {",
|
|
4514 " result = padding + result;",
|
|
4515 " }",
|
|
4516 " ",
|
|
4517 " return result;",
|
|
4518 " }",
|
|
4519 " ",
|
|
4520 /* This needs to be in sync with |escape| in utils.js. */
|
|
4521 " function escape(ch) {",
|
|
4522 " var charCode = ch.charCodeAt(0);",
|
|
4523 " ",
|
|
4524 " if (charCode <= 0xFF) {",
|
|
4525 " var escapeChar = 'x';",
|
|
4526 " var length = 2;",
|
|
4527 " } else {",
|
|
4528 " var escapeChar = 'u';",
|
|
4529 " var length = 4;",
|
|
4530 " }",
|
|
4531 " ",
|
|
4532 " return '\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);",
|
|
4533 " }",
|
|
4534 " ",
|
|
4535 /* This needs to be in sync with |quote| in utils.js. */
|
|
4536 " function quote(s) {",
|
|
4537 " /*",
|
|
4538 " * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a",
|
|
4539 " * string literal except for the closing quote character, backslash,",
|
|
4540 " * carriage return, line separator, paragraph separator, and line feed.",
|
|
4541 " * Any character may appear in the form of an escape sequence.",
|
|
4542 " */",
|
|
4543 " return '\"' + s",
|
|
4544 " .replace(/\\\\/g, '\\\\\\\\') // backslash",
|
|
4545 " .replace(/\"/g, '\\\\\"') // closing quote character",
|
|
4546 " .replace(/\\r/g, '\\\\r') // carriage return",
|
|
4547 " .replace(/\\n/g, '\\\\n') // line feed",
|
|
4548 " .replace(/[\\x80-\\uFFFF]/g, escape) // non-ASCII characters",
|
|
4549 " + '\"';",
|
|
4550 " }",
|
|
4551 " ",
|
|
4552 " function matchFailed(failure) {",
|
|
4553 " if (pos < rightmostMatchFailuresPos) {",
|
|
4554 " return;",
|
|
4555 " }",
|
|
4556 " ",
|
|
4557 " if (pos > rightmostMatchFailuresPos) {",
|
|
4558 " rightmostMatchFailuresPos = pos;",
|
|
4559 " rightmostMatchFailuresExpected = [];",
|
|
4560 " }",
|
|
4561 " ",
|
|
4562 " rightmostMatchFailuresExpected.push(failure);",
|
|
4563 " }",
|
|
4564 " ",
|
|
4565 " ${parseFunctionDefinitions}",
|
|
4566 " ",
|
|
4567 " function buildErrorMessage() {",
|
|
4568 " function buildExpected(failuresExpected) {",
|
|
4569 " failuresExpected.sort();",
|
|
4570 " ",
|
|
4571 " var lastFailure = null;",
|
|
4572 " var failuresExpectedUnique = [];",
|
|
4573 " for (var i = 0; i < failuresExpected.length; i++) {",
|
|
4574 " if (failuresExpected[i] !== lastFailure) {",
|
|
4575 " failuresExpectedUnique.push(failuresExpected[i]);",
|
|
4576 " lastFailure = failuresExpected[i];",
|
|
4577 " }",
|
|
4578 " }",
|
|
4579 " ",
|
|
4580 " switch (failuresExpectedUnique.length) {",
|
|
4581 " case 0:",
|
|
4582 " return 'end of input';",
|
|
4583 " case 1:",
|
|
4584 " return failuresExpectedUnique[0];",
|
|
4585 " default:",
|
|
4586 " return failuresExpectedUnique.slice(0, failuresExpectedUnique.length - 1).join(', ')",
|
|
4587 " + ' or '",
|
|
4588 " + failuresExpectedUnique[failuresExpectedUnique.length - 1];",
|
|
4589 " }",
|
|
4590 " }",
|
|
4591 " ",
|
|
4592 " var expected = buildExpected(rightmostMatchFailuresExpected);",
|
|
4593 " var actualPos = Math.max(pos, rightmostMatchFailuresPos);",
|
|
4594 " var actual = actualPos < input.length",
|
|
4595 " ? quote(input.charAt(actualPos))",
|
|
4596 " : 'end of input';",
|
|
4597 " ",
|
|
4598 " return 'Expected ' + expected + ' but ' + actual + ' found.';",
|
|
4599 " }",
|
|
4600 " ",
|
|
4601 " function computeErrorPosition() {",
|
|
4602 " /*",
|
|
4603 " * The first idea was to use |String.split| to break the input up to the",
|
|
4604 " * error position along newlines and derive the line and column from",
|
|
4605 " * there. However IE's |split| implementation is so broken that it was",
|
|
4606 " * enough to prevent it.",
|
|
4607 " */",
|
|
4608 " ",
|
|
4609 " var line = 1;",
|
|
4610 " var column = 1;",
|
|
4611 " var seenCR = false;",
|
|
4612 " ",
|
|
4613 " for (var i = 0; i < rightmostMatchFailuresPos; i++) {",
|
|
4614 " var ch = input.charAt(i);",
|
|
4615 " if (ch === '\\n') {",
|
|
4616 " if (!seenCR) { line++; }",
|
|
4617 " column = 1;",
|
|
4618 " seenCR = false;",
|
|
4619 " } else if (ch === '\\r' | ch === '\\u2028' || ch === '\\u2029') {",
|
|
4620 " line++;",
|
|
4621 " column = 1;",
|
|
4622 " seenCR = true;",
|
|
4623 " } else {",
|
|
4624 " column++;",
|
|
4625 " seenCR = false;",
|
|
4626 " }",
|
|
4627 " }",
|
|
4628 " ",
|
|
4629 " return { line: line, column: column };",
|
|
4630 " }",
|
|
4631 " ",
|
|
4632 " ${initializerCode}",
|
|
4633 " ",
|
|
4634 " var result = parseFunctions[startRule]();",
|
|
4635 " ",
|
|
4636 " /*",
|
|
4637 " * The parser is now in one of the following three states:",
|
|
4638 " *",
|
|
4639 " * 1. The parser successfully parsed the whole input.",
|
|
4640 " *",
|
|
4641 " * - |result !== null|",
|
|
4642 " * - |pos === input.length|",
|
|
4643 " * - |rightmostMatchFailuresExpected| may or may not contain something",
|
|
4644 " *",
|
|
4645 " * 2. The parser successfully parsed only a part of the input.",
|
|
4646 " *",
|
|
4647 " * - |result !== null|",
|
|
4648 " * - |pos < input.length|",
|
|
4649 " * - |rightmostMatchFailuresExpected| may or may not contain something",
|
|
4650 " *",
|
|
4651 " * 3. The parser did not successfully parse any part of the input.",
|
|
4652 " *",
|
|
4653 " * - |result === null|",
|
|
4654 " * - |pos === 0|",
|
|
4655 " * - |rightmostMatchFailuresExpected| contains at least one failure",
|
|
4656 " *",
|
|
4657 " * All code following this comment (including called functions) must",
|
|
4658 " * handle these states.",
|
|
4659 " */",
|
|
4660 " if (result === null || pos !== input.length) {",
|
|
4661 " var errorPosition = computeErrorPosition();",
|
|
4662 " throw new this.SyntaxError(",
|
|
4663 " buildErrorMessage(),",
|
|
4664 " errorPosition.line,",
|
|
4665 " errorPosition.column",
|
|
4666 " );",
|
|
4667 " }",
|
|
4668 " ",
|
|
4669 " return result;",
|
|
4670 " },",
|
|
4671 " ",
|
|
4672 " /* Returns the parser source code. */",
|
|
4673 " toSource: function() { return this._source; }",
|
|
4674 " };",
|
|
4675 " ",
|
|
4676 " /* Thrown when a parser encounters a syntax error. */",
|
|
4677 " ",
|
|
4678 " result.SyntaxError = function(message, line, column) {",
|
|
4679 " this.name = 'SyntaxError';",
|
|
4680 " this.message = message;",
|
|
4681 " this.line = line;",
|
|
4682 " this.column = column;",
|
|
4683 " };",
|
|
4684 " ",
|
|
4685 " result.SyntaxError.prototype = Error.prototype;",
|
|
4686 " ",
|
|
4687 " return result;",
|
|
4688 "})()",
|
|
4689 {
|
|
4690 initializerCode: initializerCode,
|
|
4691 parseFunctionTableItems: parseFunctionTableItems.join(",\n"),
|
|
4692 parseFunctionDefinitions: parseFunctionDefinitions.join("\n\n"),
|
|
4693 startRule: node.startRule
|
|
4694 }
|
|
4695 );
|
|
4696 },
|
|
4697
|
|
4698 initializer: function(node) {
|
|
4699 return node.code;
|
|
4700 },
|
|
4701
|
|
4702 rule: function(node) {
|
|
4703 /*
|
|
4704 * We want to reset variable names at the beginning of every function so
|
|
4705 * that a little change in the source grammar does not change variables in
|
|
4706 * all the generated code. This is desired especially when one has the
|
|
4707 * generated grammar stored in a VCS (this is true e.g. for our
|
|
4708 * metagrammar).
|
|
4709 */
|
|
4710 UID.reset();
|
|
4711
|
|
4712 var resultVar = UID.next("result");
|
|
4713
|
|
4714 if (node.displayName !== null) {
|
|
4715 var setReportMatchFailuresCode = formatCode(
|
|
4716 "var savedReportMatchFailures = reportMatchFailures;",
|
|
4717 "reportMatchFailures = false;"
|
|
4718 );
|
|
4719 var restoreReportMatchFailuresCode = formatCode(
|
|
4720 "reportMatchFailures = savedReportMatchFailures;"
|
|
4721 );
|
|
4722 var reportMatchFailureCode = formatCode(
|
|
4723 "if (reportMatchFailures && ${resultVar} === null) {",
|
|
4724 " matchFailed(${displayName|string});",
|
|
4725 "}",
|
|
4726 {
|
|
4727 displayName: node.displayName,
|
|
4728 resultVar: resultVar
|
|
4729 }
|
|
4730 );
|
|
4731 } else {
|
|
4732 var setReportMatchFailuresCode = "";
|
|
4733 var restoreReportMatchFailuresCode = "";
|
|
4734 var reportMatchFailureCode = "";
|
|
4735 }
|
|
4736
|
|
4737 return formatCode(
|
|
4738 "function parse_${name}() {",
|
|
4739 " var cacheKey = '${name}@' + pos;",
|
|
4740 " var cachedResult = cache[cacheKey];",
|
|
4741 " if (cachedResult) {",
|
|
4742 " pos = cachedResult.nextPos;",
|
|
4743 " return cachedResult.result;",
|
|
4744 " }",
|
|
4745 " ",
|
|
4746 " ${setReportMatchFailuresCode}",
|
|
4747 " ${code}",
|
|
4748 " ${restoreReportMatchFailuresCode}",
|
|
4749 " ${reportMatchFailureCode}",
|
|
4750 " ",
|
|
4751 " cache[cacheKey] = {",
|
|
4752 " nextPos: pos,",
|
|
4753 " result: ${resultVar}",
|
|
4754 " };",
|
|
4755 " return ${resultVar};",
|
|
4756 "}",
|
|
4757 {
|
|
4758 name: node.name,
|
|
4759 setReportMatchFailuresCode: setReportMatchFailuresCode,
|
|
4760 restoreReportMatchFailuresCode: restoreReportMatchFailuresCode,
|
|
4761 reportMatchFailureCode: reportMatchFailureCode,
|
|
4762 code: emit(node.expression, resultVar),
|
|
4763 resultVar: resultVar
|
|
4764 }
|
|
4765 );
|
|
4766 },
|
|
4767
|
|
4768 /*
|
|
4769 * The contract for all code fragments generated by the following functions
|
|
4770 * is as follows:
|
|
4771 *
|
|
4772 * * The code fragment should try to match a part of the input starting with
|
|
4773 * the position indicated in |pos|. That position may point past the end of
|
|
4774 * the input.
|
|
4775 *
|
|
4776 * * If the code fragment matches the input, it advances |pos| after the
|
|
4777 * matched part of the input and sets variable with a name stored in
|
|
4778 * |resultVar| to appropriate value, which is always non-null.
|
|
4779 *
|
|
4780 * * If the code fragment does not match the input, it does not change |pos|
|
|
4781 * and it sets a variable with a name stored in |resultVar| to |null|.
|
|
4782 */
|
|
4783
|
|
4784 choice: function(node, resultVar) {
|
|
4785 var code = formatCode(
|
|
4786 "var ${resultVar} = null;",
|
|
4787 { resultVar: resultVar }
|
|
4788 );
|
|
4789
|
|
4790 for (var i = node.alternatives.length - 1; i >= 0; i--) {
|
|
4791 var alternativeResultVar = UID.next("result");
|
|
4792 code = formatCode(
|
|
4793 "${alternativeCode}",
|
|
4794 "if (${alternativeResultVar} !== null) {",
|
|
4795 " var ${resultVar} = ${alternativeResultVar};",
|
|
4796 "} else {",
|
|
4797 " ${code};",
|
|
4798 "}",
|
|
4799 {
|
|
4800 alternativeCode: emit(node.alternatives[i], alternativeResultVar),
|
|
4801 alternativeResultVar: alternativeResultVar,
|
|
4802 code: code,
|
|
4803 resultVar: resultVar
|
|
4804 }
|
|
4805 );
|
|
4806 }
|
|
4807
|
|
4808 return code;
|
|
4809 },
|
|
4810
|
|
4811 sequence: function(node, resultVar) {
|
|
4812 var savedPosVar = UID.next("savedPos");
|
|
4813
|
|
4814 var elementResultVars = map(node.elements, function() {
|
|
4815 return UID.next("result")
|
|
4816 });
|
|
4817
|
|
4818 var code = formatCode(
|
|
4819 "var ${resultVar} = ${elementResultVarArray};",
|
|
4820 {
|
|
4821 resultVar: resultVar,
|
|
4822 elementResultVarArray: "[" + elementResultVars.join(", ") + "]"
|
|
4823 }
|
|
4824 );
|
|
4825
|
|
4826 for (var i = node.elements.length - 1; i >= 0; i--) {
|
|
4827 code = formatCode(
|
|
4828 "${elementCode}",
|
|
4829 "if (${elementResultVar} !== null) {",
|
|
4830 " ${code}",
|
|
4831 "} else {",
|
|
4832 " var ${resultVar} = null;",
|
|
4833 " pos = ${savedPosVar};",
|
|
4834 "}",
|
|
4835 {
|
|
4836 elementCode: emit(node.elements[i], elementResultVars[i]),
|
|
4837 elementResultVar: elementResultVars[i],
|
|
4838 code: code,
|
|
4839 savedPosVar: savedPosVar,
|
|
4840 resultVar: resultVar
|
|
4841 }
|
|
4842 );
|
|
4843 }
|
|
4844
|
|
4845 return formatCode(
|
|
4846 "var ${savedPosVar} = pos;",
|
|
4847 "${code}",
|
|
4848 {
|
|
4849 code: code,
|
|
4850 savedPosVar: savedPosVar
|
|
4851 }
|
|
4852 );
|
|
4853 },
|
|
4854
|
|
4855 labeled: function(node, resultVar) {
|
|
4856 return emit(node.expression, resultVar);
|
|
4857 },
|
|
4858
|
|
4859 simple_and: function(node, resultVar) {
|
|
4860 var savedPosVar = UID.next("savedPos");
|
|
4861 var savedReportMatchFailuresVar = UID.next("savedReportMatchFailuresVar");
|
|
4862 var expressionResultVar = UID.next("result");
|
|
4863
|
|
4864 return formatCode(
|
|
4865 "var ${savedPosVar} = pos;",
|
|
4866 "var ${savedReportMatchFailuresVar} = reportMatchFailures;",
|
|
4867 "reportMatchFailures = false;",
|
|
4868 "${expressionCode}",
|
|
4869 "reportMatchFailures = ${savedReportMatchFailuresVar};",
|
|
4870 "if (${expressionResultVar} !== null) {",
|
|
4871 " var ${resultVar} = '';",
|
|
4872 " pos = ${savedPosVar};",
|
|
4873 "} else {",
|
|
4874 " var ${resultVar} = null;",
|
|
4875 "}",
|
|
4876 {
|
|
4877 expressionCode: emit(node.expression, expressionResultVar),
|
|
4878 expressionResultVar: expressionResultVar,
|
|
4879 savedPosVar: savedPosVar,
|
|
4880 savedReportMatchFailuresVar: savedReportMatchFailuresVar,
|
|
4881 resultVar: resultVar
|
|
4882 }
|
|
4883 );
|
|
4884 },
|
|
4885
|
|
4886 simple_not: function(node, resultVar) {
|
|
4887 var savedPosVar = UID.next("savedPos");
|
|
4888 var savedReportMatchFailuresVar = UID.next("savedReportMatchFailuresVar");
|
|
4889 var expressionResultVar = UID.next("result");
|
|
4890
|
|
4891 return formatCode(
|
|
4892 "var ${savedPosVar} = pos;",
|
|
4893 "var ${savedReportMatchFailuresVar} = reportMatchFailures;",
|
|
4894 "reportMatchFailures = false;",
|
|
4895 "${expressionCode}",
|
|
4896 "reportMatchFailures = ${savedReportMatchFailuresVar};",
|
|
4897 "if (${expressionResultVar} === null) {",
|
|
4898 " var ${resultVar} = '';",
|
|
4899 "} else {",
|
|
4900 " var ${resultVar} = null;",
|
|
4901 " pos = ${savedPosVar};",
|
|
4902 "}",
|
|
4903 {
|
|
4904 expressionCode: emit(node.expression, expressionResultVar),
|
|
4905 expressionResultVar: expressionResultVar,
|
|
4906 savedPosVar: savedPosVar,
|
|
4907 savedReportMatchFailuresVar: savedReportMatchFailuresVar,
|
|
4908 resultVar: resultVar
|
|
4909 }
|
|
4910 );
|
|
4911 },
|
|
4912
|
|
4913 semantic_and: function(node, resultVar) {
|
|
4914 return formatCode(
|
|
4915 "var ${resultVar} = (function() {${actionCode}})() ? '' : null;",
|
|
4916 {
|
|
4917 actionCode: node.code,
|
|
4918 resultVar: resultVar
|
|
4919 }
|
|
4920 );
|
|
4921 },
|
|
4922
|
|
4923 semantic_not: function(node, resultVar) {
|
|
4924 return formatCode(
|
|
4925 "var ${resultVar} = (function() {${actionCode}})() ? null : '';",
|
|
4926 {
|
|
4927 actionCode: node.code,
|
|
4928 resultVar: resultVar
|
|
4929 }
|
|
4930 );
|
|
4931 },
|
|
4932
|
|
4933 optional: function(node, resultVar) {
|
|
4934 var expressionResultVar = UID.next("result");
|
|
4935
|
|
4936 return formatCode(
|
|
4937 "${expressionCode}",
|
|
4938 "var ${resultVar} = ${expressionResultVar} !== null ? ${expressionResultVar} : '';",
|
|
4939 {
|
|
4940 expressionCode: emit(node.expression, expressionResultVar),
|
|
4941 expressionResultVar: expressionResultVar,
|
|
4942 resultVar: resultVar
|
|
4943 }
|
|
4944 );
|
|
4945 },
|
|
4946
|
|
4947 zero_or_more: function(node, resultVar) {
|
|
4948 var expressionResultVar = UID.next("result");
|
|
4949
|
|
4950 return formatCode(
|
|
4951 "var ${resultVar} = [];",
|
|
4952 "${expressionCode}",
|
|
4953 "while (${expressionResultVar} !== null) {",
|
|
4954 " ${resultVar}.push(${expressionResultVar});",
|
|
4955 " ${expressionCode}",
|
|
4956 "}",
|
|
4957 {
|
|
4958 expressionCode: emit(node.expression, expressionResultVar),
|
|
4959 expressionResultVar: expressionResultVar,
|
|
4960 resultVar: resultVar
|
|
4961 }
|
|
4962 );
|
|
4963 },
|
|
4964
|
|
4965 one_or_more: function(node, resultVar) {
|
|
4966 var expressionResultVar = UID.next("result");
|
|
4967
|
|
4968 return formatCode(
|
|
4969 "${expressionCode}",
|
|
4970 "if (${expressionResultVar} !== null) {",
|
|
4971 " var ${resultVar} = [];",
|
|
4972 " while (${expressionResultVar} !== null) {",
|
|
4973 " ${resultVar}.push(${expressionResultVar});",
|
|
4974 " ${expressionCode}",
|
|
4975 " }",
|
|
4976 "} else {",
|
|
4977 " var ${resultVar} = null;",
|
|
4978 "}",
|
|
4979 {
|
|
4980 expressionCode: emit(node.expression, expressionResultVar),
|
|
4981 expressionResultVar: expressionResultVar,
|
|
4982 resultVar: resultVar
|
|
4983 }
|
|
4984 );
|
|
4985 },
|
|
4986
|
|
4987 action: function(node, resultVar) {
|
|
4988 /*
|
|
4989 * In case of sequences, we splat their elements into function arguments
|
|
4990 * one by one. Example:
|
|
4991 *
|
|
4992 * start: a:"a" b:"b" c:"c" { alert(arguments.length) } // => 3
|
|
4993 *
|
|
4994 * This behavior is reflected in this function.
|
|
4995 */
|
|
4996
|
|
4997 var expressionResultVar = UID.next("result");
|
|
4998 var actionResultVar = UID.next("result");
|
|
4999 var savedPosVar = UID.next("savedPos");
|
|
5000
|
|
5001 if (node.expression.type === "sequence") {
|
|
5002 var formalParams = [];
|
|
5003 var actualParams = [];
|
|
5004
|
|
5005 var elements = node.expression.elements;
|
|
5006 var elementsLength = elements.length;
|
|
5007 for (var i = 0; i < elementsLength; i++) {
|
|
5008 if (elements[i].type === "labeled") {
|
|
5009 formalParams.push(elements[i].label);
|
|
5010 actualParams.push(expressionResultVar + "[" + i + "]");
|
|
5011 }
|
|
5012 }
|
|
5013 } else if (node.expression.type === "labeled") {
|
|
5014 var formalParams = [node.expression.label];
|
|
5015 var actualParams = [expressionResultVar];
|
|
5016 } else {
|
|
5017 var formalParams = [];
|
|
5018 var actualParams = [];
|
|
5019 }
|
|
5020
|
|
5021 return formatCode(
|
|
5022 "var ${savedPosVar} = pos;",
|
|
5023 "${expressionCode}",
|
|
5024 "var ${actionResultVar} = ${expressionResultVar} !== null",
|
|
5025 " ? (function(${formalParams}) {${actionCode}})(${actualParams})",
|
|
5026 " : null;",
|
|
5027 "if (${actionResultVar} !== null) {",
|
|
5028 " var ${resultVar} = ${actionResultVar};",
|
|
5029 "} else {",
|
|
5030 " var ${resultVar} = null;",
|
|
5031 " pos = ${savedPosVar};",
|
|
5032 "}",
|
|
5033 {
|
|
5034 expressionCode: emit(node.expression, expressionResultVar),
|
|
5035 expressionResultVar: expressionResultVar,
|
|
5036 actionCode: node.code,
|
|
5037 actionResultVar: actionResultVar,
|
|
5038 formalParams: formalParams.join(", "),
|
|
5039 actualParams: actualParams.join(", "),
|
|
5040 savedPosVar: savedPosVar,
|
|
5041 resultVar: resultVar
|
|
5042 }
|
|
5043 );
|
|
5044 },
|
|
5045
|
|
5046 rule_ref: function(node, resultVar) {
|
|
5047 return formatCode(
|
|
5048 "var ${resultVar} = ${ruleMethod}();",
|
|
5049 {
|
|
5050 ruleMethod: "parse_" + node.name,
|
|
5051 resultVar: resultVar
|
|
5052 }
|
|
5053 );
|
|
5054 },
|
|
5055
|
|
5056 literal: function(node, resultVar) {
|
|
5057 return formatCode(
|
|
5058 "if (input.substr(pos, ${length}) === ${value|string}) {",
|
|
5059 " var ${resultVar} = ${value|string};",
|
|
5060 " pos += ${length};",
|
|
5061 "} else {",
|
|
5062 " var ${resultVar} = null;",
|
|
5063 " if (reportMatchFailures) {",
|
|
5064 " matchFailed(${valueQuoted|string});",
|
|
5065 " }",
|
|
5066 "}",
|
|
5067 {
|
|
5068 value: node.value,
|
|
5069 valueQuoted: quote(node.value),
|
|
5070 length: node.value.length,
|
|
5071 resultVar: resultVar
|
|
5072 }
|
|
5073 );
|
|
5074 },
|
|
5075
|
|
5076 any: function(node, resultVar) {
|
|
5077 return formatCode(
|
|
5078 "if (input.length > pos) {",
|
|
5079 " var ${resultVar} = input.charAt(pos);",
|
|
5080 " pos++;",
|
|
5081 "} else {",
|
|
5082 " var ${resultVar} = null;",
|
|
5083 " if (reportMatchFailures) {",
|
|
5084 " matchFailed('any character');",
|
|
5085 " }",
|
|
5086 "}",
|
|
5087 { resultVar: resultVar }
|
|
5088 );
|
|
5089 },
|
|
5090
|
|
5091 "class": function(node, resultVar) {
|
|
5092 if (node.parts.length > 0) {
|
|
5093 var regexp = "/^["
|
|
5094 + (node.inverted ? "^" : "")
|
|
5095 + map(node.parts, function(part) {
|
|
5096 return part instanceof Array
|
|
5097 ? quoteForRegexpClass(part[0])
|
|
5098 + "-"
|
|
5099 + quoteForRegexpClass(part[1])
|
|
5100 : quoteForRegexpClass(part);
|
|
5101 }).join("")
|
|
5102 + "]/";
|
|
5103 } else {
|
|
5104 /*
|
|
5105 * Stupid IE considers regexps /[]/ and /[^]/ syntactically invalid, so
|
|
5106 * we translate them into euqivalents it can handle.
|
|
5107 */
|
|
5108 var regexp = node.inverted ? "/^[\\S\\s]/" : "/^(?!)/";
|
|
5109 }
|
|
5110
|
|
5111 return formatCode(
|
|
5112 "if (input.substr(pos).match(${regexp}) !== null) {",
|
|
5113 " var ${resultVar} = input.charAt(pos);",
|
|
5114 " pos++;",
|
|
5115 "} else {",
|
|
5116 " var ${resultVar} = null;",
|
|
5117 " if (reportMatchFailures) {",
|
|
5118 " matchFailed(${rawText|string});",
|
|
5119 " }",
|
|
5120 "}",
|
|
5121 {
|
|
5122 regexp: regexp,
|
|
5123 rawText: node.rawText,
|
|
5124 resultVar: resultVar
|
|
5125 }
|
|
5126 );
|
|
5127 }
|
|
5128 });
|
|
5129
|
|
5130 return emit(ast);
|
|
5131 };
|
|
5132
|
|
5133 if (typeof module === "object") {
|
|
5134 module.exports = PEG;
|
|
5135 } else if (typeof window === "object") {
|
|
5136 window.PEG = PEG;
|
|
5137 } else {
|
|
5138 throw new Error("Can't export PEG library (no \"module\" nor \"window\" object detected).");
|
|
5139 }
|
|
5140
|
|
5141 })(); |