 (defn ternary? [exp]
   (and
     (= (.getChildCount exp) 5)
-    (= ":" (.getText (.getChild exp 1)))
-    (= "?" (.getText (.getChild exp 3)))))
+    (= "?" (.getText (.getChild exp 1)))
+    (= ":" (.getText (.getChild exp 3)))))
 
 
 (defn method-call? [exp]
   (or
-  (and
-    (= (.getChildCount exp) 3)
-    (= "(" (.getText (.getChild exp 1)))
-    (= ")" (.getText (.getChild exp 2))))
-  (and
-    (= (.getChildCount exp) 4)
-    (= "(" (.getText (.getChild exp 1)))
-    (= ")" (.getText (.getChild exp 3))))))
+    (and
+      (= (.getChildCount exp) 3)
+      (= "(" (.getText (.getChild exp 1)))
+      (= ")" (.getText (.getChild exp 2))))
+    (and
+      (= (.getChildCount exp) 4)
+      (= "(" (.getText (.getChild exp 1)))
+      (= ")" (.getText (.getChild exp 3))))))
 
 
 (defn member-access? [exp]


(defn visit-method-call [rule]
  (str
  "__method_call__"
  (visit-rule (.getChild rule 0))
  (when 
    (= (.getChildCount rule) 4)
    (hash (.getText (.getChild rule 2))))))


(defn visit-member-access [rule]



(defn transform [contract]
  (visit-rule (parse-contract contract)))


;Sort retrieval

(defn creates-identifier? [rule]
  (or
    (and
      (terminal? rule)
      (.contains (.toString (.getPayload rule)) "<100>"))
    (method-call? rule)
    (member-access? rule)
    (vector-access? rule)))


(defn infer-type [rule])


;Get the type of the other element of the binary relationship
(defn match-symmetric-type [rule]
  (if
    (= (.getChild (.getParent rule) 0) rule)
    (infer-type (.getChild (.getParent rule) 2))
    (infer-type (.getChild (.getParent rule) 0))))


(defn retrieve-sorts [root]
  (loop [result []
         i 0 
         max (.getChildCount root)]
    (if
      (= i max)
      result
      (let [cur (.getChild root i)]
        (cond
          ;adds the identifier and keep iterating children
          (creates-identifier? cur) (recur (conj result (visit-rule cur)) (+ i 1) max)
          ;skips terminal
          (terminal? cur) (recur result (+ i 1) max)
          ;keeps going down on the tree
          :else (recur (into [] (concat result (retrieve-sorts cur))) (+ i 1) max))))))
