                   ""
                   (try (slurp in)
                        (catch Exception e
-                         (fail (str "Could not read from '" in "'."))))))]
-      (if debug (println tree))
+                         (fail (str "Could not read from '" in "'."))))))
+          nls-map (nml-map tree)]
       (cond gets  (nml-gets tree gets (:no-prefix options))
             sets  (let [s (nml-str (nml-sets tree sets))]
                     (if (= out *out*)

    (let [val (nml-get tree nml key)]
      (println (if no-prefix val (str nml ":" key "=" val))))))

(defn- nml-map [tree]
  (let [q  #(str "\"" % "\"")
        f0 (fn [& nvsubseqs   ] (into {} nvsubseqs))
        f1 (fn [dataref values] { (q (nml-str dataref)) (q (nml-str values)) })
        f2 (fn [& stmts       ] (into {} stmts))
        f3 (fn [name nvseq    ] { (q (nml-str name)) nvseq })]
    (insta/transform {:nvseq f0 :nvsubseq f1 :s f2 :stmt f3 } tree)))

(defn- nml-name [x]

        child :nvseq
        f     (fn [& v] (into [child] (nml-uniq v)))]
      (insta/transform {child f} tree)))

;; formatting

(defn- fmt-namelist [nls-map]
  (let [f0 #(str "  " (first %) "=" (last %) "\n")
        f1 (fn [x] (str "&" (first x) "\n" (apply str (map f0 (sort (last x)))) "/\n"))]
    (string/trim (apply str (map f1 (sort nls-map))))))

;; main

