aboutsummaryrefslogtreecommitdiffstats
path: root/queries
diff options
context:
space:
mode:
authorBert Baron <bertusbaron@gmail.com>2025-02-27 09:54:26 +0100
committerGitHub <noreply@github.com>2025-02-27 09:54:26 +0100
commit376a46ccecb8d839ca0cede51b03ae5da052490f (patch)
tree5178318af3d7bef15c49acec79a38625a1732b45 /queries
parentfix(kdl): highlight query order (#7688) (diff)
downloadnvim-treesitter-376a46ccecb8d839ca0cede51b03ae5da052490f.tar
nvim-treesitter-376a46ccecb8d839ca0cede51b03ae5da052490f.tar.gz
nvim-treesitter-376a46ccecb8d839ca0cede51b03ae5da052490f.tar.bz2
nvim-treesitter-376a46ccecb8d839ca0cede51b03ae5da052490f.tar.lz
nvim-treesitter-376a46ccecb8d839ca0cede51b03ae5da052490f.tar.xz
nvim-treesitter-376a46ccecb8d839ca0cede51b03ae5da052490f.tar.zst
nvim-treesitter-376a46ccecb8d839ca0cede51b03ae5da052490f.zip
feat(kdl): parser and queries (#7657)
Diffstat (limited to 'queries')
-rw-r--r--queries/kcl/folds.scm10
-rw-r--r--queries/kcl/highlights.scm201
-rw-r--r--queries/kcl/injections.scm26
3 files changed, 237 insertions, 0 deletions
diff --git a/queries/kcl/folds.scm b/queries/kcl/folds.scm
new file mode 100644
index 000000000..64e9e95d1
--- /dev/null
+++ b/queries/kcl/folds.scm
@@ -0,0 +1,10 @@
+[
+ (protocol_stmt)
+ (rule_stmt)
+ (schema_stmt)
+ (check_stmt)
+ (if_stmt)
+ (lambda_expr)
+ (config_expr)
+ (string)
+] @fold
diff --git a/queries/kcl/highlights.scm b/queries/kcl/highlights.scm
new file mode 100644
index 000000000..81b699ac2
--- /dev/null
+++ b/queries/kcl/highlights.scm
@@ -0,0 +1,201 @@
+(identifier) @variable
+
+(import_stmt
+ (dotted_name
+ (identifier) @module))
+
+(import_stmt
+ (dotted_name
+ (identifier) @module)
+ (identifier) @module)
+
+(basic_type) @type.builtin
+
+(schema_type
+ (dotted_name
+ (identifier) @type))
+
+(schema_type
+ (dotted_name
+ (identifier) @module
+ (identifier) @type))
+
+(schema_expr
+ (identifier) @type)
+
+(protocol_stmt
+ (identifier) @type)
+
+(rule_stmt
+ (identifier) @type)
+
+(schema_stmt
+ (identifier) @type)
+
+(lambda_expr
+ (typed_parameter
+ (identifier) @variable.parameter))
+
+(lambda_expr
+ (identifier) @variable.parameter)
+
+(selector_expr
+ (select_suffix
+ (identifier) @property))
+
+(comment) @comment @spell
+
+(string) @string
+
+(escape_sequence) @string.escape
+
+(schema_stmt
+ body: (block
+ .
+ (string
+ (string_content) @string.documentation)))
+
+(decorator
+ (identifier) @attribute)
+
+(call_expr
+ function: (identifier) @function)
+
+(call_expr
+ function: (selector_expr
+ (select_suffix
+ (identifier) @function)))
+
+(integer) @number
+
+(float) @number.float
+
+[
+ (true)
+ (false)
+] @boolean
+
+[
+ (none)
+ (undefined)
+] @constant.builtin
+
+"for" @keyword.repeat
+
+[
+ "elif"
+ "else"
+ "if"
+] @keyword.conditional
+
+"lambda" @keyword.function
+
+(quant_op) @keyword.operator
+
+[
+ "protocol"
+ "rule"
+ "schema"
+ "type"
+ "mixin"
+] @keyword.type
+
+"assert" @keyword.debug
+
+[
+ "as"
+ "import"
+] @keyword.import
+
+"check" @keyword
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
+
+[
+ ","
+ ":"
+ "."
+ "?."
+ "?:"
+ "?"
+] @punctuation.delimiter
+
+(interpolation
+ "${" @punctuation.special
+ "}" @punctuation.special)
+
+[
+ "+"
+ "-"
+ "*"
+ "**"
+ "/"
+ "//"
+ "%"
+ "<<"
+ ">>"
+ "&"
+ "|"
+ "^"
+ "<"
+ ">"
+ "~"
+ "<="
+ ">="
+ "=="
+ "!="
+ "="
+ "+="
+ "-="
+ "*="
+ "**="
+ "/="
+ "//="
+ "%="
+ "<<="
+ ">>="
+ "&="
+ "^="
+ "->"
+] @operator
+
+"@" @attribute
+
+[
+ "and"
+ "or"
+ "not"
+ "in"
+ "is"
+] @keyword.operator
+
+; second argument is a regex in all regex functions with at least two arguments
+(call_expr
+ function: (selector_expr
+ (identifier) @_regex)
+ arguments: (argument_list
+ (_)
+ .
+ (string
+ (string_content) @string.regexp))
+ (#eq? @_regex "regex"))
+
+; first argument is a regex in 'regex.compile' function
+(call_expr
+ function: (selector_expr
+ (identifier) @_regex
+ (select_suffix
+ (identifier) @_fn
+ (#eq? @_fn "compile")))
+ arguments: (argument_list
+ .
+ (string
+ (string_content) @string.regexp))
+ (#eq? @_regex "regex"))
diff --git a/queries/kcl/injections.scm b/queries/kcl/injections.scm
new file mode 100644
index 000000000..4e04e54d3
--- /dev/null
+++ b/queries/kcl/injections.scm
@@ -0,0 +1,26 @@
+(call_expr
+ function: (selector_expr
+ (identifier) @_regex)
+ arguments: (argument_list
+ (_)
+ .
+ (string
+ (string_content) @injection.content))
+ (#eq? @_regex "regex")
+ (#set! injection.language "regex"))
+
+(call_expr
+ function: (selector_expr
+ (identifier) @_regex
+ (select_suffix
+ (identifier) @_fn
+ (#eq? @_fn "compile")))
+ arguments: (argument_list
+ .
+ (string
+ (string_content) @injection.content))
+ (#eq? @_regex "regex")
+ (#set! injection.language "regex"))
+
+((comment) @injection.content
+ (#set! injection.language "comment"))