UNPKG

25 kBJavaScriptView Raw
1/*
2 * Generated by PEG.js 0.10.0.
3 *
4 * http://pegjs.org/
5 */
6
7"use strict";
8
9function peg$subclass(child, parent) {
10 function ctor() { this.constructor = child; }
11 ctor.prototype = parent.prototype;
12 child.prototype = new ctor();
13}
14
15function peg$SyntaxError(message, expected, found, location) {
16 this.message = message;
17 this.expected = expected;
18 this.found = found;
19 this.location = location;
20 this.name = "SyntaxError";
21
22 if (typeof Error.captureStackTrace === "function") {
23 Error.captureStackTrace(this, peg$SyntaxError);
24 }
25}
26
27peg$subclass(peg$SyntaxError, Error);
28
29peg$SyntaxError.buildMessage = function(expected, found) {
30 var DESCRIBE_EXPECTATION_FNS = {
31 literal: function(expectation) {
32 return "\"" + literalEscape(expectation.text) + "\"";
33 },
34
35 "class": function(expectation) {
36 var escapedParts = "",
37 i;
38
39 for (i = 0; i < expectation.parts.length; i++) {
40 escapedParts += expectation.parts[i] instanceof Array
41 ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])
42 : classEscape(expectation.parts[i]);
43 }
44
45 return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
46 },
47
48 any: function(expectation) {
49 return "any character";
50 },
51
52 end: function(expectation) {
53 return "end of input";
54 },
55
56 other: function(expectation) {
57 return expectation.description;
58 }
59 };
60
61 function hex(ch) {
62 return ch.charCodeAt(0).toString(16).toUpperCase();
63 }
64
65 function literalEscape(s) {
66 return s
67 .replace(/\\/g, '\\\\')
68 .replace(/"/g, '\\"')
69 .replace(/\0/g, '\\0')
70 .replace(/\t/g, '\\t')
71 .replace(/\n/g, '\\n')
72 .replace(/\r/g, '\\r')
73 .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
74 .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
75 }
76
77 function classEscape(s) {
78 return s
79 .replace(/\\/g, '\\\\')
80 .replace(/\]/g, '\\]')
81 .replace(/\^/g, '\\^')
82 .replace(/-/g, '\\-')
83 .replace(/\0/g, '\\0')
84 .replace(/\t/g, '\\t')
85 .replace(/\n/g, '\\n')
86 .replace(/\r/g, '\\r')
87 .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
88 .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
89 }
90
91 function describeExpectation(expectation) {
92 return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
93 }
94
95 function describeExpected(expected) {
96 var descriptions = new Array(expected.length),
97 i, j;
98
99 for (i = 0; i < expected.length; i++) {
100 descriptions[i] = describeExpectation(expected[i]);
101 }
102
103 descriptions.sort();
104
105 if (descriptions.length > 0) {
106 for (i = 1, j = 1; i < descriptions.length; i++) {
107 if (descriptions[i - 1] !== descriptions[i]) {
108 descriptions[j] = descriptions[i];
109 j++;
110 }
111 }
112 descriptions.length = j;
113 }
114
115 switch (descriptions.length) {
116 case 1:
117 return descriptions[0];
118
119 case 2:
120 return descriptions[0] + " or " + descriptions[1];
121
122 default:
123 return descriptions.slice(0, -1).join(", ")
124 + ", or "
125 + descriptions[descriptions.length - 1];
126 }
127 }
128
129 function describeFound(found) {
130 return found ? "\"" + literalEscape(found) + "\"" : "end of input";
131 }
132
133 return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
134};
135
136function peg$parse(input, options) {
137 options = options !== void 0 ? options : {};
138
139 var peg$FAILED = {},
140
141 peg$startRuleFunctions = { Start: peg$parseStart },
142 peg$startRuleFunction = peg$parseStart,
143
144 peg$c0 = function(paths) {
145 paths.forEach(checkPath)
146 return checkErrors() || {paths: paths, nestedPaths: nestedPaths}
147 },
148 peg$c1 = ",",
149 peg$c2 = peg$literalExpectation(",", false),
150 peg$c3 = function(head, expr) { return expr },
151 peg$c4 = function(head, tail) {
152 return [head].concat(tail)
153 },
154 peg$c5 = peg$otherExpectation("whitespace"),
155 peg$c6 = /^[ \t\r\n]/,
156 peg$c7 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false),
157 peg$c8 = function(head, tail) {
158 var name = head + tail.join('')
159 checkReserved(name)
160 return name
161 },
162 peg$c9 = /^[a-zA-Z]/,
163 peg$c10 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false),
164 peg$c11 = "_",
165 peg$c12 = peg$literalExpectation("_", false),
166 peg$c13 = /^[0-9]/,
167 peg$c14 = peg$classExpectation([["0", "9"]], false, false),
168 peg$c15 = "#",
169 peg$c16 = peg$literalExpectation("#", false),
170 peg$c17 = function(head, tail) {
171 return resolveAttrName(head + tail.join(''))
172 },
173 peg$c18 = "[",
174 peg$c19 = peg$literalExpectation("[", false),
175 peg$c20 = "]",
176 peg$c21 = peg$literalExpectation("]", false),
177 peg$c22 = function(head, ix) {
178 return +(ix.join(''))
179 },
180 peg$c23 = ".",
181 peg$c24 = peg$literalExpectation(".", false),
182 peg$c25 = function(head, prop) {
183 return prop
184 },
185 peg$c26 = function(head, tail) {
186 var path = [head].concat(tail)
187 if (path.length > 1) {
188 nestedPaths[path[0]] = true
189 }
190 return path
191 },
192
193 peg$currPos = 0,
194 peg$savedPos = 0,
195 peg$posDetailsCache = [{ line: 1, column: 1 }],
196 peg$maxFailPos = 0,
197 peg$maxFailExpected = [],
198 peg$silentFails = 0,
199
200 peg$result;
201
202 if ("startRule" in options) {
203 if (!(options.startRule in peg$startRuleFunctions)) {
204 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
205 }
206
207 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
208 }
209
210 function text() {
211 return input.substring(peg$savedPos, peg$currPos);
212 }
213
214 function location() {
215 return peg$computeLocation(peg$savedPos, peg$currPos);
216 }
217
218 function expected(description, location) {
219 location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
220
221 throw peg$buildStructuredError(
222 [peg$otherExpectation(description)],
223 input.substring(peg$savedPos, peg$currPos),
224 location
225 );
226 }
227
228 function error(message, location) {
229 location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
230
231 throw peg$buildSimpleError(message, location);
232 }
233
234 function peg$literalExpectation(text, ignoreCase) {
235 return { type: "literal", text: text, ignoreCase: ignoreCase };
236 }
237
238 function peg$classExpectation(parts, inverted, ignoreCase) {
239 return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
240 }
241
242 function peg$anyExpectation() {
243 return { type: "any" };
244 }
245
246 function peg$endExpectation() {
247 return { type: "end" };
248 }
249
250 function peg$otherExpectation(description) {
251 return { type: "other", description: description };
252 }
253
254 function peg$computePosDetails(pos) {
255 var details = peg$posDetailsCache[pos], p;
256
257 if (details) {
258 return details;
259 } else {
260 p = pos - 1;
261 while (!peg$posDetailsCache[p]) {
262 p--;
263 }
264
265 details = peg$posDetailsCache[p];
266 details = {
267 line: details.line,
268 column: details.column
269 };
270
271 while (p < pos) {
272 if (input.charCodeAt(p) === 10) {
273 details.line++;
274 details.column = 1;
275 } else {
276 details.column++;
277 }
278
279 p++;
280 }
281
282 peg$posDetailsCache[pos] = details;
283 return details;
284 }
285 }
286
287 function peg$computeLocation(startPos, endPos) {
288 var startPosDetails = peg$computePosDetails(startPos),
289 endPosDetails = peg$computePosDetails(endPos);
290
291 return {
292 start: {
293 offset: startPos,
294 line: startPosDetails.line,
295 column: startPosDetails.column
296 },
297 end: {
298 offset: endPos,
299 line: endPosDetails.line,
300 column: endPosDetails.column
301 }
302 };
303 }
304
305 function peg$fail(expected) {
306 if (peg$currPos < peg$maxFailPos) { return; }
307
308 if (peg$currPos > peg$maxFailPos) {
309 peg$maxFailPos = peg$currPos;
310 peg$maxFailExpected = [];
311 }
312
313 peg$maxFailExpected.push(expected);
314 }
315
316 function peg$buildSimpleError(message, location) {
317 return new peg$SyntaxError(message, null, null, location);
318 }
319
320 function peg$buildStructuredError(expected, found, location) {
321 return new peg$SyntaxError(
322 peg$SyntaxError.buildMessage(expected, found),
323 expected,
324 found,
325 location
326 );
327 }
328
329 function peg$parseStart() {
330 var s0, s1, s2, s3;
331
332 s0 = peg$currPos;
333 s1 = peg$parse_();
334 if (s1 !== peg$FAILED) {
335 s2 = peg$parsePathList();
336 if (s2 !== peg$FAILED) {
337 s3 = peg$parse_();
338 if (s3 !== peg$FAILED) {
339 peg$savedPos = s0;
340 s1 = peg$c0(s2);
341 s0 = s1;
342 } else {
343 peg$currPos = s0;
344 s0 = peg$FAILED;
345 }
346 } else {
347 peg$currPos = s0;
348 s0 = peg$FAILED;
349 }
350 } else {
351 peg$currPos = s0;
352 s0 = peg$FAILED;
353 }
354
355 return s0;
356 }
357
358 function peg$parsePathList() {
359 var s0, s1, s2, s3, s4, s5, s6, s7;
360
361 s0 = peg$currPos;
362 s1 = peg$parsePathExpression();
363 if (s1 !== peg$FAILED) {
364 s2 = [];
365 s3 = peg$currPos;
366 s4 = peg$parse_();
367 if (s4 !== peg$FAILED) {
368 if (input.charCodeAt(peg$currPos) === 44) {
369 s5 = peg$c1;
370 peg$currPos++;
371 } else {
372 s5 = peg$FAILED;
373 if (peg$silentFails === 0) { peg$fail(peg$c2); }
374 }
375 if (s5 !== peg$FAILED) {
376 s6 = peg$parse_();
377 if (s6 !== peg$FAILED) {
378 s7 = peg$parsePathExpression();
379 if (s7 !== peg$FAILED) {
380 peg$savedPos = s3;
381 s4 = peg$c3(s1, s7);
382 s3 = s4;
383 } else {
384 peg$currPos = s3;
385 s3 = peg$FAILED;
386 }
387 } else {
388 peg$currPos = s3;
389 s3 = peg$FAILED;
390 }
391 } else {
392 peg$currPos = s3;
393 s3 = peg$FAILED;
394 }
395 } else {
396 peg$currPos = s3;
397 s3 = peg$FAILED;
398 }
399 while (s3 !== peg$FAILED) {
400 s2.push(s3);
401 s3 = peg$currPos;
402 s4 = peg$parse_();
403 if (s4 !== peg$FAILED) {
404 if (input.charCodeAt(peg$currPos) === 44) {
405 s5 = peg$c1;
406 peg$currPos++;
407 } else {
408 s5 = peg$FAILED;
409 if (peg$silentFails === 0) { peg$fail(peg$c2); }
410 }
411 if (s5 !== peg$FAILED) {
412 s6 = peg$parse_();
413 if (s6 !== peg$FAILED) {
414 s7 = peg$parsePathExpression();
415 if (s7 !== peg$FAILED) {
416 peg$savedPos = s3;
417 s4 = peg$c3(s1, s7);
418 s3 = s4;
419 } else {
420 peg$currPos = s3;
421 s3 = peg$FAILED;
422 }
423 } else {
424 peg$currPos = s3;
425 s3 = peg$FAILED;
426 }
427 } else {
428 peg$currPos = s3;
429 s3 = peg$FAILED;
430 }
431 } else {
432 peg$currPos = s3;
433 s3 = peg$FAILED;
434 }
435 }
436 if (s2 !== peg$FAILED) {
437 peg$savedPos = s0;
438 s1 = peg$c4(s1, s2);
439 s0 = s1;
440 } else {
441 peg$currPos = s0;
442 s0 = peg$FAILED;
443 }
444 } else {
445 peg$currPos = s0;
446 s0 = peg$FAILED;
447 }
448
449 return s0;
450 }
451
452 function peg$parse_() {
453 var s0, s1;
454
455 peg$silentFails++;
456 s0 = [];
457 if (peg$c6.test(input.charAt(peg$currPos))) {
458 s1 = input.charAt(peg$currPos);
459 peg$currPos++;
460 } else {
461 s1 = peg$FAILED;
462 if (peg$silentFails === 0) { peg$fail(peg$c7); }
463 }
464 while (s1 !== peg$FAILED) {
465 s0.push(s1);
466 if (peg$c6.test(input.charAt(peg$currPos))) {
467 s1 = input.charAt(peg$currPos);
468 peg$currPos++;
469 } else {
470 s1 = peg$FAILED;
471 if (peg$silentFails === 0) { peg$fail(peg$c7); }
472 }
473 }
474 peg$silentFails--;
475 if (s0 === peg$FAILED) {
476 s1 = peg$FAILED;
477 if (peg$silentFails === 0) { peg$fail(peg$c5); }
478 }
479
480 return s0;
481 }
482
483 function peg$parseIdentifier() {
484 var s0, s1, s2, s3;
485
486 s0 = peg$currPos;
487 s1 = peg$parseIdentifierStart();
488 if (s1 !== peg$FAILED) {
489 s2 = [];
490 s3 = peg$parseIdentifierPart();
491 while (s3 !== peg$FAILED) {
492 s2.push(s3);
493 s3 = peg$parseIdentifierPart();
494 }
495 if (s2 !== peg$FAILED) {
496 peg$savedPos = s0;
497 s1 = peg$c8(s1, s2);
498 s0 = s1;
499 } else {
500 peg$currPos = s0;
501 s0 = peg$FAILED;
502 }
503 } else {
504 peg$currPos = s0;
505 s0 = peg$FAILED;
506 }
507 if (s0 === peg$FAILED) {
508 s0 = peg$parseExpressionAttributeName();
509 }
510
511 return s0;
512 }
513
514 function peg$parseIdentifierStart() {
515 var s0;
516
517 if (peg$c9.test(input.charAt(peg$currPos))) {
518 s0 = input.charAt(peg$currPos);
519 peg$currPos++;
520 } else {
521 s0 = peg$FAILED;
522 if (peg$silentFails === 0) { peg$fail(peg$c10); }
523 }
524 if (s0 === peg$FAILED) {
525 if (input.charCodeAt(peg$currPos) === 95) {
526 s0 = peg$c11;
527 peg$currPos++;
528 } else {
529 s0 = peg$FAILED;
530 if (peg$silentFails === 0) { peg$fail(peg$c12); }
531 }
532 }
533
534 return s0;
535 }
536
537 function peg$parseIdentifierPart() {
538 var s0;
539
540 s0 = peg$parseIdentifierStart();
541 if (s0 === peg$FAILED) {
542 if (peg$c13.test(input.charAt(peg$currPos))) {
543 s0 = input.charAt(peg$currPos);
544 peg$currPos++;
545 } else {
546 s0 = peg$FAILED;
547 if (peg$silentFails === 0) { peg$fail(peg$c14); }
548 }
549 }
550
551 return s0;
552 }
553
554 function peg$parseExpressionAttributeName() {
555 var s0, s1, s2, s3;
556
557 s0 = peg$currPos;
558 if (input.charCodeAt(peg$currPos) === 35) {
559 s1 = peg$c15;
560 peg$currPos++;
561 } else {
562 s1 = peg$FAILED;
563 if (peg$silentFails === 0) { peg$fail(peg$c16); }
564 }
565 if (s1 !== peg$FAILED) {
566 s2 = [];
567 s3 = peg$parseIdentifierPart();
568 while (s3 !== peg$FAILED) {
569 s2.push(s3);
570 s3 = peg$parseIdentifierPart();
571 }
572 if (s2 !== peg$FAILED) {
573 peg$savedPos = s0;
574 s1 = peg$c17(s1, s2);
575 s0 = s1;
576 } else {
577 peg$currPos = s0;
578 s0 = peg$FAILED;
579 }
580 } else {
581 peg$currPos = s0;
582 s0 = peg$FAILED;
583 }
584
585 return s0;
586 }
587
588 function peg$parsePathExpression() {
589 var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
590
591 s0 = peg$currPos;
592 s1 = peg$parseIdentifier();
593 if (s1 !== peg$FAILED) {
594 s2 = [];
595 s3 = peg$currPos;
596 s4 = peg$parse_();
597 if (s4 !== peg$FAILED) {
598 if (input.charCodeAt(peg$currPos) === 91) {
599 s5 = peg$c18;
600 peg$currPos++;
601 } else {
602 s5 = peg$FAILED;
603 if (peg$silentFails === 0) { peg$fail(peg$c19); }
604 }
605 if (s5 !== peg$FAILED) {
606 s6 = peg$parse_();
607 if (s6 !== peg$FAILED) {
608 s7 = [];
609 if (peg$c13.test(input.charAt(peg$currPos))) {
610 s8 = input.charAt(peg$currPos);
611 peg$currPos++;
612 } else {
613 s8 = peg$FAILED;
614 if (peg$silentFails === 0) { peg$fail(peg$c14); }
615 }
616 if (s8 !== peg$FAILED) {
617 while (s8 !== peg$FAILED) {
618 s7.push(s8);
619 if (peg$c13.test(input.charAt(peg$currPos))) {
620 s8 = input.charAt(peg$currPos);
621 peg$currPos++;
622 } else {
623 s8 = peg$FAILED;
624 if (peg$silentFails === 0) { peg$fail(peg$c14); }
625 }
626 }
627 } else {
628 s7 = peg$FAILED;
629 }
630 if (s7 !== peg$FAILED) {
631 s8 = peg$parse_();
632 if (s8 !== peg$FAILED) {
633 if (input.charCodeAt(peg$currPos) === 93) {
634 s9 = peg$c20;
635 peg$currPos++;
636 } else {
637 s9 = peg$FAILED;
638 if (peg$silentFails === 0) { peg$fail(peg$c21); }
639 }
640 if (s9 !== peg$FAILED) {
641 peg$savedPos = s3;
642 s4 = peg$c22(s1, s7);
643 s3 = s4;
644 } else {
645 peg$currPos = s3;
646 s3 = peg$FAILED;
647 }
648 } else {
649 peg$currPos = s3;
650 s3 = peg$FAILED;
651 }
652 } else {
653 peg$currPos = s3;
654 s3 = peg$FAILED;
655 }
656 } else {
657 peg$currPos = s3;
658 s3 = peg$FAILED;
659 }
660 } else {
661 peg$currPos = s3;
662 s3 = peg$FAILED;
663 }
664 } else {
665 peg$currPos = s3;
666 s3 = peg$FAILED;
667 }
668 if (s3 === peg$FAILED) {
669 s3 = peg$currPos;
670 s4 = peg$parse_();
671 if (s4 !== peg$FAILED) {
672 if (input.charCodeAt(peg$currPos) === 46) {
673 s5 = peg$c23;
674 peg$currPos++;
675 } else {
676 s5 = peg$FAILED;
677 if (peg$silentFails === 0) { peg$fail(peg$c24); }
678 }
679 if (s5 !== peg$FAILED) {
680 s6 = peg$parse_();
681 if (s6 !== peg$FAILED) {
682 s7 = peg$parseIdentifier();
683 if (s7 !== peg$FAILED) {
684 peg$savedPos = s3;
685 s4 = peg$c25(s1, s7);
686 s3 = s4;
687 } else {
688 peg$currPos = s3;
689 s3 = peg$FAILED;
690 }
691 } else {
692 peg$currPos = s3;
693 s3 = peg$FAILED;
694 }
695 } else {
696 peg$currPos = s3;
697 s3 = peg$FAILED;
698 }
699 } else {
700 peg$currPos = s3;
701 s3 = peg$FAILED;
702 }
703 }
704 while (s3 !== peg$FAILED) {
705 s2.push(s3);
706 s3 = peg$currPos;
707 s4 = peg$parse_();
708 if (s4 !== peg$FAILED) {
709 if (input.charCodeAt(peg$currPos) === 91) {
710 s5 = peg$c18;
711 peg$currPos++;
712 } else {
713 s5 = peg$FAILED;
714 if (peg$silentFails === 0) { peg$fail(peg$c19); }
715 }
716 if (s5 !== peg$FAILED) {
717 s6 = peg$parse_();
718 if (s6 !== peg$FAILED) {
719 s7 = [];
720 if (peg$c13.test(input.charAt(peg$currPos))) {
721 s8 = input.charAt(peg$currPos);
722 peg$currPos++;
723 } else {
724 s8 = peg$FAILED;
725 if (peg$silentFails === 0) { peg$fail(peg$c14); }
726 }
727 if (s8 !== peg$FAILED) {
728 while (s8 !== peg$FAILED) {
729 s7.push(s8);
730 if (peg$c13.test(input.charAt(peg$currPos))) {
731 s8 = input.charAt(peg$currPos);
732 peg$currPos++;
733 } else {
734 s8 = peg$FAILED;
735 if (peg$silentFails === 0) { peg$fail(peg$c14); }
736 }
737 }
738 } else {
739 s7 = peg$FAILED;
740 }
741 if (s7 !== peg$FAILED) {
742 s8 = peg$parse_();
743 if (s8 !== peg$FAILED) {
744 if (input.charCodeAt(peg$currPos) === 93) {
745 s9 = peg$c20;
746 peg$currPos++;
747 } else {
748 s9 = peg$FAILED;
749 if (peg$silentFails === 0) { peg$fail(peg$c21); }
750 }
751 if (s9 !== peg$FAILED) {
752 peg$savedPos = s3;
753 s4 = peg$c22(s1, s7);
754 s3 = s4;
755 } else {
756 peg$currPos = s3;
757 s3 = peg$FAILED;
758 }
759 } else {
760 peg$currPos = s3;
761 s3 = peg$FAILED;
762 }
763 } else {
764 peg$currPos = s3;
765 s3 = peg$FAILED;
766 }
767 } else {
768 peg$currPos = s3;
769 s3 = peg$FAILED;
770 }
771 } else {
772 peg$currPos = s3;
773 s3 = peg$FAILED;
774 }
775 } else {
776 peg$currPos = s3;
777 s3 = peg$FAILED;
778 }
779 if (s3 === peg$FAILED) {
780 s3 = peg$currPos;
781 s4 = peg$parse_();
782 if (s4 !== peg$FAILED) {
783 if (input.charCodeAt(peg$currPos) === 46) {
784 s5 = peg$c23;
785 peg$currPos++;
786 } else {
787 s5 = peg$FAILED;
788 if (peg$silentFails === 0) { peg$fail(peg$c24); }
789 }
790 if (s5 !== peg$FAILED) {
791 s6 = peg$parse_();
792 if (s6 !== peg$FAILED) {
793 s7 = peg$parseIdentifier();
794 if (s7 !== peg$FAILED) {
795 peg$savedPos = s3;
796 s4 = peg$c25(s1, s7);
797 s3 = s4;
798 } else {
799 peg$currPos = s3;
800 s3 = peg$FAILED;
801 }
802 } else {
803 peg$currPos = s3;
804 s3 = peg$FAILED;
805 }
806 } else {
807 peg$currPos = s3;
808 s3 = peg$FAILED;
809 }
810 } else {
811 peg$currPos = s3;
812 s3 = peg$FAILED;
813 }
814 }
815 }
816 if (s2 !== peg$FAILED) {
817 peg$savedPos = s0;
818 s1 = peg$c26(s1, s2);
819 s0 = s1;
820 } else {
821 peg$currPos = s0;
822 s0 = peg$FAILED;
823 }
824 } else {
825 peg$currPos = s0;
826 s0 = peg$FAILED;
827 }
828
829 return s0;
830 }
831
832
833 // Declared by PEG: input, options, parser, text(), location(), expected(), error()
834
835 var context = options.context
836 var attrNames = context.attrNames || {}
837 var unusedAttrNames = context.unusedAttrNames || {}
838 var isReserved = context.isReserved
839 var errors = {}
840 var paths = []
841 var nestedPaths = Object.create(null)
842
843 function checkReserved(name) {
844 if (isReserved(name) && !errors.reserved) {
845 errors.reserved = 'Attribute name is a reserved keyword; reserved keyword: ' + name
846 }
847 }
848
849 function resolveAttrName(name) {
850 if (errors.attrNameVal) {
851 return
852 }
853 if (!attrNames[name]) {
854 errors.attrNameVal = 'An expression attribute name used in the document path is not defined; attribute name: ' + name
855 return
856 }
857 delete unusedAttrNames[name]
858 return attrNames[name]
859 }
860
861 function checkPath(path) {
862 if (errors.pathOverlap) {
863 return
864 }
865 for (var i = 0; i < paths.length; i++) {
866 checkPaths(paths[i], path)
867 if (errors.pathOverlap) {
868 return
869 }
870 }
871 paths.push(path)
872 }
873
874 function checkPaths(path1, path2) {
875 for (var i = 0; i < path1.length && i < path2.length; i++) {
876 if (typeof path1[i] !== typeof path2[i]) {
877 errors.pathConflict = 'Two document paths conflict with each other; ' +
878 'must remove or rewrite one of these paths; path one: ' + pathStr(path1) + ', path two: ' + pathStr(path2)
879 return
880 }
881 if (path1[i] !== path2[i]) return
882 }
883 if (errors.pathOverlap) {
884 return
885 }
886 errors.pathOverlap = 'Two document paths overlap with each other; ' +
887 'must remove or rewrite one of these paths; path one: ' + pathStr(path1) + ', path two: ' + pathStr(path2)
888 }
889
890 function pathStr(path) {
891 return '[' + path.map(function(piece) {
892 return typeof piece == 'number' ? '[' + piece + ']' : piece
893 }).join(', ') + ']'
894 }
895
896 function checkErrors() {
897 var errorOrder = ['reserved', 'attrNameVal', 'pathOverlap', 'pathConflict']
898 for (var i = 0; i < errorOrder.length; i++) {
899 if (errors[errorOrder[i]]) return errors[errorOrder[i]]
900 }
901 return null
902 }
903
904
905 peg$result = peg$startRuleFunction();
906
907 if (peg$result !== peg$FAILED && peg$currPos === input.length) {
908 return peg$result;
909 } else {
910 if (peg$result !== peg$FAILED && peg$currPos < input.length) {
911 peg$fail(peg$endExpectation());
912 }
913
914 throw peg$buildStructuredError(
915 peg$maxFailExpected,
916 peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
917 peg$maxFailPos < input.length
918 ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
919 : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
920 );
921 }
922}
923
924module.exports = {
925 SyntaxError: peg$SyntaxError,
926 parse: peg$parse
927};