diff --git a/js/src/App.svelte b/js/src/App.svelte index 46b1cc6..d35586c 100644 --- a/js/src/App.svelte +++ b/js/src/App.svelte @@ -4,6 +4,7 @@ import wasmUrl from '@vlcn.io/crsqlite-wasm/crsqlite.wasm?url'; import { start } from "@vlcn.io/ws-client/worker.js"; import { createDbProvider } from "@vlcn.io/ws-browserdb"; + import * as addParser from '../../parser/add_parser.js'; let db; let ws; @@ -17,7 +18,13 @@ await db.exec(` CREATE TABLE IF NOT EXISTS todos ( id BLOB PRIMARY KEY NOT NULL, - content TEXT, + description TEXT, + project text, + tags text, + due text, + wait text, + priority text, + urgency real, completed INTEGER NOT NULL DEFAULT 0 ); SELECT crsql_as_crr('todos'); @@ -87,12 +94,37 @@ todos = result; } + // TODO: + // This is fucking sucks + // make the stupid parser do this 😩 + async function Marshall(parsed) { + let project = ""; + const tags = []; + console.log(parsed); + for (const attr of parsed.attributes) { + console.log(attr); + switch (attr.type) { + case 'project': + console.log("project" + attr.value); + project = attr.value; + break; + case 'tag': + console.log("tag" + attr.value); + tags.push(attr.value); + break; + } + } + return {description: parsed.description, tags: tags, project: project}; + } + async function addTodo() { if (newTodo.trim()) { + const parsed = await Marshall(addParser.parse(newTodo)); + console.log(parsed); await db.exec(` - INSERT INTO todos (id, content, completed) - VALUES (lower(hex(randomblob(16))), ?, 0) - `, [newTodo.trim()]); + INSERT INTO todos (id, description, tags, project, completed) + VALUES (lower(hex(randomblob(16))), ?, ?, ?, 0) + `, [parsed.description, JSON.stringify(parsed.tags), parsed.project]); newTodo = ''; loadTodos(); } @@ -109,7 +141,7 @@
-

Svelte Todo with cr-sqlite

+

Mast

e.key === 'Enter' && addTodo()} @@ -124,7 +156,7 @@ checked={todo.completed} on:change={() => toggleTodo(todo.id)} /> - {todo.content} + {todo.description} pro:{todo.project} {todo.tags} {/each} diff --git a/parser/add_js.peg b/parser/add_js.peg index 8c48e0d..3139387 100644 --- a/parser/add_js.peg +++ b/parser/add_js.peg @@ -25,7 +25,7 @@ Attributes = attributes:(_ Attribute)* { Attribute = Project / Priority / Tag -Project = ("pro:" / "project:") value:Word { +Project = ("pro:" / "project:" / "+") value:Word { return { type: "project", value: value }; } @@ -33,7 +33,7 @@ Priority = "priority:" value:[HML] { return { type: "priority", value: value }; } -Tag = "+" value:Word { +Tag = "#" value:Word { return { type: "tag", value: value }; } diff --git a/parser/add_parser.js b/parser/add_parser.js index 0d0bb3b..7b19c53 100644 --- a/parser/add_parser.js +++ b/parser/add_parser.js @@ -1,9 +1,7 @@ -// @generated by Peggy 4.0.3. +// @generated by Peggy 4.1.1. // // https://peggyjs.org/ -"use strict"; - function peg$subclass(child, parent) { function C() { this.constructor = child; } @@ -179,8 +177,9 @@ function peg$parse(input, options) { var peg$c0 = "pro:"; var peg$c1 = "project:"; - var peg$c2 = "priority:"; - var peg$c3 = "+"; + var peg$c2 = "+"; + var peg$c3 = "priority:"; + var peg$c4 = "#"; var peg$r0 = /^[HML]/; var peg$r1 = /^[a-zA-Z0-9_\-]/; @@ -189,11 +188,12 @@ function peg$parse(input, options) { var peg$e0 = peg$anyExpectation(); var peg$e1 = peg$literalExpectation("pro:", false); var peg$e2 = peg$literalExpectation("project:", false); - var peg$e3 = peg$literalExpectation("priority:", false); - var peg$e4 = peg$classExpectation(["H", "M", "L"], false, false); - var peg$e5 = peg$literalExpectation("+", false); - var peg$e6 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_", "-"], false, false); - var peg$e7 = peg$classExpectation([" ", "\\", "t"], false, false); + var peg$e3 = peg$literalExpectation("+", false); + var peg$e4 = peg$literalExpectation("priority:", false); + var peg$e5 = peg$classExpectation(["H", "M", "L"], false, false); + var peg$e6 = peg$literalExpectation("#", false); + var peg$e7 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], "_", "-"], false, false); + var peg$e8 = peg$classExpectation([" ", "\\", "t"], false, false); var peg$f0 = function(desc, attributes) { return MakeAdd(desc, attributes); @@ -544,6 +544,15 @@ function peg$parse(input, options) { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e2); } } + if (s1 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 43) { + s1 = peg$c2; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e3); } + } + } } if (s1 !== peg$FAILED) { s2 = peg$parseWord(); @@ -566,12 +575,12 @@ function peg$parse(input, options) { var s0, s1, s2; s0 = peg$currPos; - if (input.substr(peg$currPos, 9) === peg$c2) { - s1 = peg$c2; + if (input.substr(peg$currPos, 9) === peg$c3) { + s1 = peg$c3; peg$currPos += 9; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } + if (peg$silentFails === 0) { peg$fail(peg$e4); } } if (s1 !== peg$FAILED) { s2 = input.charAt(peg$currPos); @@ -579,7 +588,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } + if (peg$silentFails === 0) { peg$fail(peg$e5); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; @@ -600,12 +609,12 @@ function peg$parse(input, options) { var s0, s1, s2; s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 43) { - s1 = peg$c3; + if (input.charCodeAt(peg$currPos) === 35) { + s1 = peg$c4; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } + if (peg$silentFails === 0) { peg$fail(peg$e6); } } if (s1 !== peg$FAILED) { s2 = peg$parseWord(); @@ -634,7 +643,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } + if (peg$silentFails === 0) { peg$fail(peg$e7); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { @@ -644,7 +653,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } + if (peg$silentFails === 0) { peg$fail(peg$e7); } } } } else { @@ -668,7 +677,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } + if (peg$silentFails === 0) { peg$fail(peg$e8); } } while (s1 !== peg$FAILED) { s0.push(s1); @@ -677,7 +686,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } + if (peg$silentFails === 0) { peg$fail(peg$e8); } } } @@ -747,8 +756,12 @@ function peg$parse(input, options) { } } -module.exports = { - StartRules: ["Add"], - SyntaxError: peg$SyntaxError, - parse: peg$parse +const peg$allowedStartRules = [ + "Add" +]; + +export { + peg$allowedStartRules as StartRules, + peg$SyntaxError as SyntaxError, + peg$parse as parse };