     (.setBuildParseTree parser true)
     (.program parser)))
 
-(with-children (main))
+(comment 
 
+  (with-children (main))
+  
+  )
+

            [clojure.set :as s])
  (:import [org.antlr.v4.runtime ANTLRFileStream CommonTokenStream ParserRuleContext]
           [clojure.lang Reflector]))

; Might be easier to implement in terms of .children
; Doesn't maintain order of child nodes

(defn find-branch-method-names [context]
  (->> context


(defn sorted-map-from-value-list [unsorted-map value-list]
  (let [inverted (s/map-invert unsorted-map)]
    (-> (reduce (fn [acc value] (assoc acc (inverted value) value))
                (sorted-map) value-list)
        (dissoc nil))))

(defn map-vals [t m]
  (into (empty m) (map (fn [[k v]] [k (t v)]) m)))

(defn with-children [context]
  (if (zero? (.getChildCount context))
    {:object context
     :text   (.getText context)}
    {:object context 
     :children (let [sorted (sorted-map-from-value-list (do-mapify context)
                                                        (.children context))]
                 (if (empty? sorted)
                   (map with-children (.children context))     
                   (map-vals with-children sorted)))}))

(defn main []
  (let [parser (-> (ANTLRFileStream. "resources/hiWaitBye.js")
