1// @generated by Peggy 4.1.1.
2//
3// https://peggyjs.org/
4
5
6function peg$subclass(child, parent) {
7 function C() { this.constructor = child; }
8 C.prototype = parent.prototype;
9 child.prototype = new C();
10}
11
12function peg$SyntaxError(message, expected, found, location) {
13 var self = Error.call(this, message);
14 // istanbul ignore next Check is a necessary evil to support older environments
15 if (Object.setPrototypeOf) {
16 Object.setPrototypeOf(self, peg$SyntaxError.prototype);
17 }
18 self.expected = expected;
19 self.found = found;
20 self.location = location;
21 self.name = "SyntaxError";
22 return self;
23}
24
25peg$subclass(peg$SyntaxError, Error);
26
27function peg$padEnd(str, targetLength, padString) {
28 padString = padString || " ";
29 if (str.length > targetLength) { return str; }
30 targetLength -= str.length;
31 padString += padString.repeat(targetLength);
32 return str + padString.slice(0, targetLength);
33}
34
35peg$SyntaxError.prototype.format = function(sources) {
36 var str = "Error: " + this.message;
37 if (this.location) {
38 var src = null;
39 var k;
40 for (k = 0; k < sources.length; k++) {
41 if (sources[k].source === this.location.source) {
42 src = sources[k].text.split(/\r\n|\n|\r/g);
43 break;
44 }
45 }
46 var s = this.location.start;
47 var offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
48 ? this.location.source.offset(s)
49 : s;
50 var loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
51 if (src) {
52 var e = this.location.end;
53 var filler = peg$padEnd("", offset_s.line.toString().length, ' ');
54 var line = src[s.line - 1];
55 var last = s.line === e.line ? e.column : line.length + 1;
56 var hatLen = (last - s.column) || 1;
57 str += "\n --> " + loc + "\n"
58 + filler + " |\n"
59 + offset_s.line + " | " + line + "\n"
60 + filler + " | " + peg$padEnd("", s.column - 1, ' ')
61 + peg$padEnd("", hatLen, "^");
62 } else {
63 str += "\n at " + loc;
64 }
65 }
66 return str;
67};
68
69peg$SyntaxError.buildMessage = function(expected, found) {
70 var DESCRIBE_EXPECTATION_FNS = {
71 literal: function(expectation) {
72 return "\"" + literalEscape(expectation.text) + "\"";
73 },
74
75 class: function(expectation) {
76 var escapedParts = expectation.parts.map(function(part) {
77 return Array.isArray(part)
78 ? classEscape(part[0]) + "-" + classEscape(part[1])
79 : classEscape(part);
80 });
81
82 return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
83 },
84
85 any: function() {
86 return "any character";
87 },
88
89 end: function() {
90 return "end of input";
91 },
92
93 other: function(expectation) {
94 return expectation.description;
95 }
96 };
97
98 function hex(ch) {
99 return ch.charCodeAt(0).toString(16).toUpperCase();
100 }
101
102 function literalEscape(s) {
103 return s
104 .replace(/\\/g, "\\\\")
105 .replace(/"/g, "\\\"")
106 .replace(/\0/g, "\\0")
107 .replace(/\t/g, "\\t")
108 .replace(/\n/g, "\\n")
109 .replace(/\r/g, "\\r")
110 .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
111 .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
112 }
113
114 function classEscape(s) {
115 return s
116 .replace(/\\/g, "\\\\")
117 .replace(/\]/g, "\\]")
118 .replace(/\^/g, "\\^")
119 .replace(/-/g, "\\-")
120 .replace(/\0/g, "\\0")
121 .replace(/\t/g, "\\t")
122 .replace(/\n/g, "\\n")
123 .replace(/\r/g, "\\r")
124 .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
125 .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
126 }
127
128 function describeExpectation(expectation) {
129 return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
130 }
131
132 function describeExpected(expected) {
133 var descriptions = expected.map(describeExpectation);
134 var i, j;
135
136 descriptions.sort();
137
138 if (descriptions.length > 0) {
139 for (i = 1, j = 1; i < descriptions.length; i++) {
140 if (descriptions[i - 1] !== descriptions[i]) {
141 descriptions[j] = descriptions[i];
142 j++;
143 }
144 }
145 descriptions.length = j;
146 }
147
148 switch (descriptions.length) {
149 case 1:
150 return descriptions[0];
151
152 case 2:
153 return descriptions[0] + " or " + descriptions[1];
154
155 default:
156 return descriptions.slice(0, -1).join(", ")
157 + ", or "
158 + descriptions[descriptions.length - 1];
159 }
160 }
161
162 function describeFound(found) {
163 return found ? "\"" + literalEscape(found) + "\"" : "end of input";
164 }
165
166 return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
167};
168
169function peg$parse(input, options) {
170 options = options !== undefined ? options : {};
171
172 var peg$FAILED = {};
173 var peg$source = options.grammarSource;
174
175 var peg$startRuleFunctions = { Add: peg$parseAdd };
176 var peg$startRuleFunction = peg$parseAdd;
177
178 var peg$c0 = "pro:";
179 var peg$c1 = "project:";
180 var peg$c2 = "+";
181 var peg$c3 = "priority:";
182 var peg$c4 = "#";
183
184 var peg$r0 = /^[HML]/;
185 var peg$r1 = /^[a-zA-Z0-9_\-]/;
186 var peg$r2 = /^[ \\t]/;
187
188 var peg$e0 = peg$anyExpectation();
189 var peg$e1 = peg$literalExpectation("pro:", false);
190 var peg$e2 = peg$literalExpectation("project:", false);
191 var peg$e3 = peg$literalExpectation("+", false);
192 var peg$e4 = peg$literalExpectation("priority:", false);
193 var peg$e5 = peg$classExpectation(["H", "M", "L"], false, false);
194 var peg$e6 = peg$literalExpectation("#", false);
195 var peg$e7 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_", "-"], false, false);
196 var peg$e8 = peg$classExpectation([" ", "\\", "t"], false, false);
197
198 var peg$f0 = function(desc, attributes) {
199 return MakeAdd(desc, attributes);
200};
201 var peg$f1 = function(chars) {
202 return chars.map(c => c[1]).join('');
203};
204 var peg$f2 = function(attributes) {
205 return MakeAttributes(attributes);
206};
207 var peg$f3 = function(value) {
208 return { type: "project", value: value };
209};
210 var peg$f4 = function(value) {
211 return { type: "priority", value: value };
212};
213 var peg$f5 = function(value) {
214 return { type: "tag", value: value };
215};
216 var peg$f6 = function(chars) {
217 return chars.join('');
218};
219 var peg$currPos = options.peg$currPos | 0;
220 var peg$savedPos = peg$currPos;
221 var peg$posDetailsCache = [{ line: 1, column: 1 }];
222 var peg$maxFailPos = peg$currPos;
223 var peg$maxFailExpected = options.peg$maxFailExpected || [];
224 var peg$silentFails = options.peg$silentFails | 0;
225
226 var peg$result;
227
228 if (options.startRule) {
229 if (!(options.startRule in peg$startRuleFunctions)) {
230 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
231 }
232
233 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
234 }
235
236 function text() {
237 return input.substring(peg$savedPos, peg$currPos);
238 }
239
240 function offset() {
241 return peg$savedPos;
242 }
243
244 function range() {
245 return {
246 source: peg$source,
247 start: peg$savedPos,
248 end: peg$currPos
249 };
250 }
251
252 function location() {
253 return peg$computeLocation(peg$savedPos, peg$currPos);
254 }
255
256 function expected(description, location) {
257 location = location !== undefined
258 ? location
259 : peg$computeLocation(peg$savedPos, peg$currPos);
260
261 throw peg$buildStructuredError(
262 [peg$otherExpectation(description)],
263 input.substring(peg$savedPos, peg$currPos),
264 location
265 );
266 }
267
268 function error(message, location) {
269 location = location !== undefined
270 ? location
271 : peg$computeLocation(peg$savedPos, peg$currPos);
272
273 throw peg$buildSimpleError(message, location);
274 }
275
276 function peg$literalExpectation(text, ignoreCase) {
277 return { type: "literal", text: text, ignoreCase: ignoreCase };
278 }
279
280 function peg$classExpectation(parts, inverted, ignoreCase) {
281 return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
282 }
283
284 function peg$anyExpectation() {
285 return { type: "any" };
286 }
287
288 function peg$endExpectation() {
289 return { type: "end" };
290 }
291
292 function peg$otherExpectation(description) {
293 return { type: "other", description: description };
294 }
295
296 function peg$computePosDetails(pos) {
297 var details = peg$posDetailsCache[pos];
298 var p;
299
300 if (details) {
301 return details;
302 } else {
303 if (pos >= peg$posDetailsCache.length) {
304 p = peg$posDetailsCache.length - 1;
305 } else {
306 p = pos;
307 while (!peg$posDetailsCache[--p]) {}
308 }
309
310 details = peg$posDetailsCache[p];
311 details = {
312 line: details.line,
313 column: details.column
314 };
315
316 while (p < pos) {
317 if (input.charCodeAt(p) === 10) {
318 details.line++;
319 details.column = 1;
320 } else {
321 details.column++;
322 }
323
324 p++;
325 }
326
327 peg$posDetailsCache[pos] = details;
328
329 return details;
330 }
331 }
332
333 function peg$computeLocation(startPos, endPos, offset) {
334 var startPosDetails = peg$computePosDetails(startPos);
335 var endPosDetails = peg$computePosDetails(endPos);
336
337 var res = {
338 source: peg$source,
339 start: {
340 offset: startPos,
341 line: startPosDetails.line,
342 column: startPosDetails.column
343 },
344 end: {
345 offset: endPos,
346 line: endPosDetails.line,
347 column: endPosDetails.column
348 }
349 };
350 if (offset && peg$source && (typeof peg$source.offset === "function")) {
351 res.start = peg$source.offset(res.start);
352 res.end = peg$source.offset(res.end);
353 }
354 return res;
355 }
356
357 function peg$fail(expected) {
358 if (peg$currPos < peg$maxFailPos) { return; }
359
360 if (peg$currPos > peg$maxFailPos) {
361 peg$maxFailPos = peg$currPos;
362 peg$maxFailExpected = [];
363 }
364
365 peg$maxFailExpected.push(expected);
366 }
367
368 function peg$buildSimpleError(message, location) {
369 return new peg$SyntaxError(message, null, null, location);
370 }
371
372 function peg$buildStructuredError(expected, found, location) {
373 return new peg$SyntaxError(
374 peg$SyntaxError.buildMessage(expected, found),
375 expected,
376 found,
377 location
378 );
379 }
380
381 function peg$parseAdd() {
382 var s0, s1, s2;
383
384 s0 = peg$currPos;
385 s1 = peg$parseDescription();
386 if (s1 !== peg$FAILED) {
387 s2 = peg$parseAttributes();
388 peg$savedPos = s0;
389 s0 = peg$f0(s1, s2);
390 } else {
391 peg$currPos = s0;
392 s0 = peg$FAILED;
393 }
394
395 return s0;
396 }
397
398 function peg$parseDescription() {
399 var s0, s1, s2, s3, s4;
400
401 s0 = peg$currPos;
402 s1 = [];
403 s2 = peg$currPos;
404 s3 = peg$currPos;
405 peg$silentFails++;
406 s4 = peg$parseAttribute();
407 peg$silentFails--;
408 if (s4 === peg$FAILED) {
409 s3 = undefined;
410 } else {
411 peg$currPos = s3;
412 s3 = peg$FAILED;
413 }
414 if (s3 !== peg$FAILED) {
415 if (input.length > peg$currPos) {
416 s4 = input.charAt(peg$currPos);
417 peg$currPos++;
418 } else {
419 s4 = peg$FAILED;
420 if (peg$silentFails === 0) { peg$fail(peg$e0); }
421 }
422 if (s4 !== peg$FAILED) {
423 s3 = [s3, s4];
424 s2 = s3;
425 } else {
426 peg$currPos = s2;
427 s2 = peg$FAILED;
428 }
429 } else {
430 peg$currPos = s2;
431 s2 = peg$FAILED;
432 }
433 if (s2 !== peg$FAILED) {
434 while (s2 !== peg$FAILED) {
435 s1.push(s2);
436 s2 = peg$currPos;
437 s3 = peg$currPos;
438 peg$silentFails++;
439 s4 = peg$parseAttribute();
440 peg$silentFails--;
441 if (s4 === peg$FAILED) {
442 s3 = undefined;
443 } else {
444 peg$currPos = s3;
445 s3 = peg$FAILED;
446 }
447 if (s3 !== peg$FAILED) {
448 if (input.length > peg$currPos) {
449 s4 = input.charAt(peg$currPos);
450 peg$currPos++;
451 } else {
452 s4 = peg$FAILED;
453 if (peg$silentFails === 0) { peg$fail(peg$e0); }
454 }
455 if (s4 !== peg$FAILED) {
456 s3 = [s3, s4];
457 s2 = s3;
458 } else {
459 peg$currPos = s2;
460 s2 = peg$FAILED;
461 }
462 } else {
463 peg$currPos = s2;
464 s2 = peg$FAILED;
465 }
466 }
467 } else {
468 s1 = peg$FAILED;
469 }
470 if (s1 !== peg$FAILED) {
471 peg$savedPos = s0;
472 s1 = peg$f1(s1);
473 }
474 s0 = s1;
475
476 return s0;
477 }
478
479 function peg$parseAttributes() {
480 var s0, s1, s2, s3, s4;
481
482 s0 = peg$currPos;
483 s1 = [];
484 s2 = peg$currPos;
485 s3 = peg$parse_();
486 s4 = peg$parseAttribute();
487 if (s4 !== peg$FAILED) {
488 s3 = [s3, s4];
489 s2 = s3;
490 } else {
491 peg$currPos = s2;
492 s2 = peg$FAILED;
493 }
494 while (s2 !== peg$FAILED) {
495 s1.push(s2);
496 s2 = peg$currPos;
497 s3 = peg$parse_();
498 s4 = peg$parseAttribute();
499 if (s4 !== peg$FAILED) {
500 s3 = [s3, s4];
501 s2 = s3;
502 } else {
503 peg$currPos = s2;
504 s2 = peg$FAILED;
505 }
506 }
507 peg$savedPos = s0;
508 s1 = peg$f2(s1);
509 s0 = s1;
510
511 return s0;
512 }
513
514 function peg$parseAttribute() {
515 var s0;
516
517 s0 = peg$parseProject();
518 if (s0 === peg$FAILED) {
519 s0 = peg$parsePriority();
520 if (s0 === peg$FAILED) {
521 s0 = peg$parseTag();
522 }
523 }
524
525 return s0;
526 }
527
528 function peg$parseProject() {
529 var s0, s1, s2;
530
531 s0 = peg$currPos;
532 if (input.substr(peg$currPos, 4) === peg$c0) {
533 s1 = peg$c0;
534 peg$currPos += 4;
535 } else {
536 s1 = peg$FAILED;
537 if (peg$silentFails === 0) { peg$fail(peg$e1); }
538 }
539 if (s1 === peg$FAILED) {
540 if (input.substr(peg$currPos, 8) === peg$c1) {
541 s1 = peg$c1;
542 peg$currPos += 8;
543 } else {
544 s1 = peg$FAILED;
545 if (peg$silentFails === 0) { peg$fail(peg$e2); }
546 }
547 if (s1 === peg$FAILED) {
548 if (input.charCodeAt(peg$currPos) === 43) {
549 s1 = peg$c2;
550 peg$currPos++;
551 } else {
552 s1 = peg$FAILED;
553 if (peg$silentFails === 0) { peg$fail(peg$e3); }
554 }
555 }
556 }
557 if (s1 !== peg$FAILED) {
558 s2 = peg$parseWord();
559 if (s2 !== peg$FAILED) {
560 peg$savedPos = s0;
561 s0 = peg$f3(s2);
562 } else {
563 peg$currPos = s0;
564 s0 = peg$FAILED;
565 }
566 } else {
567 peg$currPos = s0;
568 s0 = peg$FAILED;
569 }
570
571 return s0;
572 }
573
574 function peg$parsePriority() {
575 var s0, s1, s2;
576
577 s0 = peg$currPos;
578 if (input.substr(peg$currPos, 9) === peg$c3) {
579 s1 = peg$c3;
580 peg$currPos += 9;
581 } else {
582 s1 = peg$FAILED;
583 if (peg$silentFails === 0) { peg$fail(peg$e4); }
584 }
585 if (s1 !== peg$FAILED) {
586 s2 = input.charAt(peg$currPos);
587 if (peg$r0.test(s2)) {
588 peg$currPos++;
589 } else {
590 s2 = peg$FAILED;
591 if (peg$silentFails === 0) { peg$fail(peg$e5); }
592 }
593 if (s2 !== peg$FAILED) {
594 peg$savedPos = s0;
595 s0 = peg$f4(s2);
596 } else {
597 peg$currPos = s0;
598 s0 = peg$FAILED;
599 }
600 } else {
601 peg$currPos = s0;
602 s0 = peg$FAILED;
603 }
604
605 return s0;
606 }
607
608 function peg$parseTag() {
609 var s0, s1, s2;
610
611 s0 = peg$currPos;
612 if (input.charCodeAt(peg$currPos) === 35) {
613 s1 = peg$c4;
614 peg$currPos++;
615 } else {
616 s1 = peg$FAILED;
617 if (peg$silentFails === 0) { peg$fail(peg$e6); }
618 }
619 if (s1 !== peg$FAILED) {
620 s2 = peg$parseWord();
621 if (s2 !== peg$FAILED) {
622 peg$savedPos = s0;
623 s0 = peg$f5(s2);
624 } else {
625 peg$currPos = s0;
626 s0 = peg$FAILED;
627 }
628 } else {
629 peg$currPos = s0;
630 s0 = peg$FAILED;
631 }
632
633 return s0;
634 }
635
636 function peg$parseWord() {
637 var s0, s1, s2;
638
639 s0 = peg$currPos;
640 s1 = [];
641 s2 = input.charAt(peg$currPos);
642 if (peg$r1.test(s2)) {
643 peg$currPos++;
644 } else {
645 s2 = peg$FAILED;
646 if (peg$silentFails === 0) { peg$fail(peg$e7); }
647 }
648 if (s2 !== peg$FAILED) {
649 while (s2 !== peg$FAILED) {
650 s1.push(s2);
651 s2 = input.charAt(peg$currPos);
652 if (peg$r1.test(s2)) {
653 peg$currPos++;
654 } else {
655 s2 = peg$FAILED;
656 if (peg$silentFails === 0) { peg$fail(peg$e7); }
657 }
658 }
659 } else {
660 s1 = peg$FAILED;
661 }
662 if (s1 !== peg$FAILED) {
663 peg$savedPos = s0;
664 s1 = peg$f6(s1);
665 }
666 s0 = s1;
667
668 return s0;
669 }
670
671 function peg$parse_() {
672 var s0, s1;
673
674 s0 = [];
675 s1 = input.charAt(peg$currPos);
676 if (peg$r2.test(s1)) {
677 peg$currPos++;
678 } else {
679 s1 = peg$FAILED;
680 if (peg$silentFails === 0) { peg$fail(peg$e8); }
681 }
682 while (s1 !== peg$FAILED) {
683 s0.push(s1);
684 s1 = input.charAt(peg$currPos);
685 if (peg$r2.test(s1)) {
686 peg$currPos++;
687 } else {
688 s1 = peg$FAILED;
689 if (peg$silentFails === 0) { peg$fail(peg$e8); }
690 }
691 }
692
693 return s0;
694 }
695
696 function peg$parseEOF() {
697 var s0, s1;
698
699 s0 = peg$currPos;
700 peg$silentFails++;
701 if (input.length > peg$currPos) {
702 s1 = input.charAt(peg$currPos);
703 peg$currPos++;
704 } else {
705 s1 = peg$FAILED;
706 if (peg$silentFails === 0) { peg$fail(peg$e0); }
707 }
708 peg$silentFails--;
709 if (s1 === peg$FAILED) {
710 s0 = undefined;
711 } else {
712 peg$currPos = s0;
713 s0 = peg$FAILED;
714 }
715
716 return s0;
717 }
718
719
720 function MakeAdd(description, attributes) {
721 return {
722 description: description,
723 attributes: attributes || []
724 };
725 }
726
727 function MakeAttributes(attributes) {
728 return attributes.flatMap(attr => attr[1]);
729 }
730
731 peg$result = peg$startRuleFunction();
732
733 if (options.peg$library) {
734 return /** @type {any} */ ({
735 peg$result,
736 peg$currPos,
737 peg$FAILED,
738 peg$maxFailExpected,
739 peg$maxFailPos
740 });
741 }
742 if (peg$result !== peg$FAILED && peg$currPos === input.length) {
743 return peg$result;
744 } else {
745 if (peg$result !== peg$FAILED && peg$currPos < input.length) {
746 peg$fail(peg$endExpectation());
747 }
748
749 throw peg$buildStructuredError(
750 peg$maxFailExpected,
751 peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
752 peg$maxFailPos < input.length
753 ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
754 : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
755 );
756 }
757}
758
759const peg$allowedStartRules = [
760 "Add"
761];
762
763export {
764 peg$allowedStartRules as StartRules,
765 peg$SyntaxError as SyntaxError,
766 peg$parse as parse
767};