 
 (defn process-files [path->data]
   (let [data (reduce merge-file-data {} path->data)
-        tree (build-tree data)
+        tree (parse-tree data)
         flat-tree (flatten-tree tree)
         graph (build-graph flat-tree)]
     graph))

            [:node (:name node)])
          (node->link [node]
            {:name (:name node)})
          (build-node [graph node]
            (let [ident (node->ident node)
                  children (:children node)
                  parent (if (nil? (:parent node))
                           nil
                           {:name (:parent node)})
                  linked-data (-> node
                                  (assoc :parent parent)
                                  (update :children #(mapv node->link %))
                                  keywordize-keys)]
              (-> graph
                  (update :nodes conj ident)
                  (assoc-in ident linked-data))))
          (build-step [graph [name node]]
            (build-node graph node))]
    (reduce build-step {:node {} :nodes []} flat-tree)))

(defn recursive-merge [a b]

                (fn [children]
                  (mapv #(process-down % f ctx) children))))))

(defn set-parent [node ctx]
  (let [parent ctx]
    {:node (assoc node :parent
                  (or (:parent node)
                      (when parent {:name (:name parent)})))
     :ctx (if (custard-node? node) node parent)}))

(declare parse-node)

(defn parse-children [name-segments data]
  (into []
        (comp (filter #(map? (second %)))
              (map (fn [[k v]]
                     (parse-node (conj name-segments k) v))))
        data))

(defn parse-node [name-segments data]
  {:pre [(map? data)]}
  (let [kind (parse-kind data)
        parser (kind-parsers kind)
        basic {:name (str/join "/" name-segments)
               :children (parse-children name-segments data)}]
    (if (and kind parser)
      (merge basic
             {:kind kind}
             (parse-common data)
             (parser data))
      basic)))

(defn parse-tree [data]
  (letfn [(parse-step [root [name-segment data]]
            (let [node (parse-node [name-segment] data)]
              (update root :children conj node)))]
    (let [root {:name [] :children ()}
          tree (reduce parse-step root data)]
      (-> tree
          (process-down set-parent nil)))))

(defn flatten-tree [node]
  (letfn [(collect-step [m node]
            (merge m (flatten-tree node)))]
    (reduce collect-step
            (if (custard-node? node) 
              {(:name node) node}
              {})
            (:children node))))
