 (require '[net.cgrand.parsley.lrplus :as l])
 (require '[net.cgrand.parsley.fold :as f])
 (require '[paredit.loc-utils :as lu])
-(defn dser-ser-inc 
-  "Demonstration of parsley's incremental features"
-  [d]
-  (println "----------------------------------------")
-  (let [steps (do (println "steps computing") (time (first (reduce (fn [[steps l] r] 
-                               (let [step (sexp l r)] 
-                                 [(conj steps step) step])) 
-                             [[] l/zero]
-                             (concat d [nil])))))
-        stitch (do (println "reducing steps") (time (reduce f/stitch steps)))]
-    (f/make-node :root (nth stitch 2)))))
-
-(comment
-  ;; {:v {:count}, :l, :r}
-(defprotocol BST
-  (bst-node ([this]) ([this l r v])))
-
-(defrecord Leaf [v]
-  BST
-  (bst-node [this] this))
-(defn node-val [l r]
-  {:count (+ (-> l bst-node :v :count) (-> r bst-node :v :count))})
-(defrecord Node [l r v]
-  BST
-  (bst-node ([this] this)
-            ([this l r] (Node. l r (node-val l r))))))+(let [c (slurp "C:\\Users\\Laurent\\Downloads\\1.3.0-alpha6\\src\\clj\\clojure\\core.clj")]
+
+  (println "Executing full parser:")
+  (dotimes [_ 10] (time (sexp c)))
+
+  (println "Executing parser incrementally:")
+  (dotimes [_ 10] (time (-> sexp p/incremental-buffer (p/edit 0 0 c) parse-tree)  ))
+  (println "Test edit incremental")
+
+  (dotimes [_ 10]
+    (let [b (let [_ (println "initial incremental buffer")
+                  b (time (-> sexp p/incremental-buffer (p/edit 0 0 c)))
+                  _ (println "initial parse-tree")
+                  _ (time (p/parse-tree b))]
+              b)
+          b (let [_ (println "edit in the top comment")
+                  b (time (-> b (p/edit 1 0 "coucou")))
+                  _ (println "parse-tree after edit in the top comment")
+                  _ (time (p/parse-tree b))]
+              b)
+          b (let [_ (println "add '(\\n' before the top comment")
+                  b (time (-> b (p/edit 0 0 "(\n"))) 
+                  _ (println "parse-tree after add '(\\n' before the top comment")
+                  _ (time (p/parse-tree b))]
+              b)]
+      b))
+  (= c (lu/node-text (-> sexp p/incremental-buffer (p/edit 0 0 c) p/parse-tree)) (lu/node-text (sexp c)))))

                [open-map :expr* #{")" "]" eof}]
                [open-fn :expr* #{"]" "}" eof}]
                [open-set :expr* #{")" "]" eof}]
                (unspaced open-string #"(?:\\.|[^\\\"])++(?!\")" :? eof)
                (unspaced open-regex #"(?:\\.|[^\\\"])++(?!\")" :? eof)
                [open-quote #{"]" "}" ")" eof}]
                [open-meta :expr :? #{"]" "}" ")" eof}]
                [open-deprecated-meta :expr :? #{"]" "}" ")" eof}]

  (:use paredit.regex-utils)
	(:require [clojure.zip :as zip])
  (:require [clojure.contrib.zip-filter :as zf])
  (:require [net.cgrand.parsley :as p])
  (:require [net.cgrand.parsley.lrplus :as lr+])
  (:require [net.cgrand.regex :as r]))

