feat(kdl): parser and queries (#7657)

This commit is contained in:
Bert Baron 2025-02-27 09:54:26 +01:00 committed by GitHub
parent 28f76678ca
commit 376a46ccec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 248 additions and 0 deletions

View file

@ -410,6 +410,9 @@
"just": {
"revision": "bb0c898a80644de438e6efe5d88d30bf092935cd"
},
"kcl": {
"revision": "b0b2eb38009e04035a6e266c7e11e541f3caab7c"
},
"kconfig": {
"revision": "9ac99fe4c0c27a35dc6f757cef534c646e944881"
},

View file

@ -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",

10
queries/kcl/folds.scm Normal file
View file

@ -0,0 +1,10 @@
[
(protocol_stmt)
(rule_stmt)
(schema_stmt)
(check_stmt)
(if_stmt)
(lambda_expr)
(config_expr)
(string)
] @fold

201
queries/kcl/highlights.scm Normal file
View file

@ -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"))

View file

@ -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"))