init: working task add parser

This commit is contained in:
Anish Lakhwara 2024-08-31 21:46:09 -07:00
parent 176a81cc91
commit 636dc6d59d
8 changed files with 1775 additions and 17 deletions

View file

@ -8,6 +8,7 @@ import (
"os"
mast "mast/db"
parser "mast/parser"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
@ -222,9 +223,22 @@ func (m model) View() string {
}
func main() {
p := tea.NewProgram(initialModel())
if _, err := p.Run(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
if len(os.Args) < 2 {
fmt.Println("Please provide a Taskwarrior add command to parse")
return
}
input := os.Args[1]
result, err := parser.Parse("", []byte(input))
if err != nil {
fmt.Printf("Error parsing input: %v\n", err)
return
}
fmt.Printf("Parsed result: %+v\n", result)
// p := tea.NewProgram(initialModel())
// if _, err := p.Run(); err != nil {
// fmt.Printf("Alas, there's been an error: %v", err)
// os.Exit(1)
// }
}

View file

@ -3,16 +3,9 @@
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs = { nixpkgs, ... }:
let
pkgs = nixpkgs.legacyPackages."x86_64-linux";
in
{
devShells."x86_64-linux".default = pkgs.mkShell {
packages = with pkgs; [
go
sqlite
nodejs
];
};
let pkgs = nixpkgs.legacyPackages."x86_64-linux";
in {
devShells."x86_64-linux".default =
pkgs.mkShell { packages = with pkgs; [ go sqlite nodejs pigeon ]; };
};
}

7
go.mod
View file

@ -23,13 +23,16 @@ require (
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mna/pigeon v1.2.1 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.3.8 // indirect
golang.org/x/tools v0.24.0 // indirect
)

10
go.sum
View file

@ -33,6 +33,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mna/pigeon v1.2.1 h1:m5FxEbGdQxLaiHF+QurbWUAjmRqd5cstjIPN89svYgg=
github.com/mna/pigeon v1.2.1/go.mod h1:BUZAoRldTdU7Ac3WYkXy8hzIHfCgj1doJxGjlB+AbLI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
@ -49,11 +51,19 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=

BIN
main Executable file

Binary file not shown.

65
parser/add.peg Normal file
View file

@ -0,0 +1,65 @@
{
package parser
type Attribute struct{
Type string
Value string
}
type AddCommand struct {
Description string
Attributes []Attribute
}
func MakeAdd(description interface{}, attributes interface{}) (*AddCommand, error) {
attribs, _ := attributes.([]Attribute)
return &AddCommand{Description: description.(string), Attributes: attribs}, nil
}
func MakeAttributes(attributes interface{}) ([]Attribute, error) {
ats := attributes.([]interface{})
attribs := make([]Attribute, 0)
for _, p := range ats {
pa := p.([]interface{})
px := pa[1:]
for _, pi := range px {
ps := pi.(*Attribute)
attribs = append(attribs, *ps)
}
}
return attribs, nil
}
}
Add <- desc:Description attributes:Attributes? {
return MakeAdd(desc, attributes)
}
Description <- (!Attribute .)+ {
return string(c.text), nil
}
Attributes <- attributes:(_ Attribute)* {
return MakeAttributes(attributes)
}
Attribute <- Project / Priority / Tag
Project <- ("pro:" / "project:") value:Word {
return &Attribute{Type:"project", Value:value.(string)}, nil
}
Priority <- "priority:" value:[HML] {
return &Attribute{Type:"priority", Value:value.(string)}, nil
}
Tag <- "+" value:Word {
return &Attribute{Type:"tag", Value:value.(string)}, nil
}
Word <- [a-zA-Z0-9_-]+ {
return string(c.text), nil
}
_ <- [ \t]*
EOF = !.

1651
parser/add_parser.go Normal file

File diff suppressed because it is too large Load diff

22
parser/main.go Normal file
View file

@ -0,0 +1,22 @@
package parser
import (
"fmt"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Please provide a Taskwarrior add command to parse")
return
}
input := os.Args[1]
result, err := Parse("", []byte(input))
if err != nil {
fmt.Printf("Error parsing input: %v\n", err)
return
}
fmt.Printf("Parsed result: %+v\n", result)
}