Skip to content

Commit fc11bb3

Browse files
authored
Split keyword captures into subgroups (#108)
This introduces the backwards compatible captures: - `@keyword.definition` - `@keyword.import` - `@keyword.control.conditional` - `@keyword.control.repeat` - `@keyword.exception` - `@keyword.operator` - `@keyword.operator.regex` (used by the `~r` sigil modifiers) Additionally, this also defines the `@label.modifier` capture for all other sigil modifiers
1 parent 708fff8 commit fc11bb3

2 files changed

Lines changed: 62 additions & 18 deletions

File tree

.tsqueryrc.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@
3838
"function.special.call": "Captures built-in function calls",
3939
"hint": "Captures hints",
4040
"keyword": "Captures keywords",
41-
"keyword.exception": "Captures keywords for exception handling",
41+
"keyword.control": "Captures control flow keywords",
42+
"keyword.control.conditional": "Captures conditional control flow keywords",
43+
"keyword.control.repeat": "Captures loop control flow keywords",
44+
"keyword.control.return": "Captures return control flow keywords",
45+
"keyword.definition": "Captures definition keywords",
46+
"keyword.exception": "Captures exception handling keywords",
4247
"keyword.import": "Captures import keywords",
48+
"keyword.operator": "Captures operator keywords",
49+
"keyword.operator.regex": "Captures regex mode modifiers",
4350
"label": "Captures labels",
51+
"label.modifier": "Captures modifiers",
4452
"link_text": "Captures link text",
4553
"link_uri": "Captures link URIs",
4654
"number": "Captures numeric values",

languages/elixir/highlights.scm

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
quoted_start: _ @string.special
103103
quoted_end: _ @string.special) @string.special
104104

105+
; Sigil modifiers
106+
(sigil_modifiers) @label.modifier
107+
105108
; String/charlist sigils
106109
(sigil
107110
(sigil_name) @_sigil_name @string
@@ -114,6 +117,7 @@
114117
(sigil_name) @_sigil_name @string.regex
115118
quoted_start: _ @string.regex
116119
quoted_end: _ @string.regex
120+
(sigil_modifiers)? @keyword.operator.regex
117121
(#any-of? @_sigil_name "R" "r")) @string.regex
118122

119123
; Phoenix HEEx template sigil
@@ -239,7 +243,7 @@
239243

240244
; Function/macro definitions
241245
(call
242-
target: (identifier) @keyword
246+
target: (identifier) @keyword.definition
243247
(arguments
244248
[
245249
(identifier) @function
@@ -257,7 +261,7 @@
257261
operator: "|>"
258262
right: (identifier) @variable)
259263
])
260-
(#any-of? @keyword
264+
(#any-of? @keyword.definition
261265
"def" "defp" "defdelegate" "defguard" "defguardp" "defmacro" "defmacrop" "defn" "defnp"
262266
"deftransform" "deftransformp"))
263267

@@ -343,32 +347,64 @@
343347

344348
; Definition keywords
345349
(call
346-
target: (identifier) @keyword
347-
(#any-of? @keyword
350+
target: (identifier) @keyword.definition
351+
(#any-of? @keyword.definition
348352
"def" "defp" "defdelegate" "defoverridable" "defguard" "defguardp" "defmacro" "defmacrop"
349353
"defstruct" "defexception" "defrecord" "defrecordp" "defmodule" "defprotocol" "defimpl" "defn"
350354
"defnp" "deftransform" "deftransformp"))
351355

352-
; Kernel/special form keywords
356+
; Reserved definition keyword
357+
"fn" @keyword.definition
358+
359+
; Module import keywords
360+
(call
361+
target: (identifier) @keyword.import
362+
(#any-of? @keyword.import "alias" "import" "require" "use"))
363+
364+
; Control flow keywords
365+
(call
366+
target: (identifier) @keyword.control.conditional
367+
(#any-of? @keyword.control.conditional "case" "cond" "if" "receive" "unless" "with"))
368+
369+
; Reserved control flow keywords
370+
[
371+
"after"
372+
"else"
373+
] @keyword.control.conditional
374+
375+
; List comprehension keyword
376+
(call
377+
target: (identifier) @keyword.control.repeat
378+
(#eq? @keyword.control.repeat "for"))
379+
380+
; Exception handling keywords
381+
(call
382+
target: (identifier) @keyword.exception
383+
(#any-of? @keyword.exception "raise" "reraise" "throw" "try"))
384+
385+
; Reserved exception handling keywords
386+
[
387+
"catch"
388+
"rescue"
389+
] @keyword.exception
390+
391+
; Metaprogramming keywords
353392
(call
354393
target: (identifier) @keyword
355-
(#any-of? @keyword
356-
"alias" "case" "cond" "else" "for" "if" "import" "quote" "raise" "receive" "require" "reraise"
357-
"super" "throw" "try" "unless" "unquote" "unquote_splicing" "use" "with"))
394+
(#any-of? @keyword "quote" "super" "unquote" "unquote_splicing"))
358395

359-
; Reserved keywords
396+
; Operator keywords
360397
[
361-
"when"
362398
"and"
363-
"or"
364-
"not"
365399
"in"
400+
"not"
366401
"not in"
367-
"fn"
402+
"or"
403+
"when"
404+
] @keyword.operator
405+
406+
; Do-end block keywords
407+
[
368408
"do"
369409
"end"
370-
"catch"
371-
"rescue"
372-
"after"
373-
"else"
374410
] @keyword

0 commit comments

Comments
 (0)