|
2 | 2 | ;; Joel Holdbrooks <cjholdbrooks@gmail.com> |
3 | 3 |
|
4 | 4 | (ns vim-clojure-static.generate |
5 | | - (:require [clojure.set :as set] |
6 | | - [clojure.string :as string])) |
| 5 | + (:require [clojure.string :as string] |
| 6 | + [clojure.set :as set] |
| 7 | + [frak :as frak])) |
7 | 8 |
|
8 | 9 | ;; |
9 | 10 | ;; Helpers |
10 | 11 | ;; |
11 | 12 |
|
| 13 | +(defn vim-frak-pattern |
| 14 | + "Create a non-capturing regular expression pattern compatible with Vim." |
| 15 | + [strs] |
| 16 | + (-> (frak/pattern strs) |
| 17 | + str |
| 18 | + (string/replace #"\(\?:" "\\%\\("))) |
| 19 | + |
12 | 20 | (defn property-pattern |
13 | 21 | "Vimscript very magic pattern for a character property class." |
14 | 22 | ([s] (property-pattern s true)) |
|
23 | 31 | ([group fmt props braces?] |
24 | 32 | (format "syntax match %s \"%s\" contained display\n" |
25 | 33 | (name group) |
26 | | - (property-pattern (format fmt (string/join \| (sort props))) braces?)))) |
| 34 | + (property-pattern (format fmt (vim-frak-pattern props)) braces?)))) |
27 | 35 |
|
28 | 36 | (defn get-private-field |
29 | 37 | "Violate encapsulation and get the value of a private field." |
|
142 | 150 | ;; `IsPosix` works, but is undefined. |
143 | 151 | (syntax-match-properties |
144 | 152 | :clojureRegexpPosixCharClass |
145 | | - "%%(%s)" |
| 153 | + "%s" |
146 | 154 | (:posix character-properties))) |
147 | 155 |
|
148 | 156 | (def vim-java-char-classes |
149 | 157 | "Vimscript literal `syntax match` for \\p{javaMethod} property classes." |
150 | 158 | ;; `IsjavaMethod` works, but is undefined. |
151 | 159 | (syntax-match-properties |
152 | 160 | :clojureRegexpJavaCharClass |
153 | | - "java%%(%s)" |
| 161 | + "java%s" |
154 | 162 | (map #(string/replace % #"\Ajava" "") (:java character-properties)))) |
155 | 163 |
|
156 | 164 | (def vim-unicode-binary-char-classes |
|
159 | 167 | ;; insensitively like the other Unicode properties. |
160 | 168 | (syntax-match-properties |
161 | 169 | :clojureRegexpUnicodeCharClass |
162 | | - "\\cIs%%(%s)" |
| 170 | + "\\cIs%s" |
163 | 171 | (map string/lower-case (:binary character-properties)))) |
164 | 172 |
|
165 | 173 | (def vim-unicode-category-char-classes |
|
173 | 181 | (str |
174 | 182 | (syntax-match-properties |
175 | 183 | :clojureRegexpUnicodeCharClass |
176 | | - "%%(%s)" |
| 184 | + "%s" |
177 | 185 | (keys table) |
178 | 186 | false) |
179 | 187 | (syntax-match-properties |
180 | 188 | :clojureRegexpUnicodeCharClass |
181 | | - "%%(%s)" |
| 189 | + "%s" |
182 | 190 | (keys table)) |
183 | 191 | (syntax-match-properties |
184 | 192 | :clojureRegexpUnicodeCharClass |
185 | | - "%%(Is|gc\\=|general_category\\=)?%%(%s)" |
| 193 | + "%%(Is|gc\\=|general_category\\=)?%s" |
186 | 194 | subcats)))) |
187 | 195 |
|
188 | 196 | (def vim-unicode-script-char-classes |
|
194 | 202 | ;; InScriptName works, but is undefined. |
195 | 203 | (syntax-match-properties |
196 | 204 | :clojureRegexpUnicodeCharClass |
197 | | - "\\c%%(Is|sc\\=|script\\=)%%(%s)" |
| 205 | + "\\c%%(Is|sc\\=|script\\=)%s" |
198 | 206 | (map string/lower-case (:script character-properties)))) |
199 | 207 |
|
200 | 208 | (def vim-unicode-block-char-classes |
|
203 | 211 | ;; of Is. |
204 | 212 | (syntax-match-properties |
205 | 213 | :clojureRegexpUnicodeCharClass |
206 | | - "\\c%%(In|blk\\=|block\\=)%%(%s)" |
| 214 | + "\\c%%(In|blk\\=|block\\=)%s" |
207 | 215 | (map string/lower-case (:block character-properties)))) |
208 | 216 |
|
209 | 217 | (def comprehensive-clojure-character-property-regexps |
|
0 commit comments