Skip to content

Commit

Permalink
Bump clojure grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Nov 29, 2023
1 parent f11916b commit 77aecec
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 31 deletions.
101 changes: 71 additions & 30 deletions queries/clojure/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@
;; For the most part this means that some things have to be assigned multiple
;; groups.
;; By doing this we can add a basic capture and then later refine it with more
;; specialied captures.
;; specialized captures.
;; This can mean that sometimes things are highlighted weirdly because they
;; have multiple highlight groups applied to them.


;; >> Literals

(
(dis_expr) @comment
(#set! "priority" 105) ; Higher priority to mark the whole sexpr as a comment
)
(kwd_lit) @symbol
(str_lit) @string
(num_lit) @number
(char_lit) @character
(bool_lit) @boolean
(nil_lit) @constant.builtin
(comment) @comment
(comment) @comment @spell
(regex_lit) @string.regex

["'" "`"] @string.escape
Expand Down Expand Up @@ -51,44 +55,66 @@

; Used in destructure pattern
((sym_lit) @parameter
(#match? @parameter "^[&]"))
(#lua-match? @parameter "^[&]"))

; Inline function variables
((sym_lit) @variable.builtin
(#match? @variable.builtin "^[%]"))
(#lua-match? @variable.builtin "^%%"))

; Constructor
;;((sym_lit) @constructor
;; (#match? @constructor "^-\\>[^\\>].*"))
((sym_lit) @constructor
(#lua-match? @constructor "^-%>[^>].*"))

; Dynamic variables
; Builtin dynamic variables
((sym_lit) @variable.builtin
(#match? @variable.builtin "^[*].+[*]$"))
(#any-of? @variable.builtin
"*agent*" "*allow-unresolved-vars*" "*assert*"
"*clojure-version*" "*command-line-args*"
"*compile-files*" "*compile-path*" "*compiler-options*"
"*data-readers*" "*default-data-reader-fn*"
"*err*" "*file*" "*flush-on-newline*" "*fn-loader*"
"*in*" "*math-context*" "*ns*" "*out*"
"*print-dup*" "*print-length*" "*print-level*"
"*print-meta*" "*print-namespace-maps*" "*print-readably*"
"*read-eval*" "*reader-resolver*"
"*source-path*" "*suppress-read*"
"*unchecked-math*" "*use-context-classloader*"
"*verbose-defrecords*" "*warn-on-reflection*"))

; Builtin repl variables
((sym_lit) @variable.builtin
(#any-of? @variable.builtin
"*1" "*2" "*3" "*e"))

; Gensym
;; Might not be needed
((sym_lit) @variable
(#match? @variable "^.*#$"))
(#lua-match? @variable "^.*#$"))

; Types
;; TODO: improve?
((sym_lit) @type
(#match? @type "^[A-Z][^/]*$"))
(#lua-match? @type "^[%u][^/]*$"))
;; Symbols with `.` but not `/`
((sym_lit) @type
(#match? @type "^[^/]+[.][^/]*$"))
(#lua-match? @type "^[^/]+[.][^/]*$"))

; Interop
; (.instanceMember instance args*)
; (.instanceMember Classname args*)
((sym_lit) @method
(#match? @method "^\\.[^-]"))
(#lua-match? @method "^%.[^-]"))
; (.-instanceField instance)
((sym_lit) @field
(#match? @field "^\\.-"))
(#lua-match? @field "^%.%-.*"))
; Classname/staticField
((sym_lit) @field
(#match? @field "^[A-Z].*/.+"))
(#lua-match? @field "^[%u].*/.+"))
; (Classname/staticMethod args*)
(list_lit
.
(sym_lit) @method
(#match? @method "^[A-Z].*/.+"))
(#lua-match? @method "^[%u].*/.+"))
;; TODO: Special casing for the `.` macro

; Operators
Expand All @@ -103,13 +129,16 @@
; Definition functions
((sym_lit) @keyword
(#any-of? @keyword
"def" "defonce" "defrecord" "defmacro" "definline"
"def" "defonce" "defrecord" "defmacro" "definline" "definterface"
"defmulti" "defmethod" "defstruct" "defprotocol"
"deftype"))
((sym_lit) @keyword
(#eq? @keyword "declare"))
((sym_name) @keyword.coroutine
(#any-of? @keyword.coroutine
"alts!" "alts!!" "await" "await-for" "await1" "chan" "close!" "future" "go" "sync" "thread" "timeout" "<!" "<!!" ">!" ">!!"))
((sym_lit) @keyword.function
(#match? @keyword.function "^(defn|defn-|fn|fn[*])$"))
(#any-of? @keyword.function "defn" "defn-" "fn" "fn*"))

; Comment
((sym_lit) @comment
Expand All @@ -120,9 +149,11 @@
(#any-of? @conditional
"case" "cond" "cond->" "cond->>" "condp"))
((sym_lit) @conditional
(#match? @conditional "^if(\\-.*)?$"))
(#any-of? @conditional
"if" "if-let" "if-not" "if-some"))
((sym_lit) @conditional
(#match? @conditional "^when(\\-.*)?$"))
(#any-of? @conditional
"when" "when-first" "when-let" "when-not" "when-some"))

; Repeats
((sym_lit) @repeat
Expand All @@ -132,7 +163,7 @@
; Exception
((sym_lit) @exception
(#any-of? @exception
"throw" "try" "catch" "finally" "ex-info"))
"throw" "try" "catch" "finally"))

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

; All builtin functions
; (->> (ns-publics *ns*)
; (keep (fn [[s v]] (when-not (:macro (meta v)) s)))
; sort
; cp/print))
; clojure.pprint/pprint))
;; ...and then lots of manual filtering...
((sym_lit) @function.builtin
(#any-of? @function.builtin
Expand All @@ -171,9 +201,8 @@
"any?" "apply" "array-map" "aset" "aset-boolean" "aset-byte"
"aset-char" "aset-double" "aset-float" "aset-int"
"aset-long" "aset-short" "assoc" "assoc!" "assoc-in"
"associative?" "atom" "await" "await-for" "await1"
"bases" "bean" "bigdec" "bigint" "biginteger" "bit-and"
"bit-and-not" "bit-clear" "bit-flip" "bit-not" "bit-or"
"associative?" "atom" "bases" "bean" "bigdec" "bigint" "biginteger"
"bit-and" "bit-and-not" "bit-clear" "bit-flip" "bit-not" "bit-or"
"bit-set" "bit-shift-left" "bit-shift-right" "bit-test"
"bit-xor" "boolean" "boolean-array" "boolean?"
"booleans" "bound-fn*" "bound?" "bounded-count"
Expand Down Expand Up @@ -271,7 +300,19 @@
"val" "vals" "var-get" "var-set" "var?" "vary-meta" "vec"
"vector" "vector-of" "vector?" "volatile!" "volatile?"
"vreset!" "with-bindings*" "with-meta" "with-redefs-fn" "xml-seq"
"zero?" "zipmap"))
"zero?" "zipmap"
;; earlier
"drop" "drop-last" "drop-while"
"double?" "doubles"
"ex-data" "ex-info"
;; 1.10
"ex-cause" "ex-message"
;; 1.11
"NaN?" "abs" "infinite?" "iteration" "random-uuid"
"parse-boolean" "parse-double" "parse-long" "parse-uuid"
"seq-to-map-for-destructuring" "update-keys" "update-vals"
;; 1.12
"partitionv" "partitionv-all" "splitv-at"))



Expand Down
2 changes: 1 addition & 1 deletion repos/clojure

0 comments on commit 77aecec

Please sign in to comment.