From 242476f5957e815683bf1eb1f3ada10f2bdd3f38 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 17 Jan 2024 21:32:53 +0200 Subject: [PATCH] Add Syndicate actor --- .gitignore | 1 + Tupfile | 2 + Tuprules.tup | 3 ++ lock.json | 75 ++++++++++++++++++++++++++++++++++++ schema.prs | 3 ++ shaviliterator.nimble | 4 +- src/Tupfile | 4 ++ src/private/lexicon.nim | 2 +- src/schema.nim | 14 +++++++ src/shaviliterator_actor.nim | 19 +++++++++ 10 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 Tupfile create mode 100644 Tuprules.tup create mode 100644 lock.json create mode 100644 schema.prs create mode 100644 src/Tupfile create mode 100644 src/schema.nim create mode 100644 src/shaviliterator_actor.nim diff --git a/.gitignore b/.gitignore index e5b25b4..c2b6db0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +/nim.cfg shaviliterator diff --git a/Tupfile b/Tupfile new file mode 100644 index 0000000..28c450e --- /dev/null +++ b/Tupfile @@ -0,0 +1,2 @@ +include_rules +: lock.json |> !nim_cfg |> | ./ diff --git a/Tuprules.tup b/Tuprules.tup new file mode 100644 index 0000000..189eba9 --- /dev/null +++ b/Tuprules.tup @@ -0,0 +1,3 @@ +include ../syndicate-nim/depends.tup +NIM_FLAGS += --path:$(TUP_CWD)/../syndicate-nim/src +NIM_GROUPS += $(TUP_CWD)/ diff --git a/lock.json b/lock.json new file mode 100644 index 0000000..43755f3 --- /dev/null +++ b/lock.json @@ -0,0 +1,75 @@ +{ + "depends": [ + { + "method": "fetchzip", + "packages": [ + "hashlib" + ], + "path": "/nix/store/fav82xdbicvlk34nmcbl89zx99lr3mbs-source", + "rev": "f9455d4be988e14e3dc7933eb7cc7d7c4820b7ac", + "sha256": "1sx6j952lj98629qfgr7ds5aipyw9d6lldcnnqs205wpj4pkcjb3", + "srcDir": "", + "url": "https://github.com/ehmry/hashlib/archive/f9455d4be988e14e3dc7933eb7cc7d7c4820b7ac.tar.gz" + }, + { + "method": "fetchzip", + "packages": [ + "nimcrypto" + ], + "path": "/nix/store/zyr8zwh7vaiycn1s4r8cxwc71f2k5l0h-source", + "ref": "traditional-api", + "rev": "602c5d20c69c76137201b5d41f788f72afb95aa8", + "sha256": "1dmdmgb6b9m5f8dyxk781nnd61dsk3hdxqks7idk9ncnpj9fng65", + "srcDir": "", + "url": "https://github.com/cheatfate/nimcrypto/archive/602c5d20c69c76137201b5d41f788f72afb95aa8.tar.gz" + }, + { + "method": "fetchzip", + "packages": [ + "npeg" + ], + "path": "/nix/store/ffkxmjmigfs7zhhiiqm0iw2c34smyciy-source", + "ref": "1.2.1", + "rev": "26d62fdc40feb84c6533956dc11d5ee9ea9b6c09", + "sha256": "0xpzifjkfp49w76qmaylan8q181bs45anmp46l4bwr3lkrr7bpwh", + "srcDir": "src", + "url": "https://github.com/zevv/npeg/archive/26d62fdc40feb84c6533956dc11d5ee9ea9b6c09.tar.gz" + }, + { + "method": "fetchzip", + "packages": [ + "parsegemini" + ], + "path": "/nix/store/0xy3r2asbb56a60g83vd8vc21ww873d9-source", + "ref": "master", + "rev": "50b10def9a9fd0637fbe5a46c6b55f75c435266d", + "sha256": "141xk06flakf3q4q05hk3hwmxvgq21b8vl503x2b4kz59fmw1sfc", + "srcDir": "src", + "url": "https://github.com/autumngray/parsegemini/archive/50b10def9a9fd0637fbe5a46c6b55f75c435266d.tar.gz" + }, + { + "method": "fetchzip", + "packages": [ + "preserves" + ], + "path": "/nix/store/fmb2yckksz7iv3qdkk5gk1j060kppkq9-source", + "ref": "20231102", + "rev": "4faeb766dc3945bcfacaa1a836ef6ab29b20ceb0", + "sha256": "1a3g5bk1l1h250q3p6sqv6r1lpsplp330qqyp48r0i4a5r0jksq3", + "srcDir": "src", + "url": "https://git.syndicate-lang.org/ehmry/preserves-nim/archive/4faeb766dc3945bcfacaa1a836ef6ab29b20ceb0.tar.gz" + }, + { + "method": "fetchzip", + "packages": [ + "syndicate" + ], + "path": "/nix/store/nhpvl223vbzdrlzikw7pgyfxs344w7ma-source", + "ref": "20231108", + "rev": "095418032180e360ea27ec7fcd63193944b68e2c", + "sha256": "09pbml2chzz0v5zpz67fs7raj0mfmg8qrih2vz85xxc51h7ncqvw", + "srcDir": "src", + "url": "https://git.syndicate-lang.org/ehmry/syndicate-nim/archive/095418032180e360ea27ec7fcd63193944b68e2c.tar.gz" + } + ] +} diff --git a/schema.prs b/schema.prs new file mode 100644 index 0000000..d5c263c --- /dev/null +++ b/schema.prs @@ -0,0 +1,3 @@ +version 1 . + +Shaviliterate = . diff --git a/shaviliterator.nimble b/shaviliterator.nimble index c7ffb1d..8cb8b92 100644 --- a/shaviliterator.nimble +++ b/shaviliterator.nimble @@ -1,6 +1,6 @@ # Package -version = "0.1.0" +version = "20240108" author = "Emery Hemingway" description = "Shavian transliterator" license = "Unlicense" @@ -10,4 +10,4 @@ bin = @["shaviliterator", "shaviliterator_gemtext"] # Dependencies -requires "nim >= 1.4.2", "parsegemini" +requires "nim >= 2.0.0", "parsegemini", "syndicate" diff --git a/src/Tupfile b/src/Tupfile new file mode 100644 index 0000000..2cb9dae --- /dev/null +++ b/src/Tupfile @@ -0,0 +1,4 @@ +include_rules +: foreach ../*.prs |> !preserves_schema_nim |> %B.nim {schema} +: foreach *.nim | $(SYNDICATE_PROTOCOL) {schema} |> !nim_bin |> +: $(BIN_DIR)/shaviliterator_actor |> !assert_built |> diff --git a/src/private/lexicon.nim b/src/private/lexicon.nim index c743add..aef144f 100644 --- a/src/private/lexicon.nim +++ b/src/private/lexicon.nim @@ -5,7 +5,7 @@ import parsecsv, parseutils, ropes, streams, strutils, tables proc initLexicon(): Table[string, string] = result = initTable[string, string]() let - path = "kingsleyreadlexicon.tsv" + path = "../kingsleyreadlexicon.tsv" data = readFile(path) stream = newStringstream(data) var p: CsvParser diff --git a/src/schema.nim b/src/schema.nim new file mode 100644 index 0000000..c3ea11c --- /dev/null +++ b/src/schema.nim @@ -0,0 +1,14 @@ + +import + preserves + +type + Shaviliterate* {.preservesRecord: "shaviliterate".} = object + `latin`*: string + `shavian`*: string + +proc `$`*(x: Shaviliterate): string = + `$`(toPreserves(x)) + +proc encode*(x: Shaviliterate): seq[byte] = + encode(toPreserves(x)) diff --git a/src/shaviliterator_actor.nim b/src/shaviliterator_actor.nim new file mode 100644 index 0000000..5f41cb2 --- /dev/null +++ b/src/shaviliterator_actor.nim @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: ☭ Emery Hemingway +# SPDX-License-Identifier: Unlicense + +import std/ropes +import preserves, syndicate, syndicate/relays +import private/lexicon +import ./schema + +type Args* {.preservesDictionary.} = object + dataspace: Cap + +runActor("shaviliterator") do (turn: var Turn; root: Cap): + connectStdio(turn, root) + let pat = ?Observe(pattern: !Shaviliterate) ?? { 0: grab() } + during(turn, root, ?:Args) do (cap: Cap): + during(turn, cap, pat) do (latin: Literal[string]): + var trans = Shaviliterate(latin: latin.value) + trans.shavian = $transliterate(trans.latin) + discard publish(turn, cap, trans) -- 2.45.2