      (fn [& children]
        (let [[lhs rhs] children]
          [:Disjunction (-negate-formula lhs) rhs]))} tree))
-
-(defn- -reconstruct-node [key children] (into [key] children))
 
 (defn- -transform-term-negation
   [& children]

(ns formlogic.parser
  (:require [instaparse.core :as insta]
            [clojure.tools.logging :as log]))

(def logic-parser (insta/parser (clojure.java.io/resource "logic.bnf")
                                :auto-whitespace :standard))

(def nonterms ^{:doc "Vector of all non-terminals"}
  [:WellFormedFormula
   :QuantifiedFormula
   :Quantifier

      :Conjunction [:Disjunction (-negate-formula lhs) (-negate-formula rhs)]
      :Disjunction [:Conjunction (-negate-formula lhs) (-negate-formula rhs)]
      :Negation lhs
      ;; This is a custom rule, used for ~(\\A x) forms. Replace it with form
      ;; that can be negated in next run with the other rule.
      :QuantifiedFormula [:QuantifiedFormula (-negate-quantifier lhs) rhs]
      ;; In default case, do nothing - reconstruct original node.
      (-reconstruct-node :Negation children))))

(defn- -transform-quantifier-negation
  [& children]
  (let [[quantifier formula] children]
    (if (nonterm? quantifier :QuantifierNegation)
      (let [[[_ foreach-exists literal]] (rest quantifier)]
        (-reconstruct-node :QuantifiedFormula
                           [[:Quantifier
