This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
(ns net.deertopia.publisher.elisp
|
(ns net.deertopia.publisher.elisp
|
||||||
(:require [instaparse.core :as ip]
|
(:require
|
||||||
[clojure.java.io :as io]
|
[clojure.core.match :refer [match]]
|
||||||
[clojure.core.match :refer [match]]
|
[clojure.java.io :as io]
|
||||||
[clojure.spec.alpha :as s]))
|
[clojure.spec.alpha :as s]
|
||||||
|
[instaparse.core :as ip]))
|
||||||
|
|
||||||
(ip/defparser read*
|
(ip/defparser read*
|
||||||
(io/resource "net/deertopia/publisher/elisp/grammar"))
|
(io/resource "net/deertopia/publisher/elisp/grammar"))
|
||||||
@@ -83,19 +84,30 @@
|
|||||||
_ false))
|
_ false))
|
||||||
|
|
||||||
(defn read-alist [s]
|
(defn read-alist [s]
|
||||||
(match (->> (read* s)
|
(let [r (->> s read*
|
||||||
(ip/transform (merge transforms
|
(ip/transform
|
||||||
{:symbol (fn [s] (symbol s))
|
(merge transforms
|
||||||
:string (fn [s] s)}))
|
{:symbol (fn [s] (symbol s))
|
||||||
first)
|
:string (fn [s] s)}))
|
||||||
[:cons* pairs] (->> (for [pair pairs]
|
first)]
|
||||||
(let [x (car pair)
|
(match r
|
||||||
y (cdr pair)]
|
[:cons* pairs] (->> (for [pair pairs]
|
||||||
{x y}))
|
(let [x (car pair)
|
||||||
(apply merge))
|
y (cdr pair)]
|
||||||
_ nil))
|
{x y}))
|
||||||
|
(apply merge))
|
||||||
|
_ nil)))
|
||||||
|
|
||||||
|
(defn read-string [s])
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(do (ip/defparser parse* (io/resource "elisp-grammar"))
|
(do (ip/defparser parse* (io/resource "elisp-grammar"))
|
||||||
(parse "#(\"blah\" 0 1 (doge))")
|
(parse "#(\"blah\" 0 1 (doge))")
|
||||||
(read-alist "((x . y))")))
|
(read-alist "((x . y))")))
|
||||||
|
|
||||||
|
(defn print-elisp-string [s]
|
||||||
|
(str \" s \"))
|
||||||
|
|
||||||
|
(defn read-elisp-string [s]
|
||||||
|
(let [[_ in] (re-matches #"\"(.*)\"" s)]
|
||||||
|
in))
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
(ns net.deertopia.publisher.roam
|
(ns net.deertopia.publisher.roam
|
||||||
(:require [next.jdbc :as sql]
|
(:require [babashka.fs :as fs]
|
||||||
[net.deertopia.publisher.config :as cfg]
|
[net.deertopia.publisher.config :as cfg]
|
||||||
|
[net.deertopia.publisher.elisp :as elisp]
|
||||||
[net.deertopia.publisher.slug :as slug]
|
[net.deertopia.publisher.slug :as slug]
|
||||||
[babashka.fs :as fs]
|
[next.jdbc :as sql])
|
||||||
[net.deertopia.publisher.elisp :as elisp])
|
|
||||||
(:import (java.util UUID)))
|
(:import (java.util UUID)))
|
||||||
|
|
||||||
|
|
||||||
;;; Global database
|
;;; Global database
|
||||||
|
|
||||||
@@ -21,13 +22,6 @@
|
|||||||
|
|
||||||
;;; Elisp sexp (de)serialisation
|
;;; Elisp sexp (de)serialisation
|
||||||
|
|
||||||
(defn- read-elisp-string [s]
|
|
||||||
(let [[_ in] (re-matches #"\"(.*)\"" s)]
|
|
||||||
in))
|
|
||||||
|
|
||||||
(defn- print-elisp-string [s]
|
|
||||||
(str \" s \"))
|
|
||||||
|
|
||||||
(defn id [node]
|
(defn id [node]
|
||||||
(-> node :id))
|
(-> node :id))
|
||||||
|
|
||||||
@@ -61,8 +55,8 @@
|
|||||||
(when-some [r (sql/execute-one!
|
(when-some [r (sql/execute-one!
|
||||||
ds
|
ds
|
||||||
["select file from nodes where id = ?"
|
["select file from nodes where id = ?"
|
||||||
(print-elisp-string (:id node))])]
|
(elisp/print-elisp-string (:id node))])]
|
||||||
(-> r :nodes/file read-elisp-string)))))
|
(-> r :nodes/file elisp/read-elisp-string)))))
|
||||||
|
|
||||||
(defprotocol GetNode
|
(defprotocol GetNode
|
||||||
(get-node [this]
|
(get-node [this]
|
||||||
@@ -86,7 +80,7 @@
|
|||||||
node :title
|
node :title
|
||||||
#(do (println "fetch")
|
#(do (println "fetch")
|
||||||
(sql/execute-one! ds ["select title from nodes where id = ?"
|
(sql/execute-one! ds ["select title from nodes where id = ?"
|
||||||
(print-elisp-string (:id %))]))))
|
(elisp/print-elisp-string (:id %))]))))
|
||||||
|
|
||||||
|
|
||||||
;;; Node operations
|
;;; Node operations
|
||||||
@@ -109,7 +103,7 @@
|
|||||||
ds ["select file from nodes where id = ?"
|
ds ["select file from nodes where id = ?"
|
||||||
(print-id %)])
|
(print-id %)])
|
||||||
:nodes/file
|
:nodes/file
|
||||||
read-elisp-string)))
|
elisp/read-elisp-string)))
|
||||||
|
|
||||||
(defn properties [node]
|
(defn properties [node]
|
||||||
(fetch-with-cache
|
(fetch-with-cache
|
||||||
@@ -135,25 +129,20 @@
|
|||||||
inner join nodes
|
inner join nodes
|
||||||
on nodes.id = links.source
|
on nodes.id = links.source
|
||||||
where links.dest = ?"
|
where links.dest = ?"
|
||||||
(print-elisp-string (:id node))])
|
(elisp/print-elisp-string (:id node))])
|
||||||
:let [id (read-elisp-string id)]
|
:let [id (elisp/read-elisp-string id)]
|
||||||
:when (graph-visible? (get-node (UUID/fromString id)))]
|
:when (graph-visible? (get-node (UUID/fromString id)))]
|
||||||
{:id id
|
{:id id
|
||||||
:title (read-elisp-string title)}))
|
:title (elisp/read-elisp-string title)}))
|
||||||
|
|
||||||
(defn parent-node [node]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
;;; Graph support
|
;;; Graph support
|
||||||
|
|
||||||
#_
|
|
||||||
(defn- make-node [node]
|
|
||||||
{:id (-> node :nodes/id read-elisp-string)
|
|
||||||
:title (-> node :nodes/title read-elisp-string)})
|
|
||||||
|
|
||||||
(defn- read-string-field [n field]
|
(defn- read-string-field [n field]
|
||||||
(-> n (get field) read-elisp-string))
|
(-> n (get field) elisp/read-elisp-string))
|
||||||
|
|
||||||
|
(defn- uuid-graph-visible? [uuid]
|
||||||
|
(-> uuid parse-uuid get-node graph-visible?))
|
||||||
|
|
||||||
(defn get-graph []
|
(defn get-graph []
|
||||||
(let [nodes (sql/execute! ds ["select id, title from nodes"])
|
(let [nodes (sql/execute! ds ["select id, title from nodes"])
|
||||||
@@ -165,13 +154,13 @@
|
|||||||
where links.type = '\"id\"'"])]
|
where links.type = '\"id\"'"])]
|
||||||
{:nodes (for [n nodes
|
{:nodes (for [n nodes
|
||||||
:let [id (read-string-field n :nodes/id)]
|
:let [id (read-string-field n :nodes/id)]
|
||||||
:when (graph-visible? (get-node (UUID/fromString id)))]
|
:when (uuid-graph-visible? id)]
|
||||||
{:id id
|
{:id id
|
||||||
:title (read-string-field n :nodes/title)})
|
:title (read-string-field n :nodes/title)})
|
||||||
:links (for [l links
|
:links (for [l links
|
||||||
:let [source (read-string-field l :nodes/source)
|
:let [source (read-string-field l :nodes/source)
|
||||||
target (read-string-field l :nodes/target)]
|
target (read-string-field l :nodes/target)]
|
||||||
:when (and (graph-visible? (get-node (UUID/fromString source)))
|
:when (and (-> source uuid-graph-visible?)
|
||||||
(graph-visible? (get-node (UUID/fromString target))))]
|
(-> target uuid-graph-visible?))]
|
||||||
{:source source
|
{:source source
|
||||||
:target target})}))
|
:target target})}))
|
||||||
|
|||||||
Reference in New Issue
Block a user