diff --git a/publisher/src/net/deertopia/publisher/elisp.clj b/publisher/src/net/deertopia/publisher/elisp.clj index 7673307..2b7e672 100644 --- a/publisher/src/net/deertopia/publisher/elisp.clj +++ b/publisher/src/net/deertopia/publisher/elisp.clj @@ -98,16 +98,19 @@ (apply merge)) _ nil))) -(defn read-string [s]) +(defn read-string [s] + (match (-> s read first) + [:string x & props] x + :else nil)) + +(defn print [x] + ;; TODO: this is really not how it should be done lol. at the + ;; moment, `print` is only used in `net.deertopia.publisher.roam` + ;; and only to serialise uuids, so it's not a /massive/ priority. + (cond (string? x) (str \" s \"))) (comment (do (ip/defparser parse* (io/resource "elisp-grammar")) - (parse "#(\"blah\" 0 1 (doge))") + (read "#(\"blah\" 0 1 (doge))") + (read "\"bla\\nh\"") (read-alist "((x . y))"))) - -(defn print-elisp-string [s] - (str \" s \")) - -(defn read-elisp-string [s] - (let [[_ in] (re-matches #"\"(.*)\"" s)] - in)) diff --git a/publisher/src/net/deertopia/publisher/roam.clj b/publisher/src/net/deertopia/publisher/roam.clj index 607b77e..2ce8805 100644 --- a/publisher/src/net/deertopia/publisher/roam.clj +++ b/publisher/src/net/deertopia/publisher/roam.clj @@ -29,7 +29,7 @@ (-> node :id slug/from-uuid)) (defn- print-id [node] - (-> node id print-elisp-string)) + (-> node id print)) ;;; Node @@ -55,8 +55,8 @@ (when-some [r (sql/execute-one! ds ["select file from nodes where id = ?" - (elisp/print-elisp-string (:id node))])] - (-> r :nodes/file elisp/read-elisp-string))))) + (elisp/print (:id node))])] + (-> r :nodes/file elisp/read-string))))) (defprotocol GetNode (get-node [this] @@ -66,13 +66,18 @@ String (get-node [this] (or (some-> this slug/from-string get-node) - (some-> this parse-uuid get-node))) + (some-> this parse-uuid get-node) + (throw (IllegalArgumentException. + "Give `get-node` a UUID or slug string plz. }:)")))) java.util.UUID (get-node [this] (make-node this)) net.deertopia.publisher.slug.Slug (get-node [this] - (-> this slug/to-uuid make-node))) + (-> this slug/to-uuid make-node)) + Node + (get-node [this] + this)) (comment (def node (get-node "68XqhHerTWCbE--RYLEdHw")) @@ -80,7 +85,7 @@ node :title #(do (println "fetch") (sql/execute-one! ds ["select title from nodes where id = ?" - (elisp/print-elisp-string (:id %))])))) + (elisp/print (:id %))])))) ;;; Node operations @@ -103,7 +108,7 @@ ds ["select file from nodes where id = ?" (print-id %)]) :nodes/file - elisp/read-elisp-string))) + elisp/read-string))) (defn properties [node] (fetch-with-cache @@ -129,17 +134,17 @@ inner join nodes on nodes.id = links.source where links.dest = ?" - (elisp/print-elisp-string (:id node))]) - :let [id (elisp/read-elisp-string id)] + (elisp/print (:id node))]) + :let [id (elisp/read-string id)] :when (graph-visible? (get-node (UUID/fromString id)))] {:id id - :title (elisp/read-elisp-string title)})) + :title (elisp/read-string title)})) ;;; Graph support (defn- read-string-field [n field] - (-> n (get field) elisp/read-elisp-string)) + (-> n (get field) elisp/read-string)) (defn- uuid-graph-visible? [uuid] (-> uuid parse-uuid get-node graph-visible?)) @@ -160,7 +165,7 @@ :links (for [l links :let [source (read-string-field l :nodes/source) target (read-string-field l :nodes/target)] - :when (and (-> source uuid-graph-visible?) - (-> target uuid-graph-visible?))] + :when (and (uuid-graph-visible? source) + (uuid-graph-visible? target))] {:source source :target target})}))