aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/queries/c3
diff options
context:
space:
mode:
authorChristian Buttner <christian@cbuttner.de>2025-05-28 23:04:10 +0200
committerGitHub <noreply@github.com>2025-05-28 23:04:10 +0200
commitc59004f1e03e111099978932e86bb2f479b5ea73 (patch)
tree7082f695110ff123a8a34bf209c9a00fbd9ce130 /runtime/queries/c3
parentfix(just): do not restrict `@function.call` to explicit list (#7905) (diff)
downloadnvim-treesitter-c59004f1e03e111099978932e86bb2f479b5ea73.tar
nvim-treesitter-c59004f1e03e111099978932e86bb2f479b5ea73.tar.gz
nvim-treesitter-c59004f1e03e111099978932e86bb2f479b5ea73.tar.bz2
nvim-treesitter-c59004f1e03e111099978932e86bb2f479b5ea73.tar.lz
nvim-treesitter-c59004f1e03e111099978932e86bb2f479b5ea73.tar.xz
nvim-treesitter-c59004f1e03e111099978932e86bb2f479b5ea73.tar.zst
nvim-treesitter-c59004f1e03e111099978932e86bb2f479b5ea73.zip
feat: add c3 (#7891)
Diffstat (limited to 'runtime/queries/c3')
-rw-r--r--runtime/queries/c3/folds.scm35
-rw-r--r--runtime/queries/c3/highlights.scm408
-rw-r--r--runtime/queries/c3/indents.scm73
-rw-r--r--runtime/queries/c3/injections.scm5
4 files changed, 521 insertions, 0 deletions
diff --git a/runtime/queries/c3/folds.scm b/runtime/queries/c3/folds.scm
new file mode 100644
index 000000000..0776e7678
--- /dev/null
+++ b/runtime/queries/c3/folds.scm
@@ -0,0 +1,35 @@
+[
+ ; Top-level declarations
+ (bitstruct_declaration)
+ (enum_declaration)
+ (faultdef_declaration)
+ (func_definition)
+ (import_declaration)+
+ (interface_declaration)
+ (macro_declaration)
+ (struct_declaration)
+ ; Statements
+ (asm_block_stmt)
+ (case_stmt)
+ (defer_stmt)
+ (do_stmt)
+ (for_stmt)
+ (foreach_stmt)
+ (if_stmt)
+ (switch_stmt)
+ (while_stmt)
+ (ct_for_stmt)
+ (ct_foreach_stmt)
+ (ct_switch_stmt)
+ (ct_case_stmt)
+ (ct_if_stmt)
+ (ct_else_stmt)
+ ; Comments
+ (block_comment)
+ (doc_comment)
+ ; Initializer list
+ (initializer_list)
+] @fold
+
+(compound_stmt
+ (compound_stmt) @fold)
diff --git a/runtime/queries/c3/highlights.scm b/runtime/queries/c3/highlights.scm
new file mode 100644
index 000000000..1f02496b8
--- /dev/null
+++ b/runtime/queries/c3/highlights.scm
@@ -0,0 +1,408 @@
+; Punctuation
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+ "[<"
+ ">]"
+] @punctuation.bracket
+
+[
+ ";"
+ ","
+ ":"
+ "::"
+] @punctuation.delimiter
+
+; Constant
+(const_ident) @constant
+
+[
+ "true"
+ "false"
+] @boolean
+
+"null" @constant.builtin
+
+; Variable
+[
+ (ident)
+ (ct_ident)
+ (hash_ident)
+] @variable
+
+; 1) Member
+(field_expr
+ field: (access_ident
+ (ident) @variable.member))
+
+(struct_member_declaration
+ (ident) @variable.member)
+
+(struct_member_declaration
+ (identifier_list
+ (ident) @variable.member))
+
+(bitstruct_member_declaration
+ (ident) @variable.member)
+
+(initializer_list
+ (initializer_element
+ (param_path
+ (param_path_element
+ (access_ident
+ (ident) @variable.member)))))
+
+; 2) Parameter
+(param
+ name: (_) @variable.parameter)
+
+(trailing_block_param
+ (at_ident) @variable.parameter)
+
+(call_arg_list
+ (call_arg
+ name: (_) @variable.parameter))
+
+(enum_param
+ (ident) @variable.parameter)
+
+; Keyword (from `c3c --list-keywords`)
+[
+ "alias"
+ "asm"
+ "attrdef"
+ "catch"
+ "defer"
+ "try"
+ "var"
+] @keyword
+
+[
+ "$alignof"
+ "$assert"
+ "$assignable"
+ "$case"
+ "$default"
+ "$defined"
+ "$echo"
+ "$else"
+ "$embed"
+ "$endfor"
+ "$endforeach"
+ "$endif"
+ "$endswitch"
+ "$eval"
+ "$evaltype"
+ "$error"
+ "$exec"
+ "$extnameof"
+ "$feature"
+ "$for"
+ "$foreach"
+ "$if"
+ "$include"
+ "$is_const"
+ "$nameof"
+ "$offsetof"
+ "$qnameof"
+ "$sizeof"
+ "$stringify"
+ "$switch"
+ "$typefrom"
+ "$typeof"
+ "$vacount"
+ "$vatype"
+ "$vaconst"
+ "$vaarg"
+ "$vaexpr"
+ "$vasplat"
+] @keyword.directive
+
+"assert" @keyword.debug
+
+"fn" @keyword.function
+
+"macro" @keyword.function
+
+"return" @keyword.return
+
+[
+ "import"
+ "module"
+] @keyword.import
+
+[
+ "bitstruct"
+ "enum"
+ "faultdef"
+ "interface"
+ "struct"
+ "typedef"
+ "union"
+] @keyword.type
+
+[
+ "case"
+ "default"
+ "else"
+ "if"
+ "nextcase"
+ "switch"
+] @keyword.conditional
+
+[
+ "break"
+ "continue"
+ "do"
+ "for"
+ "foreach"
+ "foreach_r"
+ "while"
+] @keyword.repeat
+
+[
+ "const"
+ "extern"
+ "inline"
+ "static"
+ "tlocal"
+] @keyword.modifier
+
+; Operator (from `c3c --list-operators`)
+[
+ "&"
+ "!"
+ "~"
+ "|"
+ "^"
+ "="
+ ">"
+ "/"
+ "."
+ "<"
+ "-"
+ "%"
+ "+"
+ "?"
+ "*"
+ "&&"
+ "!!"
+ "&="
+ "|="
+ "^="
+ "/="
+ ".."
+ "?:"
+ "=="
+ ">="
+ "=>"
+ "<="
+ "-="
+ "--"
+ "%="
+ "*="
+ "!="
+ "||"
+ "+="
+ "++"
+ "??"
+ "<<"
+ ">>"
+ "..."
+ "<<="
+ ">>="
+ "&&&"
+ "+++"
+ "|||"
+] @operator
+
+(range_expr
+ ":" @operator)
+
+(foreach_cond
+ ":" @operator)
+
+(ct_foreach_cond
+ ":" @operator)
+
+(ternary_expr
+ [
+ "?"
+ ":"
+ ] @keyword.conditional.ternary)
+
+(elvis_orelse_expr
+ [
+ "?:"
+ "??"
+ ] @keyword.conditional.ternary)
+
+; Literal
+(integer_literal) @number
+
+(real_literal) @number.float
+
+(char_literal) @character
+
+(bytes_literal) @number
+
+; String
+(string_literal) @string
+
+(raw_string_literal) @string
+
+; Escape Sequence
+(escape_sequence) @string.escape
+
+; Builtin (constants)
+(builtin_const) @constant.builtin
+
+; Type Property (from `c3c --list-type-properties`)
+(type_access_expr
+ (access_ident
+ (ident) @variable.builtin
+ (#any-of? @variable.builtin
+ "alignof" "associated" "elements" "extnameof" "from_ordinal" "get" "inf" "is_eq" "is_ordered"
+ "is_substruct" "len" "lookup" "lookup_field" "max" "membersof" "methodsof" "min" "nan" "inner"
+ "kindof" "names" "nameof" "params" "paramsof" "parentof" "qnameof" "returns" "sizeof" "tagof"
+ "has_tagof" "values" "typeid")))
+
+; Label
+[
+ (label)
+ (label_target)
+] @label
+
+; Module
+(module_resolution
+ (ident) @module)
+
+(module_declaration
+ (path_ident
+ (ident) @module))
+
+(import_declaration
+ (path_ident
+ (ident) @module))
+
+; Attribute
+(attribute
+ name: (at_ident) @attribute)
+
+(at_type_ident) @attribute
+
+(call_inline_attributes
+ (at_ident) @attribute)
+
+(asm_block_stmt
+ (at_ident) @attribute)
+
+; Type
+[
+ (type_ident)
+ (ct_type_ident)
+] @type
+
+(base_type_name) @type.builtin
+
+; Function Definition
+(func_header
+ name: (_) @function)
+
+(func_header
+ method_type: (_)
+ name: (_) @function.method)
+
+(macro_header
+ name: (_) @function)
+
+(macro_header
+ method_type: (_)
+ name: (_) @function.method)
+
+; Function Call
+(call_expr
+ function: (ident_expr
+ [
+ (ident)
+ (at_ident)
+ ] @function.call))
+
+(call_expr
+ function: (trailing_generic_expr
+ argument: (ident_expr
+ [
+ (ident)
+ (at_ident)
+ ] @function.call)))
+
+; Method call
+(call_expr
+ function: (field_expr
+ field: (access_ident
+ [
+ (ident)
+ (at_ident)
+ ] @function.method.call)))
+
+; Method on type
+(call_expr
+ function: (type_access_expr
+ field: (access_ident
+ [
+ (ident)
+ (at_ident)
+ ] @function.method.call)))
+
+; Builtin call
+(call_expr
+ function: (builtin) @function.builtin)
+
+; Asm
+(asm_instr
+ [
+ (ident)
+ "int"
+ ] @function.builtin)
+
+(asm_expr
+ [
+ (ct_ident)
+ (ct_const_ident)
+ ] @variable.builtin)
+
+; Comment
+[
+ (line_comment)
+ (block_comment)
+] @comment @spell
+
+(doc_comment) @comment.documentation
+
+(doc_comment_text) @spell
+
+(doc_comment_contract
+ name: (_) @attribute)
+
+(doc_comment_contract
+ parameter: [
+ (ident)
+ (ct_ident)
+ (hash_ident)
+ ] @variable.parameter
+ (#set! priority 110))
+
+(doc_comment_contract
+ [
+ ":"
+ "?"
+ ] @comment.documentation
+ (#set! priority 110))
+
+(doc_comment_contract
+ description: (_) @comment.documentation
+ (#set! priority 110))
diff --git a/runtime/queries/c3/indents.scm b/runtime/queries/c3/indents.scm
new file mode 100644
index 000000000..61758ce32
--- /dev/null
+++ b/runtime/queries/c3/indents.scm
@@ -0,0 +1,73 @@
+[
+ (compound_stmt)
+ (initializer_list)
+ (implies_body)
+ (struct_body)
+ (bitstruct_body)
+ (enum_body)
+ (interface_body)
+ (switch_body)
+ (ct_if_stmt)
+ (ct_for_stmt)
+ (ct_foreach_stmt)
+ (ct_switch_stmt)
+] @indent.begin
+
+([
+ (case_stmt)
+ (default_stmt)
+ (ct_case_stmt)
+] @indent.begin
+ (#set! indent.immediate 1))
+
+(expr_stmt
+ ";" @indent.end) @indent.begin
+
+(declaration
+ ";" @indent.end) @indent.begin
+
+(const_declaration
+ ";" @indent.end) @indent.begin
+
+(return_stmt
+ ";" @indent.end) @indent.begin
+
+(faultdef_declaration
+ ";" @indent.end) @indent.begin
+
+(macro_func_body
+ ";" @indent.end)
+
+[
+ ")"
+ "}"
+ "$endfor"
+ "$endforeach"
+ "$endswitch"
+ "$endif"
+] @indent.branch @indent.end
+
+"$else" @indent.branch
+
+([
+ (func_param_list)
+ (macro_param_list)
+ (enum_param_list)
+ (attribute_param_list)
+ (call_arg_list)
+ (paren_cond)
+ (for_cond)
+ (foreach_cond)
+ (paren_expr)
+] @indent.align
+ (#set! indent.open_delimiter "(")
+ (#set! indent.close_delimiter ")"))
+
+[
+ (block_comment)
+ (doc_comment)
+ (raw_string_literal)
+ (bytes_literal)
+] @indent.auto
+
+(string_literal) @indent.ignore
diff --git a/runtime/queries/c3/injections.scm b/runtime/queries/c3/injections.scm
new file mode 100644
index 000000000..3cd6aac8e
--- /dev/null
+++ b/runtime/queries/c3/injections.scm
@@ -0,0 +1,5 @@
+([
+ (line_comment)
+ (block_comment)
+] @injection.content
+ (#set! injection.language "comment"))