Skip to content

Commit 74c7682

Browse files
committed
Move vim-nfa-dump to test and add convenience fn
1 parent 742216c commit 74c7682

2 files changed

Lines changed: 47 additions & 30 deletions

File tree

clj/src/vim_clojure_static/generate.clj

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
;; Joel Holdbrooks <cjholdbrooks@gmail.com>
33

44
(ns vim-clojure-static.generate
5-
(:require [clojure.java.shell :as shell]
6-
[clojure.set :as set]
5+
(:require [clojure.set :as set]
76
[clojure.string :as string]))
87

98
;;
@@ -222,16 +221,6 @@
222221
(fmt "script=" :script)
223222
(fmt "block=" :block)])))
224223

225-
(defn vim-nfa-dump
226-
"Run a patched version of Vim compiled with -DDEBUG on a new file containing
227-
buffer, then move the NFA log to log-path. The patch is located at
228-
vim/custom-nfa-log.patch"
229-
[vim-path buffer log-path]
230-
(let [file "tmp/nfa-test-file.clj"]
231-
(spit file buffer)
232-
(shell/sh vim-path "-u" "NONE" "-N" "-S" "vim/test-runtime.vim" file)
233-
(shell/sh "mv" "nfa_regexp.log" log-path)))
234-
235224
(comment
236225
;; Generate the vim literal definitions for pasting into the runtime files.
237226
(spit "tmp/clojure-defs.vim"
@@ -251,23 +240,7 @@
251240
vim-unicode-category-char-classes
252241
vim-unicode-script-char-classes
253242
vim-unicode-block-char-classes))
254-
(spit "tmp/nfa-test-file.clj"
243+
;; Generate an example file with all possible character property literals.
244+
(spit "tmp/all-char-props.clj"
255245
comprehensive-clojure-character-property-regexps)
256-
;; Create regexp engine dump files and compare number of operations.
257-
(let [syn-path "../syntax/clojure.vim"
258-
orig-syn-buf (slurp syn-path)
259-
vim-path (or (System/getenv "VIMDEBUG") "vim")
260-
buf (format "#\"\\p{%s}\"\n" "Ll")
261-
buf-hash (hash buf)]
262-
(try
263-
(mapv (fn [path]
264-
(let [syn-buf (slurp path)
265-
syn-hash (hash syn-buf)
266-
log-path (format "tmp/debug:%d:%d.log" buf-hash syn-hash)]
267-
(spit syn-path syn-buf)
268-
(vim-nfa-dump vim-path buf log-path)
269-
(count (re-seq #"\n" (slurp log-path)))))
270-
["../syntax/clojure.vim" "tmp/altsyntax.vim"])
271-
(finally
272-
(spit syn-path orig-syn-buf))))
273246
)

clj/src/vim_clojure_static/test.clj

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,42 @@
6969
ss λs)))
7070
contexts)))))
7171

72+
(defn vim-nfa-dump
73+
"Run a patched version of Vim compiled with -DDEBUG on a new file containing
74+
buffer, then move the NFA log to log-path. The patch is located at
75+
vim/custom-nfa-log.patch"
76+
[vim-path buffer log-path]
77+
(let [file "tmp/nfa-test-file.clj"]
78+
(spit file buffer)
79+
(time (shell/sh vim-path "-u" "NONE" "-N" "-S" "vim/test-runtime.vim" file))
80+
(shell/sh "mv" "nfa_regexp.log" log-path)))
81+
82+
(defn compare-nfa-dumps
83+
"Dump NFA logs with given buffer and syntax-files; log-files are written to
84+
tmp/ and are distinguished by the hash of the buffer and syntax script.
85+
86+
The vim-path passed to vim-nfa-dump should either be in the VIMDEBUG
87+
environment variable, or be the top vim in your PATH.
88+
89+
Returns the line count of each corresponding log file."
90+
[buf [& syntax-files] & opts]
91+
(let [{:keys [vim-path]
92+
:or {vim-path (or (System/getenv "VIMDEBUG") "vim")}} opts
93+
syn-path "../syntax/clojure.vim"
94+
orig-syn (slurp syn-path)
95+
buf-hash (hash buf)]
96+
(try
97+
(mapv (fn [path]
98+
(let [syn-buf (slurp path)
99+
syn-hash (hash syn-buf)
100+
log-path (format "tmp/debug:%d:%d.log" buf-hash syn-hash)]
101+
(spit syn-path syn-buf)
102+
(vim-nfa-dump vim-path buf log-path)
103+
(count (re-seq #"\n" (slurp log-path)))))
104+
syntax-files)
105+
(finally
106+
(spit syn-path orig-syn)))))
107+
72108
(comment
73109

74110
(macroexpand-1
@@ -80,4 +116,12 @@
80116
["^" #(= % [:clojureRegexpBoundary])]]))
81117
(test #'number-literals-test)
82118

119+
(defn dump! [buf]
120+
(compare-nfa-dumps (format "#\"\\p{%s}\"\n" buf)
121+
["../syntax/clojure.vim" "tmp/altsyntax.vim"]))
122+
123+
(dump! "Ll")
124+
(dump! "javaLowercase")
125+
(dump! "block=UNIFIED CANADIAN ABORIGINAL SYLLABICS")
126+
83127
)

0 commit comments

Comments
 (0)