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