this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

web: use parser in web

+78 -33
+38 -6
js/src/App.svelte
··· 4 4 import wasmUrl from '@vlcn.io/crsqlite-wasm/crsqlite.wasm?url'; 5 5 import { start } from "@vlcn.io/ws-client/worker.js"; 6 6 import { createDbProvider } from "@vlcn.io/ws-browserdb"; 7 + import * as addParser from '../../parser/add_parser.js'; 7 8 8 9 let db; 9 10 let ws; ··· 17 18 await db.exec(` 18 19 CREATE TABLE IF NOT EXISTS todos ( 19 20 id BLOB PRIMARY KEY NOT NULL, 20 - content TEXT, 21 + description TEXT, 22 + project text, 23 + tags text, 24 + due text, 25 + wait text, 26 + priority text, 27 + urgency real, 21 28 completed INTEGER NOT NULL DEFAULT 0 22 29 ); 23 30 SELECT crsql_as_crr('todos'); ··· 87 94 todos = result; 88 95 } 89 96 97 + // TODO: 98 + // This is fucking sucks 99 + // make the stupid parser do this 😩 100 + async function Marshall(parsed) { 101 + let project = ""; 102 + const tags = []; 103 + console.log(parsed); 104 + for (const attr of parsed.attributes) { 105 + console.log(attr); 106 + switch (attr.type) { 107 + case 'project': 108 + console.log("project" + attr.value); 109 + project = attr.value; 110 + break; 111 + case 'tag': 112 + console.log("tag" + attr.value); 113 + tags.push(attr.value); 114 + break; 115 + } 116 + } 117 + return {description: parsed.description, tags: tags, project: project}; 118 + } 119 + 90 120 async function addTodo() { 91 121 if (newTodo.trim()) { 122 + const parsed = await Marshall(addParser.parse(newTodo)); 123 + console.log(parsed); 92 124 await db.exec(` 93 - INSERT INTO todos (id, content, completed) 94 - VALUES (lower(hex(randomblob(16))), ?, 0) 95 - `, [newTodo.trim()]); 125 + INSERT INTO todos (id, description, tags, project, completed) 126 + VALUES (lower(hex(randomblob(16))), ?, ?, ?, 0) 127 + `, [parsed.description, JSON.stringify(parsed.tags), parsed.project]); 96 128 newTodo = ''; 97 129 loadTodos(); 98 130 } ··· 109 141 </script> 110 142 111 143 <main> 112 - <h1>Svelte Todo with cr-sqlite</h1> 144 + <h1>Mast</h1> 113 145 <input 114 146 bind:value={newTodo} 115 147 on:keypress={(e) => e.key === 'Enter' && addTodo()} ··· 124 156 checked={todo.completed} 125 157 on:change={() => toggleTodo(todo.id)} 126 158 /> 127 - <span class:completed={todo.completed}>{todo.content}</span> 159 + <span class:completed={todo.completed}>{todo.description} pro:{todo.project} {todo.tags}</span> 128 160 </li> 129 161 {/each} 130 162 </ul>
+2 -2
parser/add_js.peg
··· 25 25 26 26 Attribute = Project / Priority / Tag 27 27 28 - Project = ("pro:" / "project:") value:Word { 28 + Project = ("pro:" / "project:" / "+") value:Word { 29 29 return { type: "project", value: value }; 30 30 } 31 31 ··· 33 33 return { type: "priority", value: value }; 34 34 } 35 35 36 - Tag = "+" value:Word { 36 + Tag = "#" value:Word { 37 37 return { type: "tag", value: value }; 38 38 } 39 39
+38 -25
parser/add_parser.js
··· 1 - // @generated by Peggy 4.0.3. 1 + // @generated by Peggy 4.1.1. 2 2 // 3 3 // https://peggyjs.org/ 4 - 5 - "use strict"; 6 4 7 5 8 6 function peg$subclass(child, parent) { ··· 179 177 180 178 var peg$c0 = "pro:"; 181 179 var peg$c1 = "project:"; 182 - var peg$c2 = "priority:"; 183 - var peg$c3 = "+"; 180 + var peg$c2 = "+"; 181 + var peg$c3 = "priority:"; 182 + var peg$c4 = "#"; 184 183 185 184 var peg$r0 = /^[HML]/; 186 185 var peg$r1 = /^[a-zA-Z0-9_\-]/; ··· 189 188 var peg$e0 = peg$anyExpectation(); 190 189 var peg$e1 = peg$literalExpectation("pro:", false); 191 190 var peg$e2 = peg$literalExpectation("project:", false); 192 - var peg$e3 = peg$literalExpectation("priority:", false); 193 - var peg$e4 = peg$classExpectation(["H", "M", "L"], false, false); 194 - var peg$e5 = peg$literalExpectation("+", false); 195 - var peg$e6 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_", "-"], false, false); 196 - var peg$e7 = peg$classExpectation([" ", "\\", "t"], false, 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 197 198 198 var peg$f0 = function(desc, attributes) { 199 199 return MakeAdd(desc, attributes); ··· 544 544 s1 = peg$FAILED; 545 545 if (peg$silentFails === 0) { peg$fail(peg$e2); } 546 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 + } 547 556 } 548 557 if (s1 !== peg$FAILED) { 549 558 s2 = peg$parseWord(); ··· 566 575 var s0, s1, s2; 567 576 568 577 s0 = peg$currPos; 569 - if (input.substr(peg$currPos, 9) === peg$c2) { 570 - s1 = peg$c2; 578 + if (input.substr(peg$currPos, 9) === peg$c3) { 579 + s1 = peg$c3; 571 580 peg$currPos += 9; 572 581 } else { 573 582 s1 = peg$FAILED; 574 - if (peg$silentFails === 0) { peg$fail(peg$e3); } 583 + if (peg$silentFails === 0) { peg$fail(peg$e4); } 575 584 } 576 585 if (s1 !== peg$FAILED) { 577 586 s2 = input.charAt(peg$currPos); ··· 579 588 peg$currPos++; 580 589 } else { 581 590 s2 = peg$FAILED; 582 - if (peg$silentFails === 0) { peg$fail(peg$e4); } 591 + if (peg$silentFails === 0) { peg$fail(peg$e5); } 583 592 } 584 593 if (s2 !== peg$FAILED) { 585 594 peg$savedPos = s0; ··· 600 609 var s0, s1, s2; 601 610 602 611 s0 = peg$currPos; 603 - if (input.charCodeAt(peg$currPos) === 43) { 604 - s1 = peg$c3; 612 + if (input.charCodeAt(peg$currPos) === 35) { 613 + s1 = peg$c4; 605 614 peg$currPos++; 606 615 } else { 607 616 s1 = peg$FAILED; 608 - if (peg$silentFails === 0) { peg$fail(peg$e5); } 617 + if (peg$silentFails === 0) { peg$fail(peg$e6); } 609 618 } 610 619 if (s1 !== peg$FAILED) { 611 620 s2 = peg$parseWord(); ··· 634 643 peg$currPos++; 635 644 } else { 636 645 s2 = peg$FAILED; 637 - if (peg$silentFails === 0) { peg$fail(peg$e6); } 646 + if (peg$silentFails === 0) { peg$fail(peg$e7); } 638 647 } 639 648 if (s2 !== peg$FAILED) { 640 649 while (s2 !== peg$FAILED) { ··· 644 653 peg$currPos++; 645 654 } else { 646 655 s2 = peg$FAILED; 647 - if (peg$silentFails === 0) { peg$fail(peg$e6); } 656 + if (peg$silentFails === 0) { peg$fail(peg$e7); } 648 657 } 649 658 } 650 659 } else { ··· 668 677 peg$currPos++; 669 678 } else { 670 679 s1 = peg$FAILED; 671 - if (peg$silentFails === 0) { peg$fail(peg$e7); } 680 + if (peg$silentFails === 0) { peg$fail(peg$e8); } 672 681 } 673 682 while (s1 !== peg$FAILED) { 674 683 s0.push(s1); ··· 677 686 peg$currPos++; 678 687 } else { 679 688 s1 = peg$FAILED; 680 - if (peg$silentFails === 0) { peg$fail(peg$e7); } 689 + if (peg$silentFails === 0) { peg$fail(peg$e8); } 681 690 } 682 691 } 683 692 ··· 747 756 } 748 757 } 749 758 750 - module.exports = { 751 - StartRules: ["Add"], 752 - SyntaxError: peg$SyntaxError, 753 - parse: peg$parse 759 + const peg$allowedStartRules = [ 760 + "Add" 761 + ]; 762 + 763 + export { 764 + peg$allowedStartRules as StartRules, 765 + peg$SyntaxError as SyntaxError, 766 + peg$parse as parse 754 767 };