Compare commits
15 Commits
96d1766386
...
b066d82259
| Author | SHA1 | Date | |
|---|---|---|---|
| b066d82259 | |||
| 2d3a23f085 | |||
| a95135daae | |||
| 3b22eb880b | |||
| 4491a3e0cc | |||
| f326fad9f4 | |||
| 2c755422a7 | |||
| 777968cac5 | |||
| a35453c2be | |||
| e20dcf591d | |||
| cbfa42bc73 | |||
| b0a3895a18 | |||
| 1ff453262d | |||
| d0840233c9 | |||
| 86db8d0fe2 |
@@ -209,22 +209,6 @@
|
|||||||
:first-section-nodes of-first-section
|
:first-section-nodes of-first-section
|
||||||
:rest remaining-nodes*}))
|
:rest remaining-nodes*}))
|
||||||
|
|
||||||
(defn- element-bounds [& nodes]
|
|
||||||
(reduce (fn [acc {:keys [contents-begin contents-end]}]
|
|
||||||
(if (and (nat-int? contents-begin)
|
|
||||||
(nat-int? contents-end))
|
|
||||||
(-> acc
|
|
||||||
(update
|
|
||||||
:contents-begin
|
|
||||||
#(min (or % Integer/MAX_VALUE) contents-begin))
|
|
||||||
(update
|
|
||||||
:contents-end
|
|
||||||
#(max (or % Integer/MIN_VALUE) contents-end)))
|
|
||||||
acc))
|
|
||||||
{:contents-begin nil
|
|
||||||
:contents-end nil}
|
|
||||||
nodes))
|
|
||||||
|
|
||||||
(defn gather-first-section [node]
|
(defn gather-first-section [node]
|
||||||
(assert (of-type? node "org-data")
|
(assert (of-type? node "org-data")
|
||||||
"`gather-doerg-data` should be applied to the document root.")
|
"`gather-doerg-data` should be applied to the document root.")
|
||||||
@@ -232,11 +216,9 @@
|
|||||||
(split-sections (:children node))
|
(split-sections (:children node))
|
||||||
;; TODO: Construct `:contents-begin` and `:contents-end` data
|
;; TODO: Construct `:contents-begin` and `:contents-end` data
|
||||||
;; by spanning the children.
|
;; by spanning the children.
|
||||||
first-section (merge {:type "section"
|
|
||||||
:children first-section-nodes}
|
|
||||||
(apply element-bounds first-section-nodes))
|
|
||||||
new-children (concat top-level-nodes
|
new-children (concat top-level-nodes
|
||||||
(list first-section)
|
(list {:type "section"
|
||||||
|
:children first-section-nodes})
|
||||||
rest)]
|
rest)]
|
||||||
(assoc node :children new-children)))
|
(assoc node :children new-children)))
|
||||||
|
|
||||||
@@ -260,6 +242,15 @@
|
|||||||
([predator prey & more-prey]
|
([predator prey & more-prey]
|
||||||
(reduce swallow predator (cons prey more-prey))))
|
(reduce swallow predator (cons prey more-prey))))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(-> [1 2 3 4]
|
||||||
|
(neighbourly-mapcat prn) )
|
||||||
|
(def doc (read-string (slurp some-org-file)))
|
||||||
|
|
||||||
|
(let [r (atom [])
|
||||||
|
blah]
|
||||||
|
@r))
|
||||||
|
|
||||||
(defn gather-latex-paragraphs [node]
|
(defn gather-latex-paragraphs [node]
|
||||||
(->> node
|
(->> node
|
||||||
(sp/transform
|
(sp/transform
|
||||||
@@ -341,13 +332,19 @@
|
|||||||
(s/def ::contents-begin nat-int?)
|
(s/def ::contents-begin nat-int?)
|
||||||
(s/def ::contents-end nat-int?)
|
(s/def ::contents-end nat-int?)
|
||||||
|
|
||||||
(defmulti node-spec :type)
|
(defmulti object-spec :type)
|
||||||
|
(defmulti recursive-object-spec :type)
|
||||||
|
(defmulti element-spec :type)
|
||||||
|
(defmulti greater-element-spec :type)
|
||||||
|
|
||||||
(defn- unimplemented-spec [x]
|
(defn- unimplemented-spec [x]
|
||||||
(lr/warnf "unimplemented method for %s" (:type x))
|
(lr/warnf "unimplemented method for %s" (:type x))
|
||||||
any?)
|
any?)
|
||||||
|
|
||||||
(defmethod node-spec :default [x] (unimplemented-spec x))
|
(defmethod object-spec :default [x] (unimplemented-spec x))
|
||||||
|
(defmethod recursive-object-spec :default [x] (unimplemented-spec x))
|
||||||
|
(defmethod greater-element-spec :default [x] (unimplemented-spec x))
|
||||||
|
(defmethod element-spec :default [x] (unimplemented-spec x))
|
||||||
|
|
||||||
(def ^:private nfe
|
(def ^:private nfe
|
||||||
"NFE — “no further expectations.” Used in sub-specs of `::element`
|
"NFE — “no further expectations.” Used in sub-specs of `::element`
|
||||||
@@ -357,33 +354,27 @@
|
|||||||
(constantly (gen/return {}))))
|
(constantly (gen/return {}))))
|
||||||
|
|
||||||
(s/def ::object
|
(s/def ::object
|
||||||
(dict {:type string?}))
|
(s/multi-spec object-spec :type))
|
||||||
|
|
||||||
(s/def ::element
|
(s/def ::element
|
||||||
(dict ^:opt {:contents-begin ::contents-begin
|
(s/merge (dict ^:opt {:contents-begin ::contents-begin
|
||||||
:contents-end ::contents-end}
|
:contents-end ::contents-end}
|
||||||
{:children (s/coll-of nfe :kind vector?)
|
{:children (s/coll-of ::object :kind vector?)})
|
||||||
:type string?}))
|
(s/multi-spec element-spec :type)))
|
||||||
|
|
||||||
(s/def ::node nil)
|
|
||||||
|
|
||||||
(s/def ::greater-element
|
(s/def ::greater-element
|
||||||
(dict {:contents-begin ::contents-begin
|
(s/merge (dict {:contents-begin ::contents-begin
|
||||||
:contents-end ::contents-end
|
:contents-end ::contents-end
|
||||||
:children (s/coll-of ::node :kind vector?)
|
:children (s/coll-of
|
||||||
:type string?}))
|
(s/or :element ::element
|
||||||
|
:greater-element ::greater-element)
|
||||||
|
:kind vector?)})
|
||||||
|
(s/multi-spec greater-element-spec :type)))
|
||||||
|
|
||||||
(s/def ::recursive-object
|
(s/def ::recursive-object-base
|
||||||
(dict ^:opt {:contents-begin ::contents-begin
|
(dict ^:opt {:contents-begin ::contents-begin
|
||||||
:contents-end ::contents-end}
|
:contents-end ::contents-end}
|
||||||
{:children (s/coll-of ::node :kind vector?)}))
|
{:children (s/coll-of ::object-base :kind vector?)}))
|
||||||
|
|
||||||
(s/def ::node (s/multi-spec node-spec :type))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(use 'net.deertopia.doerg.repl)
|
|
||||||
(def doc (-> some-org-file slurp read-string))
|
|
||||||
(s/explain ::node doc))
|
|
||||||
|
|
||||||
(s/def ::todo-keyword string?)
|
(s/def ::todo-keyword string?)
|
||||||
(s/def ::priority string?)
|
(s/def ::priority string?)
|
||||||
@@ -396,29 +387,26 @@
|
|||||||
|
|
||||||
(def ^:private string-value (dict {:value string?}))
|
(def ^:private string-value (dict {:value string?}))
|
||||||
|
|
||||||
(defmethod node-spec "text" [_] (s/merge ::object string-value))
|
(defmethod object-spec "text" [_] string-value)
|
||||||
(defmethod node-spec "verbatim" [_] (s/merge ::object string-value))
|
(defmethod object-spec "verbatim" [_] string-value)
|
||||||
(defmethod node-spec "code" [_] (s/merge ::object string-value))
|
(defmethod object-spec "code" [_] string-value)
|
||||||
(defmethod node-spec "bold" [_] ::recursive-object)
|
(defmethod recursive-object-spec "bold" [_] nfe)
|
||||||
(defmethod node-spec "italic" [_] ::recursive-object)
|
(defmethod recursive-object-spec "italic" [_] nfe)
|
||||||
|
|
||||||
|
|
||||||
;;; Specs (specific elements)
|
;;; Specs (specific elements)
|
||||||
|
|
||||||
(defmethod node-spec "headline" [_]
|
(defmethod element-spec "headline" [_]
|
||||||
(s/merge ::element
|
(dict {:todo-keyword (s/nilable ::todo-keyword)
|
||||||
(dict {:todo-keyword (s/nilable ::todo-keyword)
|
:priority (s/nilable ::priority)
|
||||||
:priority (s/nilable ::priority)
|
:level ::level
|
||||||
:level ::level
|
:commented ::commented
|
||||||
:commented ::commented
|
:raw-value string?
|
||||||
:raw-value string?
|
:tags ::tags}))
|
||||||
:tags ::tags})))
|
|
||||||
|
|
||||||
|
|
||||||
;;; Specs (specific greater elements)
|
;;; Specs (specific greater elements)
|
||||||
|
|
||||||
(defmethod node-spec "org-data" [_]
|
(defmethod greater-element-spec "org-data" [_] nfe)
|
||||||
::greater-element)
|
|
||||||
|
|
||||||
(defmethod node-spec "section" [_]
|
(defmethod greater-element-spec "section" [_] nfe)
|
||||||
::greater-element)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user