Skip to content

Commit 77aecec

Browse files
committed
Bump clojure grammar
1 parent f11916b commit 77aecec

File tree

2 files changed

+72
-31
lines changed

2 files changed

+72
-31
lines changed

queries/clojure/highlights.scm

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66
;; For the most part this means that some things have to be assigned multiple
77
;; groups.
88
;; By doing this we can add a basic capture and then later refine it with more
9-
;; specialied captures.
9+
;; specialized captures.
1010
;; This can mean that sometimes things are highlighted weirdly because they
1111
;; have multiple highlight groups applied to them.
1212

1313

1414
;; >> Literals
1515

16+
(
17+
(dis_expr) @comment
18+
(#set! "priority" 105) ; Higher priority to mark the whole sexpr as a comment
19+
)
1620
(kwd_lit) @symbol
1721
(str_lit) @string
1822
(num_lit) @number
1923
(char_lit) @character
2024
(bool_lit) @boolean
2125
(nil_lit) @constant.builtin
22-
(comment) @comment
26+
(comment) @comment @spell
2327
(regex_lit) @string.regex
2428

2529
["'" "`"] @string.escape
@@ -51,44 +55,66 @@
5155

5256
; Used in destructure pattern
5357
((sym_lit) @parameter
54-
(#match? @parameter "^[&]"))
58+
(#lua-match? @parameter "^[&]"))
5559

5660
; Inline function variables
5761
((sym_lit) @variable.builtin
58-
(#match? @variable.builtin "^[%]"))
62+
(#lua-match? @variable.builtin "^%%"))
5963

6064
; Constructor
61-
;;((sym_lit) @constructor
62-
;; (#match? @constructor "^-\\>[^\\>].*"))
65+
((sym_lit) @constructor
66+
(#lua-match? @constructor "^-%>[^>].*"))
6367

64-
; Dynamic variables
68+
; Builtin dynamic variables
6569
((sym_lit) @variable.builtin
66-
(#match? @variable.builtin "^[*].+[*]$"))
70+
(#any-of? @variable.builtin
71+
"*agent*" "*allow-unresolved-vars*" "*assert*"
72+
"*clojure-version*" "*command-line-args*"
73+
"*compile-files*" "*compile-path*" "*compiler-options*"
74+
"*data-readers*" "*default-data-reader-fn*"
75+
"*err*" "*file*" "*flush-on-newline*" "*fn-loader*"
76+
"*in*" "*math-context*" "*ns*" "*out*"
77+
"*print-dup*" "*print-length*" "*print-level*"
78+
"*print-meta*" "*print-namespace-maps*" "*print-readably*"
79+
"*read-eval*" "*reader-resolver*"
80+
"*source-path*" "*suppress-read*"
81+
"*unchecked-math*" "*use-context-classloader*"
82+
"*verbose-defrecords*" "*warn-on-reflection*"))
83+
84+
; Builtin repl variables
85+
((sym_lit) @variable.builtin
86+
(#any-of? @variable.builtin
87+
"*1" "*2" "*3" "*e"))
6788

6889
; Gensym
6990
;; Might not be needed
7091
((sym_lit) @variable
71-
(#match? @variable "^.*#$"))
92+
(#lua-match? @variable "^.*#$"))
7293

7394
; Types
7495
;; TODO: improve?
7596
((sym_lit) @type
76-
(#match? @type "^[A-Z][^/]*$"))
97+
(#lua-match? @type "^[%u][^/]*$"))
7798
;; Symbols with `.` but not `/`
7899
((sym_lit) @type
79-
(#match? @type "^[^/]+[.][^/]*$"))
100+
(#lua-match? @type "^[^/]+[.][^/]*$"))
80101

81102
; Interop
103+
; (.instanceMember instance args*)
104+
; (.instanceMember Classname args*)
82105
((sym_lit) @method
83-
(#match? @method "^\\.[^-]"))
106+
(#lua-match? @method "^%.[^-]"))
107+
; (.-instanceField instance)
84108
((sym_lit) @field
85-
(#match? @field "^\\.-"))
109+
(#lua-match? @field "^%.%-.*"))
110+
; Classname/staticField
86111
((sym_lit) @field
87-
(#match? @field "^[A-Z].*/.+"))
112+
(#lua-match? @field "^[%u].*/.+"))
113+
; (Classname/staticMethod args*)
88114
(list_lit
89115
.
90116
(sym_lit) @method
91-
(#match? @method "^[A-Z].*/.+"))
117+
(#lua-match? @method "^[%u].*/.+"))
92118
;; TODO: Special casing for the `.` macro
93119

94120
; Operators
@@ -103,13 +129,16 @@
103129
; Definition functions
104130
((sym_lit) @keyword
105131
(#any-of? @keyword
106-
"def" "defonce" "defrecord" "defmacro" "definline"
132+
"def" "defonce" "defrecord" "defmacro" "definline" "definterface"
107133
"defmulti" "defmethod" "defstruct" "defprotocol"
108134
"deftype"))
109135
((sym_lit) @keyword
110136
(#eq? @keyword "declare"))
137+
((sym_name) @keyword.coroutine
138+
(#any-of? @keyword.coroutine
139+
"alts!" "alts!!" "await" "await-for" "await1" "chan" "close!" "future" "go" "sync" "thread" "timeout" "<!" "<!!" ">!" ">!!"))
111140
((sym_lit) @keyword.function
112-
(#match? @keyword.function "^(defn|defn-|fn|fn[*])$"))
141+
(#any-of? @keyword.function "defn" "defn-" "fn" "fn*"))
113142

114143
; Comment
115144
((sym_lit) @comment
@@ -120,9 +149,11 @@
120149
(#any-of? @conditional
121150
"case" "cond" "cond->" "cond->>" "condp"))
122151
((sym_lit) @conditional
123-
(#match? @conditional "^if(\\-.*)?$"))
152+
(#any-of? @conditional
153+
"if" "if-let" "if-not" "if-some"))
124154
((sym_lit) @conditional
125-
(#match? @conditional "^when(\\-.*)?$"))
155+
(#any-of? @conditional
156+
"when" "when-first" "when-let" "when-not" "when-some"))
126157

127158
; Repeats
128159
((sym_lit) @repeat
@@ -132,7 +163,7 @@
132163
; Exception
133164
((sym_lit) @exception
134165
(#any-of? @exception
135-
"throw" "try" "catch" "finally" "ex-info"))
166+
"throw" "try" "catch" "finally"))
136167

137168
; Includes
138169
((sym_lit) @include
@@ -144,21 +175,20 @@
144175
(#any-of? @function.macro
145176
"." ".." "->" "->>" "amap" "areduce" "as->" "assert"
146177
"binding" "bound-fn" "delay" "do" "dosync"
147-
"doto" "extend-protocol" "extend-type" "future"
178+
"doto" "extend-protocol" "extend-type"
148179
"gen-class" "gen-interface" "io!" "lazy-cat"
149180
"lazy-seq" "let" "letfn" "locking" "memfn" "monitor-enter"
150181
"monitor-exit" "proxy" "proxy-super" "pvalues"
151-
"refer-clojure" "reify" "set!" "some->" "some->>" "sync"
182+
"refer-clojure" "reify" "set!" "some->" "some->>"
152183
"time" "unquote" "unquote-splicing" "var" "vswap!"
153-
"ex-cause" "ex-data" "ex-message"))
154-
((sym_lit) @function.macro
155-
(#match? @function.macro "^with\\-.*$"))
184+
"with-bindings" "with-in-str" "with-loading-context" "with-local-vars"
185+
"with-open" "with-out-str" "with-precision" "with-redefs"))
156186

157187
; All builtin functions
158188
; (->> (ns-publics *ns*)
159189
; (keep (fn [[s v]] (when-not (:macro (meta v)) s)))
160190
; sort
161-
; cp/print))
191+
; clojure.pprint/pprint))
162192
;; ...and then lots of manual filtering...
163193
((sym_lit) @function.builtin
164194
(#any-of? @function.builtin
@@ -171,9 +201,8 @@
171201
"any?" "apply" "array-map" "aset" "aset-boolean" "aset-byte"
172202
"aset-char" "aset-double" "aset-float" "aset-int"
173203
"aset-long" "aset-short" "assoc" "assoc!" "assoc-in"
174-
"associative?" "atom" "await" "await-for" "await1"
175-
"bases" "bean" "bigdec" "bigint" "biginteger" "bit-and"
176-
"bit-and-not" "bit-clear" "bit-flip" "bit-not" "bit-or"
204+
"associative?" "atom" "bases" "bean" "bigdec" "bigint" "biginteger"
205+
"bit-and" "bit-and-not" "bit-clear" "bit-flip" "bit-not" "bit-or"
177206
"bit-set" "bit-shift-left" "bit-shift-right" "bit-test"
178207
"bit-xor" "boolean" "boolean-array" "boolean?"
179208
"booleans" "bound-fn*" "bound?" "bounded-count"
@@ -271,7 +300,19 @@
271300
"val" "vals" "var-get" "var-set" "var?" "vary-meta" "vec"
272301
"vector" "vector-of" "vector?" "volatile!" "volatile?"
273302
"vreset!" "with-bindings*" "with-meta" "with-redefs-fn" "xml-seq"
274-
"zero?" "zipmap"))
303+
"zero?" "zipmap"
304+
;; earlier
305+
"drop" "drop-last" "drop-while"
306+
"double?" "doubles"
307+
"ex-data" "ex-info"
308+
;; 1.10
309+
"ex-cause" "ex-message"
310+
;; 1.11
311+
"NaN?" "abs" "infinite?" "iteration" "random-uuid"
312+
"parse-boolean" "parse-double" "parse-long" "parse-uuid"
313+
"seq-to-map-for-destructuring" "update-keys" "update-vals"
314+
;; 1.12
315+
"partitionv" "partitionv-all" "splitv-at"))
275316

276317

277318

0 commit comments

Comments
 (0)