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