       (let [node (->> loc zip/node)]
         (recur (->> loc zip/next)
                (if (= node :message)
-                 (cons (buildmessage loc) msgs)
+                 (cons (buildmessage fqname loc) msgs)
                  msgs))))))
+
+(defn buildallmessages [ast]
+  (->> ast (map (fn [[fqname ast]] (buildmessages fqname ast))) flatten))
 
 ;;(defn generateproto [intf ast template]
 ;;  (loop [loc ast]

    (map (fn [[index {:keys [modifier type fieldName]}]]
           (->Field modifier (let [[_ _type] type] _type) fieldName index)) rawfields)))

(defn buildmessage [ast]
  (let [name (->> ast zip/right zip/node)
        fields (buildfields (->> ast zip/right zip/right))]
    (->Message name fields)))

(defn buildmessages [ast]
  (loop [loc ast msgs '()]
    (cond


    ;; and then generate our output
    (let [stg  (STGroupFile. "generators/proto.stg")
          template (.getInstanceOf stg "protobuf")]
      (.add template "messages" messages)
      (with-open [output (io/writer protopath :truncate true)]
        (.write output (.render template))))))
