1// @generated by Peggy 5.0.2.
2//
3// https://peggyjs.org/
4
5
6class peg$SyntaxError extends SyntaxError {
7 constructor(message, expected, found, location) {
8 super(message);
9 this.expected = expected;
10 this.found = found;
11 this.location = location;
12 this.name = "SyntaxError";
13 }
14
15 format(sources) {
16 let str = "Error: " + this.message;
17 if (this.location) {
18 let src = null;
19 const st = sources.find(s => s.source === this.location.source);
20 if (st) {
21 src = st.text.split(/\r\n|\n|\r/g);
22 }
23 const s = this.location.start;
24 const offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
25 ? this.location.source.offset(s)
26 : s;
27 const loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
28 if (src) {
29 const e = this.location.end;
30 const filler = "".padEnd(offset_s.line.toString().length, " ");
31 const line = src[s.line - 1];
32 const last = s.line === e.line ? e.column : line.length + 1;
33 const hatLen = (last - s.column) || 1;
34 str += "\n --> " + loc + "\n"
35 + filler + " |\n"
36 + offset_s.line + " | " + line + "\n"
37 + filler + " | " + "".padEnd(s.column - 1, " ")
38 + "".padEnd(hatLen, "^");
39 } else {
40 str += "\n at " + loc;
41 }
42 }
43 return str;
44 }
45
46 static buildMessage(expected, found) {
47 function hex(ch) {
48 return ch.codePointAt(0).toString(16).toUpperCase();
49 }
50
51 const nonPrintable = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode")
52 ? new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu")
53 : null;
54 function unicodeEscape(s) {
55 if (nonPrintable) {
56 return s.replace(nonPrintable, ch => "\\u{" + hex(ch) + "}");
57 }
58 return s;
59 }
60
61 function literalEscape(s) {
62 return unicodeEscape(s
63 .replace(/\\/g, "\\\\")
64 .replace(/"/g, "\\\"")
65 .replace(/\0/g, "\\0")
66 .replace(/\t/g, "\\t")
67 .replace(/\n/g, "\\n")
68 .replace(/\r/g, "\\r")
69 .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
70 .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
71 }
72
73 function classEscape(s) {
74 return unicodeEscape(s
75 .replace(/\\/g, "\\\\")
76 .replace(/\]/g, "\\]")
77 .replace(/\^/g, "\\^")
78 .replace(/-/g, "\\-")
79 .replace(/\0/g, "\\0")
80 .replace(/\t/g, "\\t")
81 .replace(/\n/g, "\\n")
82 .replace(/\r/g, "\\r")
83 .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
84 .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
85 }
86
87 const DESCRIBE_EXPECTATION_FNS = {
88 literal(expectation) {
89 return "\"" + literalEscape(expectation.text) + "\"";
90 },
91
92 class(expectation) {
93 const escapedParts = expectation.parts.map(
94 part => (Array.isArray(part)
95 ? classEscape(part[0]) + "-" + classEscape(part[1])
96 : classEscape(part))
97 );
98
99 return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : "");
100 },
101
102 any() {
103 return "any character";
104 },
105
106 end() {
107 return "end of input";
108 },
109
110 other(expectation) {
111 return expectation.description;
112 },
113 };
114
115 function describeExpectation(expectation) {
116 return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
117 }
118
119 function describeExpected(expected) {
120 const descriptions = expected.map(describeExpectation);
121 descriptions.sort();
122
123 if (descriptions.length > 0) {
124 let j = 1;
125 for (let i = 1; i < descriptions.length; i++) {
126 if (descriptions[i - 1] !== descriptions[i]) {
127 descriptions[j] = descriptions[i];
128 j++;
129 }
130 }
131 descriptions.length = j;
132 }
133
134 switch (descriptions.length) {
135 case 1:
136 return descriptions[0];
137
138 case 2:
139 return descriptions[0] + " or " + descriptions[1];
140
141 default:
142 return descriptions.slice(0, -1).join(", ")
143 + ", or "
144 + descriptions[descriptions.length - 1];
145 }
146 }
147
148 function describeFound(found) {
149 return found ? "\"" + literalEscape(found) + "\"" : "end of input";
150 }
151
152 return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
153 }
154}
155
156function peg$parse(input, options) {
157 options = options !== undefined ? options : {};
158
159 const peg$FAILED = {};
160 const peg$source = options.grammarSource;
161
162 const peg$startRuleFunctions = {
163 Start: peg$parseStart,
164 };
165 let peg$startRuleFunction = peg$parseStart;
166
167 const peg$c0 = "add";
168 const peg$c1 = "done";
169 const peg$c2 = "filter";
170 const peg$c3 = "modify";
171 const peg$c4 = "-";
172 const peg$c5 = ",";
173 const peg$c6 = "due:";
174 const peg$c7 = "@";
175 const peg$c8 = "pro:";
176 const peg$c9 = "project:";
177 const peg$c10 = "+";
178 const peg$c11 = "priority";
179 const peg$c12 = "!!";
180 const peg$c13 = "#";
181
182 const peg$r0 = /^[0-9]/;
183 const peg$r1 = /^[0-9\/\-]/;
184 const peg$r2 = /^[a-zA-Z0-9_\-]/;
185 const peg$r3 = /^[ \t]/;
186
187 const peg$e0 = peg$literalExpectation("add", false);
188 const peg$e1 = peg$literalExpectation("done", false);
189 const peg$e2 = peg$literalExpectation("filter", false);
190 const peg$e3 = peg$literalExpectation("modify", false);
191 const peg$e4 = peg$literalExpectation("-", false);
192 const peg$e5 = peg$literalExpectation(",", false);
193 const peg$e6 = peg$literalExpectation("due:", false);
194 const peg$e7 = peg$literalExpectation("@", false);
195 const peg$e8 = peg$literalExpectation("pro:", false);
196 const peg$e9 = peg$literalExpectation("project:", false);
197 const peg$e10 = peg$literalExpectation("+", false);
198 const peg$e11 = peg$literalExpectation("priority", false);
199 const peg$e12 = peg$literalExpectation("!!", false);
200 const peg$e13 = peg$literalExpectation("#", false);
201 const peg$e14 = peg$classExpectation([["0", "9"]], false, false, false);
202 const peg$e15 = peg$classExpectation([["0", "9"], "/", "-"], false, false, false);
203 const peg$e16 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_", "-"], false, false, false);
204 const peg$e17 = peg$classExpectation([" ", "\t"], false, false, false);
205 const peg$e18 = peg$anyExpectation();
206
207 function peg$f0(selection, parts) {
208 return makeCommand('add', selection, parts.filter(p => p !== null));
209 }
210 function peg$f1(selection, parts) {
211 return makeCommand('done', selection, parts.filter(p => p !== null));
212 }
213 function peg$f2(selection, moreFilters) {
214 return makeCommand('filter', selection, moreFilters);
215 }
216 function peg$f3(selection, moreFilters) {
217 return makeCommand('modify', selection, moreFilters);
218 }
219 function peg$f4(first, rest) {
220 return [first, ...rest.map(r => r[1])];
221 }
222 function peg$f5(start, end) {
223 const ids = [];
224 for (let i = start; i <= end; i++) {
225 ids.push(i);
226 }
227 return ids;
228 }
229 function peg$f6(id) {
230 return [id];
231 }
232 function peg$f7(first, rest) {
233 return [first, ...rest.map(r => r[1])];
234 }
235 function peg$f8(first, rest, trailing) {
236 const ids = [first, ...rest.map(r => r[1])].flat();
237 return {
238 type: 'id',
239 ids: ids,
240 reconstruct: function() { return this.ids.join(','); }
241 };
242 }
243 function peg$f9(chars) {
244 return {
245 type: "text",
246 value: chars,
247 reconstruct: function() { return this.value; }
248 };
249 }
250 function peg$f10(value) {
251 return {
252 type: "due",
253 value: value,
254 reconstruct: function() { return `@${this.value}`; }
255 };
256 }
257 function peg$f11(value) {
258 return {
259 type: "project",
260 value: value,
261 reconstruct: function() { return `+${this.value}`; }
262 };
263 }
264 function peg$f12() {
265 return {
266 type: "priority",
267 value: true,
268 reconstruct: function() { return `priority:${this.value}`; }
269 };
270 }
271 function peg$f13(value) {
272 return {
273 type: "tag",
274 value: value,
275 reconstruct: function() { return `#${this.value}`; }
276 };
277 }
278 function peg$f14(digits) {
279 return parseInt(digits.join(''), 10);
280 }
281 function peg$f15(chars) {
282 return chars.join('');
283 }
284 function peg$f16(chars) {
285 return chars.join('');
286 }
287 function peg$f17() {
288 return null;
289 }
290 let peg$currPos = options.peg$currPos | 0;
291 let peg$savedPos = peg$currPos;
292 const peg$posDetailsCache = [{ line: 1, column: 1 }];
293 let peg$maxFailPos = peg$currPos;
294 let peg$maxFailExpected = options.peg$maxFailExpected || [];
295 let peg$silentFails = options.peg$silentFails | 0;
296
297 let peg$result;
298
299 if (options.startRule) {
300 if (!(options.startRule in peg$startRuleFunctions)) {
301 throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
302 }
303
304 peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
305 }
306
307 function text() {
308 return input.substring(peg$savedPos, peg$currPos);
309 }
310
311 function offset() {
312 return peg$savedPos;
313 }
314
315 function range() {
316 return {
317 source: peg$source,
318 start: peg$savedPos,
319 end: peg$currPos,
320 };
321 }
322
323 function location() {
324 return peg$computeLocation(peg$savedPos, peg$currPos);
325 }
326
327 function expected(description, location) {
328 location = location !== undefined
329 ? location
330 : peg$computeLocation(peg$savedPos, peg$currPos);
331
332 throw peg$buildStructuredError(
333 [peg$otherExpectation(description)],
334 input.substring(peg$savedPos, peg$currPos),
335 location
336 );
337 }
338
339 function error(message, location) {
340 location = location !== undefined
341 ? location
342 : peg$computeLocation(peg$savedPos, peg$currPos);
343
344 throw peg$buildSimpleError(message, location);
345 }
346
347 function peg$getUnicode(pos = peg$currPos) {
348 const cp = input.codePointAt(pos);
349 if (cp === undefined) {
350 return "";
351 }
352 return String.fromCodePoint(cp);
353 }
354
355 function peg$literalExpectation(text, ignoreCase) {
356 return { type: "literal", text, ignoreCase };
357 }
358
359 function peg$classExpectation(parts, inverted, ignoreCase, unicode) {
360 return { type: "class", parts, inverted, ignoreCase, unicode };
361 }
362
363 function peg$anyExpectation() {
364 return { type: "any" };
365 }
366
367 function peg$endExpectation() {
368 return { type: "end" };
369 }
370
371 function peg$otherExpectation(description) {
372 return { type: "other", description };
373 }
374
375 function peg$computePosDetails(pos) {
376 let details = peg$posDetailsCache[pos];
377 let p;
378
379 if (details) {
380 return details;
381 } else {
382 if (pos >= peg$posDetailsCache.length) {
383 p = peg$posDetailsCache.length - 1;
384 } else {
385 p = pos;
386 while (!peg$posDetailsCache[--p]) {}
387 }
388
389 details = peg$posDetailsCache[p];
390 details = {
391 line: details.line,
392 column: details.column,
393 };
394
395 while (p < pos) {
396 if (input.charCodeAt(p) === 10) {
397 details.line++;
398 details.column = 1;
399 } else {
400 details.column++;
401 }
402
403 p++;
404 }
405
406 peg$posDetailsCache[pos] = details;
407
408 return details;
409 }
410 }
411
412 function peg$computeLocation(startPos, endPos, offset) {
413 const startPosDetails = peg$computePosDetails(startPos);
414 const endPosDetails = peg$computePosDetails(endPos);
415
416 const res = {
417 source: peg$source,
418 start: {
419 offset: startPos,
420 line: startPosDetails.line,
421 column: startPosDetails.column,
422 },
423 end: {
424 offset: endPos,
425 line: endPosDetails.line,
426 column: endPosDetails.column,
427 },
428 };
429 if (offset && peg$source && (typeof peg$source.offset === "function")) {
430 res.start = peg$source.offset(res.start);
431 res.end = peg$source.offset(res.end);
432 }
433 return res;
434 }
435
436 function peg$fail(expected) {
437 if (peg$currPos < peg$maxFailPos) { return; }
438
439 if (peg$currPos > peg$maxFailPos) {
440 peg$maxFailPos = peg$currPos;
441 peg$maxFailExpected = [];
442 }
443
444 peg$maxFailExpected.push(expected);
445 }
446
447 function peg$buildSimpleError(message, location) {
448 return new peg$SyntaxError(message, null, null, location);
449 }
450
451 function peg$buildStructuredError(expected, found, location) {
452 return new peg$SyntaxError(
453 peg$SyntaxError.buildMessage(expected, found),
454 expected,
455 found,
456 location
457 );
458 }
459
460 function peg$parseStart() {
461 let s0;
462
463 s0 = peg$parseAddCommand();
464 if (s0 === peg$FAILED) {
465 s0 = peg$parseDoneCommand();
466 if (s0 === peg$FAILED) {
467 s0 = peg$parseExplicitFilterCommand();
468 if (s0 === peg$FAILED) {
469 s0 = peg$parseModifyCommand();
470 }
471 }
472 }
473
474 return s0;
475 }
476
477 function peg$parseAddCommand() {
478 let s0, s1, s2, s3, s4, s5, s6;
479
480 s0 = peg$currPos;
481 s1 = peg$parseSelections();
482 if (s1 === peg$FAILED) {
483 s1 = null;
484 }
485 s2 = peg$parse_();
486 if (s2 === peg$FAILED) {
487 s2 = null;
488 }
489 if (input.substr(peg$currPos, 3) === peg$c0) {
490 s3 = peg$c0;
491 peg$currPos += 3;
492 } else {
493 s3 = peg$FAILED;
494 if (peg$silentFails === 0) { peg$fail(peg$e0); }
495 }
496 if (s3 !== peg$FAILED) {
497 s4 = peg$parse_();
498 if (s4 !== peg$FAILED) {
499 s5 = [];
500 s6 = peg$parsePart();
501 if (s6 === peg$FAILED) {
502 s6 = peg$parse_();
503 }
504 if (s6 !== peg$FAILED) {
505 while (s6 !== peg$FAILED) {
506 s5.push(s6);
507 s6 = peg$parsePart();
508 if (s6 === peg$FAILED) {
509 s6 = peg$parse_();
510 }
511 }
512 } else {
513 s5 = peg$FAILED;
514 }
515 if (s5 !== peg$FAILED) {
516 s6 = peg$parseEOF();
517 if (s6 !== peg$FAILED) {
518 peg$savedPos = s0;
519 s0 = peg$f0(s1, s5);
520 } else {
521 peg$currPos = s0;
522 s0 = peg$FAILED;
523 }
524 } else {
525 peg$currPos = s0;
526 s0 = peg$FAILED;
527 }
528 } else {
529 peg$currPos = s0;
530 s0 = peg$FAILED;
531 }
532 } else {
533 peg$currPos = s0;
534 s0 = peg$FAILED;
535 }
536
537 return s0;
538 }
539
540 function peg$parseDoneCommand() {
541 let s0, s1, s2, s3, s4, s5, s6;
542
543 s0 = peg$currPos;
544 s1 = peg$parseSelections();
545 if (s1 === peg$FAILED) {
546 s1 = null;
547 }
548 s2 = peg$parse_();
549 if (s2 === peg$FAILED) {
550 s2 = null;
551 }
552 if (input.substr(peg$currPos, 4) === peg$c1) {
553 s3 = peg$c1;
554 peg$currPos += 4;
555 } else {
556 s3 = peg$FAILED;
557 if (peg$silentFails === 0) { peg$fail(peg$e1); }
558 }
559 if (s3 !== peg$FAILED) {
560 s4 = peg$parse_();
561 if (s4 === peg$FAILED) {
562 s4 = null;
563 }
564 s5 = [];
565 s6 = peg$parsePart();
566 if (s6 === peg$FAILED) {
567 s6 = peg$parse_();
568 }
569 while (s6 !== peg$FAILED) {
570 s5.push(s6);
571 s6 = peg$parsePart();
572 if (s6 === peg$FAILED) {
573 s6 = peg$parse_();
574 }
575 }
576 s6 = peg$parseEOF();
577 if (s6 !== peg$FAILED) {
578 peg$savedPos = s0;
579 s0 = peg$f1(s1, s5);
580 } else {
581 peg$currPos = s0;
582 s0 = peg$FAILED;
583 }
584 } else {
585 peg$currPos = s0;
586 s0 = peg$FAILED;
587 }
588
589 return s0;
590 }
591
592 function peg$parseExplicitFilterCommand() {
593 let s0, s1, s2, s3, s4, s5, s6;
594
595 s0 = peg$currPos;
596 s1 = peg$parseSelections();
597 if (s1 === peg$FAILED) {
598 s1 = null;
599 }
600 s2 = peg$parse_();
601 if (s2 === peg$FAILED) {
602 s2 = null;
603 }
604 if (input.substr(peg$currPos, 6) === peg$c2) {
605 s3 = peg$c2;
606 peg$currPos += 6;
607 } else {
608 s3 = peg$FAILED;
609 if (peg$silentFails === 0) { peg$fail(peg$e2); }
610 }
611 if (s3 !== peg$FAILED) {
612 s4 = [];
613 s5 = peg$parse_();
614 while (s5 !== peg$FAILED) {
615 s4.push(s5);
616 s5 = peg$parse_();
617 }
618 s5 = peg$parseFilters();
619 if (s5 !== peg$FAILED) {
620 s6 = peg$parseEOF();
621 if (s6 !== peg$FAILED) {
622 peg$savedPos = s0;
623 s0 = peg$f2(s1, s5);
624 } else {
625 peg$currPos = s0;
626 s0 = peg$FAILED;
627 }
628 } else {
629 peg$currPos = s0;
630 s0 = peg$FAILED;
631 }
632 } else {
633 peg$currPos = s0;
634 s0 = peg$FAILED;
635 }
636
637 return s0;
638 }
639
640 function peg$parseModifyCommand() {
641 let s0, s1, s2, s3, s4, s5, s6;
642
643 s0 = peg$currPos;
644 s1 = peg$parseSelections();
645 if (s1 === peg$FAILED) {
646 s1 = null;
647 }
648 s2 = peg$parse_();
649 if (s2 === peg$FAILED) {
650 s2 = null;
651 }
652 if (input.substr(peg$currPos, 6) === peg$c3) {
653 s3 = peg$c3;
654 peg$currPos += 6;
655 } else {
656 s3 = peg$FAILED;
657 if (peg$silentFails === 0) { peg$fail(peg$e3); }
658 }
659 if (s3 !== peg$FAILED) {
660 s4 = [];
661 s5 = peg$parse_();
662 while (s5 !== peg$FAILED) {
663 s4.push(s5);
664 s5 = peg$parse_();
665 }
666 s5 = peg$parseFilters();
667 if (s5 !== peg$FAILED) {
668 s6 = peg$parseEOF();
669 if (s6 !== peg$FAILED) {
670 peg$savedPos = s0;
671 s0 = peg$f3(s1, s5);
672 } else {
673 peg$currPos = s0;
674 s0 = peg$FAILED;
675 }
676 } else {
677 peg$currPos = s0;
678 s0 = peg$FAILED;
679 }
680 } else {
681 peg$currPos = s0;
682 s0 = peg$FAILED;
683 }
684
685 return s0;
686 }
687
688 function peg$parseFilters() {
689 let s0, s1, s2, s3, s4, s5;
690
691 s0 = peg$currPos;
692 s1 = peg$parsePart();
693 if (s1 !== peg$FAILED) {
694 s2 = [];
695 s3 = peg$currPos;
696 s4 = peg$parse_();
697 if (s4 !== peg$FAILED) {
698 s5 = peg$parsePart();
699 if (s5 !== peg$FAILED) {
700 s4 = [s4, s5];
701 s3 = s4;
702 } else {
703 peg$currPos = s3;
704 s3 = peg$FAILED;
705 }
706 } else {
707 peg$currPos = s3;
708 s3 = peg$FAILED;
709 }
710 while (s3 !== peg$FAILED) {
711 s2.push(s3);
712 s3 = peg$currPos;
713 s4 = peg$parse_();
714 if (s4 !== peg$FAILED) {
715 s5 = peg$parsePart();
716 if (s5 !== peg$FAILED) {
717 s4 = [s4, s5];
718 s3 = s4;
719 } else {
720 peg$currPos = s3;
721 s3 = peg$FAILED;
722 }
723 } else {
724 peg$currPos = s3;
725 s3 = peg$FAILED;
726 }
727 }
728 peg$savedPos = s0;
729 s0 = peg$f4(s1, s2);
730 } else {
731 peg$currPos = s0;
732 s0 = peg$FAILED;
733 }
734
735 return s0;
736 }
737
738 function peg$parseIdRange() {
739 let s0, s1, s2, s3;
740
741 s0 = peg$currPos;
742 s1 = peg$parseInteger();
743 if (s1 !== peg$FAILED) {
744 if (input.charCodeAt(peg$currPos) === 45) {
745 s2 = peg$c4;
746 peg$currPos++;
747 } else {
748 s2 = peg$FAILED;
749 if (peg$silentFails === 0) { peg$fail(peg$e4); }
750 }
751 if (s2 !== peg$FAILED) {
752 s3 = peg$parseInteger();
753 if (s3 !== peg$FAILED) {
754 peg$savedPos = s0;
755 s0 = peg$f5(s1, s3);
756 } else {
757 peg$currPos = s0;
758 s0 = peg$FAILED;
759 }
760 } else {
761 peg$currPos = s0;
762 s0 = peg$FAILED;
763 }
764 } else {
765 peg$currPos = s0;
766 s0 = peg$FAILED;
767 }
768
769 return s0;
770 }
771
772 function peg$parseSingleId() {
773 let s0, s1;
774
775 s0 = peg$currPos;
776 s1 = peg$parseInteger();
777 if (s1 !== peg$FAILED) {
778 peg$savedPos = s0;
779 s1 = peg$f6(s1);
780 }
781 s0 = s1;
782
783 return s0;
784 }
785
786 function peg$parseSelections() {
787 let s0, s1, s2, s3, s4, s5;
788
789 s0 = peg$currPos;
790 s1 = peg$parseSelection();
791 if (s1 !== peg$FAILED) {
792 s2 = [];
793 s3 = peg$currPos;
794 s4 = peg$parse_();
795 if (s4 !== peg$FAILED) {
796 s5 = peg$parseSelection();
797 if (s5 !== peg$FAILED) {
798 s4 = [s4, s5];
799 s3 = s4;
800 } else {
801 peg$currPos = s3;
802 s3 = peg$FAILED;
803 }
804 } else {
805 peg$currPos = s3;
806 s3 = peg$FAILED;
807 }
808 while (s3 !== peg$FAILED) {
809 s2.push(s3);
810 s3 = peg$currPos;
811 s4 = peg$parse_();
812 if (s4 !== peg$FAILED) {
813 s5 = peg$parseSelection();
814 if (s5 !== peg$FAILED) {
815 s4 = [s4, s5];
816 s3 = s4;
817 } else {
818 peg$currPos = s3;
819 s3 = peg$FAILED;
820 }
821 } else {
822 peg$currPos = s3;
823 s3 = peg$FAILED;
824 }
825 }
826 peg$savedPos = s0;
827 s0 = peg$f7(s1, s2);
828 } else {
829 peg$currPos = s0;
830 s0 = peg$FAILED;
831 }
832
833 return s0;
834 }
835
836 function peg$parseSelection() {
837 let s0;
838
839 s0 = peg$parseIdFilter();
840 if (s0 === peg$FAILED) {
841 s0 = peg$parseAttribute();
842 }
843
844 return s0;
845 }
846
847 function peg$parseIdFilter() {
848 let s0, s1, s2, s3, s4, s5;
849
850 s0 = peg$currPos;
851 s1 = peg$parseIdRange();
852 if (s1 === peg$FAILED) {
853 s1 = peg$parseSingleId();
854 }
855 if (s1 !== peg$FAILED) {
856 s2 = [];
857 s3 = peg$currPos;
858 if (input.charCodeAt(peg$currPos) === 44) {
859 s4 = peg$c5;
860 peg$currPos++;
861 } else {
862 s4 = peg$FAILED;
863 if (peg$silentFails === 0) { peg$fail(peg$e5); }
864 }
865 if (s4 !== peg$FAILED) {
866 s5 = peg$parseIdRange();
867 if (s5 === peg$FAILED) {
868 s5 = peg$parseSingleId();
869 }
870 if (s5 !== peg$FAILED) {
871 s4 = [s4, s5];
872 s3 = s4;
873 } else {
874 peg$currPos = s3;
875 s3 = peg$FAILED;
876 }
877 } else {
878 peg$currPos = s3;
879 s3 = peg$FAILED;
880 }
881 while (s3 !== peg$FAILED) {
882 s2.push(s3);
883 s3 = peg$currPos;
884 if (input.charCodeAt(peg$currPos) === 44) {
885 s4 = peg$c5;
886 peg$currPos++;
887 } else {
888 s4 = peg$FAILED;
889 if (peg$silentFails === 0) { peg$fail(peg$e5); }
890 }
891 if (s4 !== peg$FAILED) {
892 s5 = peg$parseIdRange();
893 if (s5 === peg$FAILED) {
894 s5 = peg$parseSingleId();
895 }
896 if (s5 !== peg$FAILED) {
897 s4 = [s4, s5];
898 s3 = s4;
899 } else {
900 peg$currPos = s3;
901 s3 = peg$FAILED;
902 }
903 } else {
904 peg$currPos = s3;
905 s3 = peg$FAILED;
906 }
907 }
908 if (input.charCodeAt(peg$currPos) === 44) {
909 s3 = peg$c5;
910 peg$currPos++;
911 } else {
912 s3 = peg$FAILED;
913 if (peg$silentFails === 0) { peg$fail(peg$e5); }
914 }
915 if (s3 === peg$FAILED) {
916 s3 = null;
917 }
918 peg$savedPos = s0;
919 s0 = peg$f8(s1, s2, s3);
920 } else {
921 peg$currPos = s0;
922 s0 = peg$FAILED;
923 }
924
925 return s0;
926 }
927
928 function peg$parsePart() {
929 let s0;
930
931 s0 = peg$parseAttribute();
932 if (s0 === peg$FAILED) {
933 s0 = peg$parseTextPart();
934 }
935
936 return s0;
937 }
938
939 function peg$parseTextPart() {
940 let s0, s1;
941
942 s0 = peg$currPos;
943 s1 = peg$parseWord();
944 if (s1 !== peg$FAILED) {
945 peg$savedPos = s0;
946 s1 = peg$f9(s1);
947 }
948 s0 = s1;
949
950 return s0;
951 }
952
953 function peg$parseAttribute() {
954 let s0;
955
956 s0 = peg$parseDue();
957 if (s0 === peg$FAILED) {
958 s0 = peg$parseTag();
959 if (s0 === peg$FAILED) {
960 s0 = peg$parseProject();
961 if (s0 === peg$FAILED) {
962 s0 = peg$parsePriority();
963 }
964 }
965 }
966
967 return s0;
968 }
969
970 function peg$parseDue() {
971 let s0, s1, s2;
972
973 s0 = peg$currPos;
974 if (input.substr(peg$currPos, 4) === peg$c6) {
975 s1 = peg$c6;
976 peg$currPos += 4;
977 } else {
978 s1 = peg$FAILED;
979 if (peg$silentFails === 0) { peg$fail(peg$e6); }
980 }
981 if (s1 === peg$FAILED) {
982 if (input.charCodeAt(peg$currPos) === 64) {
983 s1 = peg$c7;
984 peg$currPos++;
985 } else {
986 s1 = peg$FAILED;
987 if (peg$silentFails === 0) { peg$fail(peg$e7); }
988 }
989 }
990 if (s1 !== peg$FAILED) {
991 s2 = peg$parseDateValue();
992 if (s2 !== peg$FAILED) {
993 peg$savedPos = s0;
994 s0 = peg$f10(s2);
995 } else {
996 peg$currPos = s0;
997 s0 = peg$FAILED;
998 }
999 } else {
1000 peg$currPos = s0;
1001 s0 = peg$FAILED;
1002 }
1003
1004 return s0;
1005 }
1006
1007 function peg$parseProject() {
1008 let s0, s1, s2;
1009
1010 s0 = peg$currPos;
1011 if (input.substr(peg$currPos, 4) === peg$c8) {
1012 s1 = peg$c8;
1013 peg$currPos += 4;
1014 } else {
1015 s1 = peg$FAILED;
1016 if (peg$silentFails === 0) { peg$fail(peg$e8); }
1017 }
1018 if (s1 === peg$FAILED) {
1019 if (input.substr(peg$currPos, 8) === peg$c9) {
1020 s1 = peg$c9;
1021 peg$currPos += 8;
1022 } else {
1023 s1 = peg$FAILED;
1024 if (peg$silentFails === 0) { peg$fail(peg$e9); }
1025 }
1026 if (s1 === peg$FAILED) {
1027 if (input.charCodeAt(peg$currPos) === 43) {
1028 s1 = peg$c10;
1029 peg$currPos++;
1030 } else {
1031 s1 = peg$FAILED;
1032 if (peg$silentFails === 0) { peg$fail(peg$e10); }
1033 }
1034 }
1035 }
1036 if (s1 !== peg$FAILED) {
1037 s2 = peg$parseWord();
1038 if (s2 !== peg$FAILED) {
1039 peg$savedPos = s0;
1040 s0 = peg$f11(s2);
1041 } else {
1042 peg$currPos = s0;
1043 s0 = peg$FAILED;
1044 }
1045 } else {
1046 peg$currPos = s0;
1047 s0 = peg$FAILED;
1048 }
1049
1050 return s0;
1051 }
1052
1053 function peg$parsePriority() {
1054 let s0, s1;
1055
1056 s0 = peg$currPos;
1057 if (input.substr(peg$currPos, 8) === peg$c11) {
1058 s1 = peg$c11;
1059 peg$currPos += 8;
1060 } else {
1061 s1 = peg$FAILED;
1062 if (peg$silentFails === 0) { peg$fail(peg$e11); }
1063 }
1064 if (s1 === peg$FAILED) {
1065 if (input.substr(peg$currPos, 2) === peg$c12) {
1066 s1 = peg$c12;
1067 peg$currPos += 2;
1068 } else {
1069 s1 = peg$FAILED;
1070 if (peg$silentFails === 0) { peg$fail(peg$e12); }
1071 }
1072 }
1073 if (s1 !== peg$FAILED) {
1074 peg$savedPos = s0;
1075 s1 = peg$f12();
1076 }
1077 s0 = s1;
1078
1079 return s0;
1080 }
1081
1082 function peg$parseTag() {
1083 let s0, s1, s2;
1084
1085 s0 = peg$currPos;
1086 if (input.charCodeAt(peg$currPos) === 35) {
1087 s1 = peg$c13;
1088 peg$currPos++;
1089 } else {
1090 s1 = peg$FAILED;
1091 if (peg$silentFails === 0) { peg$fail(peg$e13); }
1092 }
1093 if (s1 !== peg$FAILED) {
1094 s2 = peg$parseWord();
1095 if (s2 !== peg$FAILED) {
1096 peg$savedPos = s0;
1097 s0 = peg$f13(s2);
1098 } else {
1099 peg$currPos = s0;
1100 s0 = peg$FAILED;
1101 }
1102 } else {
1103 peg$currPos = s0;
1104 s0 = peg$FAILED;
1105 }
1106
1107 return s0;
1108 }
1109
1110 function peg$parseInteger() {
1111 let s0, s1, s2;
1112
1113 s0 = peg$currPos;
1114 s1 = [];
1115 s2 = input.charAt(peg$currPos);
1116 if (peg$r0.test(s2)) {
1117 peg$currPos++;
1118 } else {
1119 s2 = peg$FAILED;
1120 if (peg$silentFails === 0) { peg$fail(peg$e14); }
1121 }
1122 if (s2 !== peg$FAILED) {
1123 while (s2 !== peg$FAILED) {
1124 s1.push(s2);
1125 s2 = input.charAt(peg$currPos);
1126 if (peg$r0.test(s2)) {
1127 peg$currPos++;
1128 } else {
1129 s2 = peg$FAILED;
1130 if (peg$silentFails === 0) { peg$fail(peg$e14); }
1131 }
1132 }
1133 } else {
1134 s1 = peg$FAILED;
1135 }
1136 if (s1 !== peg$FAILED) {
1137 peg$savedPos = s0;
1138 s1 = peg$f14(s1);
1139 }
1140 s0 = s1;
1141
1142 return s0;
1143 }
1144
1145 function peg$parseDateValue() {
1146 let s0, s1, s2;
1147
1148 s0 = peg$currPos;
1149 s1 = [];
1150 s2 = input.charAt(peg$currPos);
1151 if (peg$r1.test(s2)) {
1152 peg$currPos++;
1153 } else {
1154 s2 = peg$FAILED;
1155 if (peg$silentFails === 0) { peg$fail(peg$e15); }
1156 }
1157 if (s2 !== peg$FAILED) {
1158 while (s2 !== peg$FAILED) {
1159 s1.push(s2);
1160 s2 = input.charAt(peg$currPos);
1161 if (peg$r1.test(s2)) {
1162 peg$currPos++;
1163 } else {
1164 s2 = peg$FAILED;
1165 if (peg$silentFails === 0) { peg$fail(peg$e15); }
1166 }
1167 }
1168 } else {
1169 s1 = peg$FAILED;
1170 }
1171 if (s1 !== peg$FAILED) {
1172 peg$savedPos = s0;
1173 s1 = peg$f15(s1);
1174 }
1175 s0 = s1;
1176
1177 return s0;
1178 }
1179
1180 function peg$parseWord() {
1181 let s0, s1, s2;
1182
1183 s0 = peg$currPos;
1184 s1 = [];
1185 s2 = input.charAt(peg$currPos);
1186 if (peg$r2.test(s2)) {
1187 peg$currPos++;
1188 } else {
1189 s2 = peg$FAILED;
1190 if (peg$silentFails === 0) { peg$fail(peg$e16); }
1191 }
1192 if (s2 !== peg$FAILED) {
1193 while (s2 !== peg$FAILED) {
1194 s1.push(s2);
1195 s2 = input.charAt(peg$currPos);
1196 if (peg$r2.test(s2)) {
1197 peg$currPos++;
1198 } else {
1199 s2 = peg$FAILED;
1200 if (peg$silentFails === 0) { peg$fail(peg$e16); }
1201 }
1202 }
1203 } else {
1204 s1 = peg$FAILED;
1205 }
1206 if (s1 !== peg$FAILED) {
1207 peg$savedPos = s0;
1208 s1 = peg$f16(s1);
1209 }
1210 s0 = s1;
1211
1212 return s0;
1213 }
1214
1215 function peg$parse_() {
1216 let s0, s1, s2;
1217
1218 s0 = peg$currPos;
1219 s1 = [];
1220 s2 = input.charAt(peg$currPos);
1221 if (peg$r3.test(s2)) {
1222 peg$currPos++;
1223 } else {
1224 s2 = peg$FAILED;
1225 if (peg$silentFails === 0) { peg$fail(peg$e17); }
1226 }
1227 if (s2 !== peg$FAILED) {
1228 while (s2 !== peg$FAILED) {
1229 s1.push(s2);
1230 s2 = input.charAt(peg$currPos);
1231 if (peg$r3.test(s2)) {
1232 peg$currPos++;
1233 } else {
1234 s2 = peg$FAILED;
1235 if (peg$silentFails === 0) { peg$fail(peg$e17); }
1236 }
1237 }
1238 } else {
1239 s1 = peg$FAILED;
1240 }
1241 if (s1 !== peg$FAILED) {
1242 peg$savedPos = s0;
1243 s1 = peg$f17();
1244 }
1245 s0 = s1;
1246
1247 return s0;
1248 }
1249
1250 function peg$parseEOF() {
1251 let s0, s1;
1252
1253 s0 = peg$currPos;
1254 peg$silentFails++;
1255 if (input.length > peg$currPos) {
1256 s1 = input.charAt(peg$currPos);
1257 peg$currPos++;
1258 } else {
1259 s1 = peg$FAILED;
1260 if (peg$silentFails === 0) { peg$fail(peg$e18); }
1261 }
1262 peg$silentFails--;
1263 if (s1 === peg$FAILED) {
1264 s0 = undefined;
1265 } else {
1266 peg$currPos = s0;
1267 s0 = peg$FAILED;
1268 }
1269
1270 return s0;
1271 }
1272
1273
1274 function makeCommand(action, selection, parts) {
1275
1276 const validParts = parts || [];
1277 // Extract pure description (without attributes)
1278 const description = validParts
1279 .filter(part => part.type === 'text')
1280 .map(part => part.value)
1281 .join(' ')
1282 .trim();
1283
1284 // Collect all attributes
1285 const attributes = validParts
1286 .filter(part => part.type !== 'text')
1287 .filter(part => part !== null);
1288
1289 const project = validParts
1290 .filter(part => part.type === 'project')
1291 .map(part => part.value)
1292 .join('')
1293 .trim();
1294
1295 const tags = validParts
1296 .filter(part => part.type === 'tag')
1297 .map(part => part.value);
1298
1299 // Extract priority flag
1300 const hasPriority = validParts.some(part => part.type === 'priority');
1301
1302 // Extract due date
1303 const dueDate = validParts
1304 .filter(part => part.type === 'due')
1305 .map(part => part.value)[0] || null;
1306
1307 return {
1308 action: action,
1309 selection: selection || [],
1310 description: description || [],
1311 attributes: attributes || [],
1312 project: project,
1313 tags: tags,
1314 priority: hasPriority,
1315 due: dueDate,
1316 parts: parts || [],
1317 reconstruct: function() {
1318 const filterStr = this.filters.map(f => f.reconstruct()).join(',');
1319 const partsStr = this.parts.map(p => p.reconstruct()).join(' ');
1320 return [filterStr, this.type, partsStr].filter(Boolean).join(' ');
1321 }
1322 };
1323 }
1324
1325 peg$result = peg$startRuleFunction();
1326
1327 const peg$success = (peg$result !== peg$FAILED && peg$currPos === input.length);
1328 function peg$throw() {
1329 if (peg$result !== peg$FAILED && peg$currPos < input.length) {
1330 peg$fail(peg$endExpectation());
1331 }
1332
1333 throw peg$buildStructuredError(
1334 peg$maxFailExpected,
1335 peg$maxFailPos < input.length ? peg$getUnicode(peg$maxFailPos) : null,
1336 peg$maxFailPos < input.length
1337 ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
1338 : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
1339 );
1340 }
1341 if (options.peg$library) {
1342 return /** @type {any} */ ({
1343 peg$result,
1344 peg$currPos,
1345 peg$FAILED,
1346 peg$maxFailExpected,
1347 peg$maxFailPos,
1348 peg$success,
1349 peg$throw: peg$success ? undefined : peg$throw,
1350 });
1351 }
1352 if (peg$success) {
1353 return peg$result;
1354 } else {
1355 peg$throw();
1356 }
1357}
1358
1359const peg$allowedStartRules = [
1360 "Start"
1361];
1362
1363export {
1364 peg$allowedStartRules as StartRules,
1365 peg$SyntaxError as SyntaxError,
1366 peg$parse as parse
1367};