Browse Source

Begin building message parser

main
Netscape Navigator 1 year ago
parent
commit
a498bf0c9e
  1. 16
      README.md
  2. 2
      coverage.sh
  3. 129
      fixture.pgn
  4. 79
      project/parser.go
  5. 25
      project/parser_test.go
  6. 0
      project/testdata/.gitkeep
  7. 2
      tests.sh

16
README.md

@ -11,10 +11,23 @@ Don't use the Go version yet. If you want something stable, there is a [Ruby ver
By default, data is stored in `~/.pigeon`.
You can override this value by specifying a `PIGEON_PATH` ENV var.
# Help Wanted
Want to get involved? Below are a few things I need help with.
Email `contact@vaporsfot.xyz` if you have any questions.
* Writing a BNF grammar for message parsing
* Test coverage increases
* Manual QA of features and edge cases
* Cross-compiling windows binaries
* General Golang help (I am a Golang novice- project structure could be improved)
# TODO
**CURRENT TASK:** Write a message parser.
- [ ] Add a real testing lib to DRY things up.
- [ ] Figure out a system for where to place the default data storage directory
- [ ] Get a good CI system going? Run tests at PR time, provide prebuilt binaries, prevent coverage slips, etc..
- [ ] Add a `transact()` helper to ensure all transactions are closed out.
- [ ] Switch to [SQLX](https://github.com/jmoiron/sqlx) for extra sanity.
@ -23,6 +36,7 @@ You can override this value by specifying a `PIGEON_PATH` ENV var.
|Done?|Noun |Verb | Flag / arg 1 | Flag 2 |
|-----|------------|-----------|---------------|-----------|
| |blob |remove | mhash | |
| |bundle |ingest | | |
| |message |show | message mhash | |
| |message |find | --all | |

2
coverage.sh

@ -1,5 +1,7 @@
#!/bin/sh
cd project
rm -rf testdata
mkdir testdata
PIGEON_PATH="./testdata" go test -coverprofile coverage.out
PIGEON_PATH="./testdata" go tool cover -html=coverage.out
cd -

129
fixture.pgn

@ -0,0 +1,129 @@
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 0
kind FILE.ET9C7B9N82XR0F021CXEWSPDH23H4CHMX866WWA3R2PXEFZM67PG
lipmaa NONE
prev NONE
a:"b"
signature TKVXZ5EJV0GRDY60V2ZHN4ART60FYYJ99SJQGXAK8AF80X1ZFQCR18P5JVJZWMFME5Q7WF1999MH13V2ZYMVBX4XZGGR537FVFXWG10
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 1
kind a
lipmaa NONE
prev TEXT.0HG26KBTYFD3FW8K72GFJJ5CV9KXSDRG2WJS15P3XQ5V56XNX8E0
FILE.7Z2CSZKMB1RE5G6SKXRZ63ZGCNP8VVEM3K0XFMYKETRDQSM5WBSG:"b"
signature DPBY0XEKZPMFT0DM7JFFZVPZG4FR248SQVAXJ7T3T7QB1QYV3MKKS1V9FHWK9P33MECKBE4AYV4V70X9M9Z292JFC0DXBHH0HSJHM1R
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 2
kind a
lipmaa NONE
prev TEXT.BJEPB3TPZM2ZSQWHYB4N5ECMF0S9H4VKH0WYE1QY5T911YYZEA5G
b:FILE.HDDSVC617PS44NP856N3CJN91HPJXEHHHE93595BJC9VJN6KANFG
signature P6DK52KZ2KWHDJJ7Y7GZA2VGDRNQ9FDBFTDJY1ME6V21BDCCKYMFF3TEZ5EENJMRR4B8NCS0W4354WG88ZSW421RKW38JR8BPVQVC1R
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 3
kind a8df9e36-7c32-431c-af4c-855b6c398c87
lipmaa NONE
prev TEXT.TCZ4GCD45ETX73EEGRHPFX1BBPNBG70S03GC6V0F2QE07SCQ18T0
foo:"fe3d0f08-13a3-47eb-b605-cc9c1dd1811c"
signature R4RZ2DXD624C5TT0JCS1CP8ZA89KVMP8C2X39H7N0H6T4CPZNHGN5DA1B6B7B35V4WBB6X6XGNRBYMXJHD50BHRR3SMGDFCJ8YM8G20
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 4
kind dcf7d089-b5ef-4f8b-8fe7-c176e7c7605b
lipmaa TEXT.BJEPB3TPZM2ZSQWHYB4N5ECMF0S9H4VKH0WYE1QY5T911YYZEA5G
prev TEXT.94NPGGDTM456TFBJTQH2YFSQ2W46AJ9GGVYYYGXHGTR9A27ZPG2G
foo:"bar"
signature 95TCVY0CP01NZVHQSR8CNXDGYW9BK4CJADXQGA1R5G5Y8HD05N8MZ4KTSSAGP785BXQYMYMBVJEV1NMC0GF651RHQYGP57XR716JG3G
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 5
kind 485d10d6-87b3-4f1f-baf3-752796afec64
lipmaa NONE
prev TEXT.HWR2DNDWJYP60348W0M78QF4H0B5B7X6NT6KVS9GNJSP207PDB9G
foo:"16c4ad9b-34cc-4c37-a4c9-3ab0161ea4b5"
signature 0NPJG4A0VWP0HPS2SV3DJH696QMWBWZZ27CKCTX5JK8WJ1JE818PPJGRJRAC4QQ7K10GT2Z2Q19R3YKQFF1S0HFHYSPCC64079WZA38
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 6
kind 74be7129-06b8-4cb6-8aa9-d549710cd657
lipmaa NONE
prev TEXT.YEBFRRM6HCX514HBHBTB3AK2HF5B71MPDMB5HNQW4ACYETQYDNZ0
foo:"123"
signature HD7VNKTMARQ3294C6KDGXV4BP0GKFWEXBC5R8RHWF8VKBMFXDB2NCX4XQN6Q524ZWPNTM0HGSHSAX359GCAEFE0P688S4825RY2P418
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 7
kind f06d3a2b-a1c0-4bf5-83e7-29409ac0c9b4
lipmaa NONE
prev TEXT.XQRKXB46M6HZAWTADNXWFTHQS8PGEPDZ581J40REFNT3YWG8YZ70
foo:"123"
signature ZYHVXQGZ9G78AD69A9SFMF281B4WHX05AG8TEKBKSFH706HXNYRTPH9G5VP01ZC515MMP69KPV41THB7DG9XJT90ZRX99KZ1WGJQM2R
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 8
kind a4df2c79-17ef-4c90-ba11-3021fe23269c
lipmaa TEXT.HWR2DNDWJYP60348W0M78QF4H0B5B7X6NT6KVS9GNJSP207PDB9G
prev TEXT.49S2F3Y6AXHDD8F62RKXPFWC2BYBV5D16VQY34F40NTQFZW1R0G0
foo:"bar"
signature W57NQEX8HD3DQG1F8G6SD8960QRP0HYPWXCKTN6AZ5SXZCWABPBWHM84EFDH5MJTJ4YYVZHC5RC01382DAW19EDCCXCG3KM2XCRH620
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 9
kind a2c49e15-befd-4a62-8a7d-f4a28d052c38
lipmaa NONE
prev TEXT.NRK3MEG982X5N76RFF4F9WC405452YNZFCH5WTP9G8ERRTYNN3V0
foo:"3b39df57-9dee-4a66-8d49-ee4944631f33"
signature ATRMAPBKQ7VZWRDSX4ASSVZ3D9CKSS3PZ8ZP229H96MA9DGD7RM5TA1E4CZD42BWK6Q9XJ1C1KDY2BMXJ8Z3Z780YDZEWWJYYTQHW1R
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 10
kind 7a1a2b5a-32c2-4b3f-b287-42e4a73e340d
lipmaa NONE
prev TEXT.FKH08FA04MCC7RPYN1GZZT0VAGHAW0VRHQD6QZX3C6YCTAZM9WE0
foo:"bar"
signature 3F774WW8NVA3HAQRV7M4CWKBYH86QB8F9QPQ6FV96MG6S9KHBG519WKPNBZR7YRFFBWHZZ50RSKP9YVDHW9K3XXHERQ8BDXYKAR8Y2G
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 11
kind c8cfac48-460f-47c6-a6b3-34daa431fcab
lipmaa NONE
prev TEXT.DQH1TX6QM3223PNX4Y352AQSDJM91SMFYJFG6PPC182ZW9PYR70G
foo:"450024fc-ea1c-4144-b7b9-16c60ff00e45"
signature AT3VWBJXP7NZBGADPWGX0PVHPKS0W14SAY12XZHYQ3EF025641M29P46ZNYM3M4Q0HKZYH4GSMRR7RTC7R5V3K5AXKH68SJ4B094E0R
author USER.PJC0W5XRFX4JBFPX929PQETB58VM7A4P5RDMW7Y8E9P4CRZDWEBG
depth 12
kind 6ecac9f1-e5dc-4274-a0fd-633c2cd56832
lipmaa TEXT.NRK3MEG982X5N76RFF4F9WC405452YNZFCH5WTP9G8ERRTYNN3V0
prev TEXT.Y3K7WH4R9W9EBTZB27NJCYR6VBKYTHZX97Y05841VPM5G50ZYG00
foo:"fc1a7066-2af2-4437-98e3-dbc33e67d7c6"
signature CGC4PHDQBSR7ZWS5NY3KZ7YJ342K30QB3DKHDS78GD4H2F5J196424GBQD04EDMYX8M4J971VJ7JQ1N1QZDV24ABDY02TW0QDP82P1G

79
project/parser.go

@ -0,0 +1,79 @@
package main
import (
"bufio"
"errors"
"fmt"
"strings"
)
type pigeonBodyItem struct {
key string
value string
}
type pigeonMessage struct {
author string
depth int
kind string
lipmaa string
prev string
body [256]pigeonBodyItem
signature string
}
type parserMode int
const (
parsingHeader parserMode = iota
parsingBody parserMode = iota
parsingFooter parserMode = iota
parsingDone parserMode = iota
)
type parserState struct {
mode parserMode
scanner *bufio.Scanner
}
func newState(message string) parserState {
return parserState{
mode: parsingHeader,
scanner: bufio.NewScanner(strings.NewReader(message)),
}
}
func parseMessage(message string) ([]pigeonMessage, error) {
state := newState(message)
for state.scanner.Scan() {
switch state.mode {
case parsingHeader:
parseHeader(state)
case parsingBody:
parseBody(state)
case parsingFooter:
parseFooter(state)
}
}
return []pigeonMessage{}, errors.New("whatever")
}
func parseHeader(state parserState) {
t := state.scanner.Text()
chunks := strings.Split(t, " ")
switch len(chunks) {
case 2:
fmt.Printf("=== KEY: %s | VALUE: %s\n", chunks[0], chunks[1])
default:
fmt.Printf("WHATS THIS?? %s\n", chunks[0])
}
}
func parseBody(state parserState) {
panic("Not done yet")
}
func parseFooter(state parserState) {
panic("Not done yet")
}

25
project/parser_test.go

@ -0,0 +1,25 @@
package main
import (
"io/ioutil"
"log"
"testing"
)
func TestParser(t *testing.T) {
content, err1 := ioutil.ReadFile("../fixture.pgn")
if err1 != nil {
log.Fatal(err1)
}
output, err2 := parseMessage(string(content))
if err2 != nil {
log.Fatal(err2)
}
fixtureSize := 13
length := len(output)
if length != fixtureSize {
t.Fatalf("Expected %d items, got %d", fixtureSize, length)
}
}

0
project/testdata/.gitkeep

2
tests.sh

@ -1,4 +1,6 @@
#!/bin/sh
cd project
rm -rf testdata
mkdir testdata
PIGEON_PATH="./testdata" go test -v
cd -

Loading…
Cancel
Save