aboutsummaryrefslogtreecommitdiffstats
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
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)
-rw-r--r--lockfile.json3
-rw-r--r--lua/nvim-treesitter/parsers.lua8
-rw-r--r--queries/kcl/folds.scm10
-rw-r--r--queries/kcl/highlights.scm201
-rw-r--r--queries/kcl/injections.scm26
5 files changed, 248 insertions, 0 deletions
diff --git a/lockfile.json b/lockfile.json
index 47f14be90..ce2f67e84 100644
--- a/lockfile.json
+++ b/lockfile.json
@@ -410,6 +410,9 @@
"just": {
"revision": "bb0c898a80644de438e6efe5d88d30bf092935cd"
},
+ "kcl": {
+ "revision": "b0b2eb38009e04035a6e266c7e11e541f3caab7c"
+ },
"kconfig": {
"revision": "9ac99fe4c0c27a35dc6f757cef534c646e944881"
},
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index f1b03f473..8a3acf2c6 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -1211,6 +1211,14 @@ list.just = {
maintainers = { "@Hubro" },
}
+list.kcl = {
+ install_info = {
+ url = "https://github.com/kcl-lang/tree-sitter-kcl",
+ files = { "src/parser.c", "src/scanner.c" },
+ },
+ maintainers = { "@bertbaron" },
+}
+
list.kconfig = {
install_info = {
url = "https://github.com/amaanq/tree-sitter-kconfig",
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"))