                  " must have its own method implementation of " `render)]
     (throw (ex-info msg {:spec spec}))))
 
+(defn call-with-base-printer [f printer x]
+  (f (:base-printer printer) x))
+
 (defn- highlight [x]
   [:span [:escaped *highlighting-mark*] x [:escaped *highlighting-mark*]])
 

  (let [frame (first trace)]
    (if (= x (:val frame))
      (if (and (= (count trace) 1) (not (:reason frame)))
        (highlight (f (:base-printer printer) x))
        (render frame printer x))
      (f (:base-printer printer) x))))

(defn pop-trace [printer]
  (update printer :trace rest))


(defn- render-regex [{:keys [reason steps] :as frame} printer x]
  (cond (= reason "Extra input")
        (render-coll frame (:base-printer printer) x
          (fn [i v]
            (cond-> (call-with-base-printer visit/visit printer v)
              (>= i (first steps)) highlight)))

        (or (= reason "Insufficient input") ;; special case for s/alt
            (when-let [next-frame (second (:trace printer))]
              (= (:reason next-frame) "Insufficient input")))
        (let [x (if (seq? x) (concat x ['...]) (conj x '...))]
          (render-coll frame printer x
            (fn [i v]
              (cond-> (call-with-base-printer visit/visit printer v)
                (= i (dec (count x))) highlight))))

        (empty? steps)
