Compare commits
2 Commits
3f25000723
...
31c309aecc
| Author | SHA1 | Date | |
|---|---|---|---|
|
31c309aecc
|
|||
|
12fa9e4e75
|
@@ -22,10 +22,36 @@ task = "-" _ "[" status:. "]" _ label:label meta:meta* {
|
||||
};
|
||||
}
|
||||
|
||||
label = text:([^⏬🔽🔼⏫🔺➕⏳🛫📅✅❌🔁🏁🆔⛔⏰]*) {
|
||||
return text.join("").trim()
|
||||
/**************************************************************************************************************************************/
|
||||
|
||||
label = spans:(tag / labelWord / labelWhitespace)* {
|
||||
return spans;
|
||||
}
|
||||
|
||||
labelWord = word:[^ \t\r⏬🔽🔼⏫🔺➕⏳🛫📅✅❌🔁🏁🆔⛔⏰]+ {
|
||||
return {
|
||||
span: "word",
|
||||
value: word.join("")
|
||||
}
|
||||
}
|
||||
|
||||
labelWhitespace = whitespace:[ \t\r]+ {
|
||||
return {
|
||||
span: "whitespace",
|
||||
value: whitespace.join("")
|
||||
}
|
||||
}
|
||||
|
||||
tag = "#" tag:[a-zA-Z0-9-]+ {
|
||||
return {
|
||||
span: "tag",
|
||||
value: tag.join("")
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************************************************************************/
|
||||
|
||||
|
||||
meta = _ @(date / recurrence / delete / priority / dependency / reminder) _
|
||||
|
||||
/**************************************************************************************************************************************/
|
||||
|
||||
7
package-lock.json
generated
7
package-lock.json
generated
@@ -9,6 +9,7 @@
|
||||
"version": "0.0.1",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dayjs": "^1.11.13",
|
||||
"peggy": "^4.2.0"
|
||||
},
|
||||
"bin": {
|
||||
@@ -574,6 +575,12 @@
|
||||
"node": "^12.20.0 || >=14"
|
||||
}
|
||||
},
|
||||
"node_modules/dayjs": {
|
||||
"version": "1.11.13",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.13.tgz",
|
||||
"integrity": "sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/dir-glob": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"typescript": "^5.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"dayjs": "^1.11.13",
|
||||
"peggy": "^4.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import dayjs, { Dayjs } from "dayjs";
|
||||
import { ParsedTask, ParsedTaskDate, ParsedTaskDependency, ParsedTaskMeta } from "../types/grammar/task";
|
||||
import { Task, TaskPriority } from "../types/task";
|
||||
|
||||
@@ -15,7 +16,24 @@ export class LazyTask implements Task {
|
||||
}
|
||||
|
||||
get label(): string {
|
||||
return this.#parsed.label;
|
||||
return this.#parsed.label
|
||||
.filter(x => x.span === 'word' || x.span === 'whitespace')
|
||||
.map(x => x.value)
|
||||
.join("")
|
||||
.trim();
|
||||
}
|
||||
|
||||
get fullLabel(): string {
|
||||
return this.#parsed.label
|
||||
.map(x => x.span === 'tag' ? `#${x.value}` : x.value)
|
||||
.join("")
|
||||
.trim();
|
||||
}
|
||||
|
||||
get tags(): string[] {
|
||||
return this.#parsed.label
|
||||
.filter(x => x.span === 'tag')
|
||||
.map(x => x.value);
|
||||
}
|
||||
|
||||
get priority(): TaskPriority {
|
||||
@@ -34,31 +52,37 @@ export class LazyTask implements Task {
|
||||
}[priority] as TaskPriority;
|
||||
}
|
||||
|
||||
get createdDate(): string|undefined {
|
||||
return this.#dates.find(d => d.type === '➕')?.date;
|
||||
get createdDate(): Dayjs|undefined {
|
||||
return this.#date(this.#dates.find(d => d.type === '➕')?.date);
|
||||
}
|
||||
|
||||
get startDate(): string|undefined {
|
||||
return this.#dates.find(d => d.type === '🛫')?.date;
|
||||
#date(string?: string): Dayjs|undefined {
|
||||
return string
|
||||
? dayjs(string)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
get scheduledDate(): string|undefined {
|
||||
return this.#dates.find(d => d.type === '⏳')?.date;
|
||||
get startDate(): Dayjs|undefined {
|
||||
return this.#date(this.#dates.find(d => d.type === '🛫')?.date);
|
||||
}
|
||||
|
||||
get scheduledDate(): Dayjs|undefined {
|
||||
return this.#date(this.#dates.find(d => d.type === '⏳')?.date);
|
||||
}
|
||||
|
||||
get dueDate(): string|undefined {
|
||||
return this.#dates.find(d => d.type === '📅')?.date;
|
||||
get dueDate(): Dayjs|undefined {
|
||||
return this.#date(this.#dates.find(d => d.type === '📅')?.date);
|
||||
}
|
||||
|
||||
get completedDate(): string|undefined {
|
||||
return this.#dates.find(d => d.type === '✅')?.date;
|
||||
get completedDate(): Dayjs|undefined {
|
||||
return this.#date(this.#dates.find(d => d.type === '✅')?.date);
|
||||
}
|
||||
|
||||
get cancelledDate(): string|undefined {
|
||||
return this.#dates.find(d => d.type === '❌')?.date;
|
||||
get cancelledDate(): Dayjs|undefined {
|
||||
return this.#date(this.#dates.find(d => d.type === '❌')?.date);
|
||||
}
|
||||
|
||||
get recurrencyRule(): string|undefined {
|
||||
get recurrenceRule(): string|undefined {
|
||||
return this.#parsed.meta.find(x => x.feature === 'recurrence')?.rule;
|
||||
}
|
||||
|
||||
@@ -87,17 +111,18 @@ export class LazyTask implements Task {
|
||||
|
||||
const items = [
|
||||
o("priority", this.priority),
|
||||
o("created", this.createdDate),
|
||||
o("start", this.startDate),
|
||||
o("scheduled", this.scheduledDate),
|
||||
o("due", this.dueDate),
|
||||
o("completed", this.completedDate),
|
||||
o("cancelled", this.cancelledDate),
|
||||
o("recurrence", this.recurrencyRule),
|
||||
o("created", this.createdDate?.format("YYYY-MM-DD")),
|
||||
o("start", this.startDate?.format("YYYY-MM-DD")),
|
||||
o("scheduled", this.scheduledDate?.format("YYYY-MM-DD")),
|
||||
o("due", this.dueDate?.format("YYYY-MM-DD")),
|
||||
o("completed", this.completedDate?.format("YYYY-MM-DD")),
|
||||
o("cancelled", this.cancelledDate?.format("YYYY-MM-DD")),
|
||||
o("recurrence", this.recurrenceRule),
|
||||
o("delete", this.onDelete),
|
||||
o("id", this.id),
|
||||
o("deps", this.dependsOn.join(",")),
|
||||
o("reminder", this.reminder)
|
||||
o("reminder", this.reminder),
|
||||
o("tags", this.tags.join(","))
|
||||
];
|
||||
|
||||
return `- [${this.status}] ${this.label} {${items.filter(x => x.length > 0).join(", ")}}`;
|
||||
|
||||
@@ -8,10 +8,15 @@ export type ParseResult = {
|
||||
|
||||
export type ParsedTask = {
|
||||
status: string;
|
||||
label: string;
|
||||
label: ParsedTaskLabel[];
|
||||
meta: ParsedTaskMeta[];
|
||||
}
|
||||
|
||||
export type ParsedTaskLabel = {
|
||||
span: 'word'|'whitespace'|'tag';
|
||||
value: string
|
||||
};
|
||||
|
||||
export type ParsedTaskMeta =
|
||||
| ParsedTaskPriority
|
||||
| ParsedTaskRecurrence
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import { Dayjs } from "dayjs";
|
||||
|
||||
export type Task = {
|
||||
status: string;
|
||||
label: string;
|
||||
fullLabel: string;
|
||||
tags: string[];
|
||||
priority: TaskPriority;
|
||||
createdDate?: string;
|
||||
startDate?: string;
|
||||
scheduledDate?: string;
|
||||
dueDate?: string;
|
||||
completedDate?: string;
|
||||
cancelledDate?: string;
|
||||
recurrencyRule?: string;
|
||||
createdDate?: Dayjs;
|
||||
startDate?: Dayjs;
|
||||
scheduledDate?: Dayjs;
|
||||
dueDate?: Dayjs;
|
||||
completedDate?: Dayjs;
|
||||
cancelledDate?: Dayjs;
|
||||
recurrenceRule?: string;
|
||||
onDelete?: string;
|
||||
id?: string;
|
||||
dependsOn?: string[];
|
||||
|
||||
Reference in New Issue
Block a user