 #_(pp)
 ;; printing
 
+(defn gen-path [path value]
+  (if (empty? path)
+    value
+    (let [[x & xs] path]
+      (cond
+        (and (integer? x) (zero? x))
+        [(gen-path xs value)]
+        :else {x (gen-path xs value)}))))
+
 (defn print-path [[x & xs] leaf-node edn]
-  (if (and x (get edn x))
-    (let [v (get edn x)]
-      [:group
-       (str (if (map? edn)
-              (str (pr-str x) " ")
-              "")
-            (if (and (not (map? v)) (integer? (first xs)))
-              "["
-              "{"))
-       (if (map? v)
-         [:nest 2
-          :line
-          (print-path xs leaf-node v)]
-         (print-path xs leaf-node v))
-       (if (and (not (map? v)) (integer? (first xs)))
-         "]"
-         "}")])
-    leaf-node))
+   (if (and x (get edn x))
+     (let [v (get edn x)]
+       [:group
+        (str (if (map? edn)
+               (str (pr-str x) " ")
+               "")
+             (if (and (not (map? v)) (integer? (first xs)))
+               "["
+               "{"))
+        (if (map? v)
+          [:nest 2
+           :line
+           (print-path xs leaf-node v)]
+          (print-path xs leaf-node v))
+        (if (and (not (map? v)) (integer? (first xs)))
+          "]"
+          "}")])
+     leaf-node))
 
 #_(pprint-document (print-path2 [:cljsbuild :builds 0 :css-dirs] [:group "hey"] {:cljsbuild {:builds [{:css-dirs []}]}})
                  {:width 20})
 
+(defn blank-document? [x]
+  (or (nil? x)
+      (and (string? x) (string/blank? x))
+      (empty? x)))
+
+(defn print-document [d]
+  (if (blank-document? d)
+    [:group :break :break]
+    [:group :break d :line]))
+
 (defn print-path-error
   ([{:keys [path orig-config] :as error} leaf-node document]
+   (prn document)
+   (prn (print-document document))
    [:group
-    "\n------- Figwheel Configuration Error -------\n"
+    (color "\n------- Figwheel Configuration Error -------\n" :red)
     :break
     (error-help-message error)
     :break

                  ;; TODO make this conditional like keyword
                  ;; predicates
                  ;; BEFORE keyword predicates
                  (when (and (map? val) (> (count val) 0))
                    (for [[k _ [pt _ val-typ]] (schema-rules :-)
                          :when (and
                                 (not= k ky)
                                 (not (similar-key 0 k ky)))
                          parent-type (concrete-parent pt)]
                      (let [child-type-paths (filter #(= (first %) val-typ)
                                                     (tc-with-parent val-typ val))]
                        (when (< (good-bad-ratio child-type-paths)
                                 (if (> (count val) 1)
                                   0.5 0.3))
                          (mapcat #(concat [parent-type [:replace-key ky k]] %)
                                  child-type-paths))))))))]
    res
    ;; try keyword predicates expensive
    (doall
     (for [[pred-id _ [pt _ val-typ]] (schema-rules :?-)
           parent-type (concrete-parent pt)
           :when (when-let [pred-func (last (first (schema-rules [:= pred-id])))]
                   (pred-func ky)) 
           child-types (tc-with-parent val-typ val)]
       (concat [parent-type ky] child-types)))))

#_(pp)

     rule))))

(defn concrete-parent [typ']
  (or (not-empty
       (for [[ky _ [parent-type _ t]] (ancester-key-rules typ')]
         t))
      ;; TODO this type should exist in parent position in a rule
      (if (not-empty (schema-rules [:parent :-  typ']))
        [typ']
        [])))

(defn parents-for-type [typ']
  (for [[ky _ [parent-type _ t]] (ancester-key-rules typ')]
