diff --git a/doerg/src/net/deertopia/doerg/element.clj b/doerg/src/net/deertopia/doerg/element.clj index 8aae19d..2b347ea 100644 --- a/doerg/src/net/deertopia/doerg/element.clj +++ b/doerg/src/net/deertopia/doerg/element.clj @@ -312,33 +312,26 @@ "planning" "diary-sexp" "fixed-width" "export-block" "horizontal-rule" "comment" "table-row" "headline"}) -(def element-types - (set/union greater-element-types element-types)) +(def recursive-object-types + #{"citation" "footnote-reference" "superscript" "table-cell" "link" + "italic" "citation-common-prefix" "subscript" "citation-prefix" + "citation-common-suffix" "strike-through" "citation-reference" + "bold" "underline"}) (def object-types - #{"citation" "line-break" "citation-suffix" "footnote-reference" - "statistics-cookie" "timestamp" "superscript" "text" "table-cell" - "link" "verbatim" "italic" "citation-common-prefix" "subscript" - "citation-key" "export-snippet" "citation-prefix" - "citation-common-suffix" "latex-fragment" "strike-through" "entity" - "citation-reference" "bold" "underline" "code"}) + #{"line-break" "citation-suffix" "statistics-cookie" "timestamp" + "text" "verbatim" "citation-key" "export-snippet" "latex-fragment" + "entity" "code"}) -(s/def ::greater-element-type - greater-element-types) - -(s/def ::element-type - element-types) - -(s/def ::object-type - object-types) +(s/def ::greater-element-type greater-element-types) +(s/def ::element-type element-types) +(s/def ::object-type object-types) +(s/def ::recursive-object-type recursive-object-types) (s/def ::contents-begin nat-int?) (s/def ::contents-end nat-int?) -(defmulti element-spec :type) -(defmulti object-spec :type) -(defmulti greater-element-spec :type) -(defmulti recursive-object-spec :type) +(defmulti node-spec :type) (def ^:private nfe "NFE — “no further expectations.” Used in sub-specs of `::element` @@ -347,31 +340,32 @@ (s/with-gen (constantly true) (constantly (gen/return {})))) -(defmacro ^:private with-parent-spec [multifn spec] - `(s/merge ~spec (s/multi-spec ~multifn :type))) +(s/def ::object-base + (dict {:type ::object-type})) -(s/def ::object (s/multi-spec object-spec :type)) +(s/def ::element-base + (dict ^:opt {:contents-begin ::contents-begin + :contents-end ::contents-end} + {:children (s/coll-of ::object :kind vector?) + :type ::element-type})) -(s/def ::element - (with-parent-spec element-spec - (dict ^:opt {:contents-begin ::contents-begin - :contents-end ::contents-end} - {:children (s/coll-of ::object :kind vector?) - :type ::element-type}))) +(s/def ::greater-element-base + (dict {:contents-begin ::contents-begin + :contents-end ::contents-end + :children (s/coll-of ::object :kind vector?) + :type ::greater-element-type})) -(s/def ::greater-element - (with-parent-spec greater-element-spec - (dict {:contents-begin ::contents-begin - :contents-end ::contents-end - :children (s/coll-of ::object :kind vector?) - :type ::greater-element-type}))) +(s/def ::recursive-object-base + (dict ^:opt {:contents-begin ::contents-begin + :contents-end ::contents-end} + {:children (s/coll-of ::object :kind vector?) + :type ::recursive-object-type})) + +(s/def ::object + (s/merge ::object-base (s/multi-spec node-spec :type))) (s/def ::recursive-object - (with-parent-spec recursive-object-spec - (dict {:contents-begin ::contents-begin - :contents-end ::contents-end - :children (s/coll-of ::object :kind vector?) - :type ::object-type}))) + (s/merge ::recursive-object-base (s/multi-spec node-spec :type))) (s/def ::todo-keyword string?) (s/def ::priority string?) @@ -382,20 +376,18 @@ ;;; Specs (specific objects) -(defmethod object-spec "text" [_] - (dict {:value string?})) +(def ^:private string-value (dict {:value string?})) -(defmethod recursive-object-spec "bold" [_] nfe) -(defmethod recursive-object-spec "italic" [_] nfe) -(defmethod recursive-object-spec "code" [_] nfe) - -(defmethod recursive-object-spec "verbatim" [_] - (dict {:value string?})) +(defmethod node-spec "text" [_] (s/merge string-value)) +(defmethod node-spec "verbatim" [_] string-value) +(defmethod node-spec "code" [_] string-value) +(defmethod node-spec "bold" [_] nfe) +(defmethod node-spec "italic" [_] nfe) ;;; Specs (specific elements) -(defmethod element-spec "headline" [_] +(defmethod node-spec "headline" [_] (dict {:todo-keyword (s/nilable ::todo-keyword) :priority (s/nilable ::priority) :level ::level @@ -406,6 +398,6 @@ ;;; Specs (specific greater elements) -(defmethod greater-element-spec "org-data" [_] nfe) +(defmethod node-spec "org-data" [_] nfe) -(defmethod greater-element-spec "section" [_] nfe) +(defmethod node-spec "section" [_] nfe)