Add C3 language

This commit is contained in:
Christian Buttner 2025-04-29 15:49:51 +02:00
parent 3b308861a8
commit 59ec5968f8
6 changed files with 436 additions and 0 deletions

View file

@ -193,6 +193,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [bp](https://github.com/ambroisie/tree-sitter-bp) (maintained by @ambroisie) - [x] [bp](https://github.com/ambroisie/tree-sitter-bp) (maintained by @ambroisie)
- [x] [brightscript](https://github.com/ajdelcimmuto/tree-sitter-brightscript) (maintained by @ajdelcimmuto) - [x] [brightscript](https://github.com/ajdelcimmuto/tree-sitter-brightscript) (maintained by @ajdelcimmuto)
- [x] [c](https://github.com/tree-sitter/tree-sitter-c) (maintained by @amaanq) - [x] [c](https://github.com/tree-sitter/tree-sitter-c) (maintained by @amaanq)
- [x] [c3](https://github.com/c3lang/tree-sitter-c3) (maintained by @cbuttner)
- [x] [c_sharp](https://github.com/tree-sitter/tree-sitter-c-sharp) (maintained by @amaanq) - [x] [c_sharp](https://github.com/tree-sitter/tree-sitter-c-sharp) (maintained by @amaanq)
- [x] [caddy](https://github.com/opa-oz/tree-sitter-caddy) (maintained by @opa-oz) - [x] [caddy](https://github.com/opa-oz/tree-sitter-caddy) (maintained by @opa-oz)
- [x] [cairo](https://github.com/amaanq/tree-sitter-cairo) (maintained by @amaanq) - [x] [cairo](https://github.com/amaanq/tree-sitter-cairo) (maintained by @amaanq)

View file

@ -59,6 +59,9 @@
"c": { "c": {
"revision": "2a265d69a4caf57108a73ad2ed1e6922dd2f998c" "revision": "2a265d69a4caf57108a73ad2ed1e6922dd2f998c"
}, },
"c3": {
"revision": "0bc58398fdc9decefe1f24551bc022666d2a2d15"
},
"c_sharp": { "c_sharp": {
"revision": "b5eb5742f6a7e9438bee22ce8026d6b927be2cd7" "revision": "b5eb5742f6a7e9438bee22ce8026d6b927be2cd7"
}, },

View file

@ -232,6 +232,14 @@ list.c = {
maintainers = { "@amaanq" }, maintainers = { "@amaanq" },
} }
list.c3 = {
install_info = {
url = "https://github.com/c3lang/tree-sitter-c3",
files = { "src/parser.c", "src/scanner.c" },
},
maintainers = { "@cbuttner" },
}
list.c_sharp = { list.c_sharp = {
install_info = { install_info = {
url = "https://github.com/tree-sitter/tree-sitter-c-sharp", url = "https://github.com/tree-sitter/tree-sitter-c-sharp",

35
queries/c3/folds.scm Normal file
View file

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

384
queries/c3/highlights.scm Normal file
View file

@ -0,0 +1,384 @@
; Punctuation
[
"("
")"
"["
"]"
"{"
"}"
"[<"
">]"
] @punctuation.bracket
[
";"
","
":"
"::"
] @punctuation.delimiter
; Constant
(const_ident) @constant
[
"true"
"false"
] @boolean
"null" @constant.builtin
; Variable
[
(ident)
(ct_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
(arg
(param_path
(param_path_element
(ident) @variable.member))))
; 2) Parameter
(parameter
name: (_) @variable.parameter)
(call_invocation
(call_arg
name: (_) @variable.parameter))
(enum_param_declaration
(ident) @variable.parameter)
; Keyword (from `c3c --list-keywords`)
[
"asm"
"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" @keyword.import
"module" @keyword
[
"alias"
"attrdef"
"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)
(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) @constant.builtin
(#match? @constant.builtin "_*[A-Z][_A-Z0-9]*"))
; Type Property (from `c3c --list-type-properties`)
(type_access_expr
(access_ident
[
(ident)
"typeid"
] @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
(path_ident
(ident) @module))
(import_declaration
(path_ident
(ident) @module))
; Attribute
(attribute
name: (_) @attribute)
(attrdef_declaration
name: (_) @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)
(at_ident)
] @function.call)
(call_expr
function: (builtin) @function.builtin)
(call_expr
function: (module_ident_expr
ident: (_) @function.call))
(call_expr
function: (trailing_generic_expr
argument: (module_ident_expr
ident: (_) @function.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)))
; 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: (_) @markup.strong
(#any-of? @markup.strong "@param" "@return" "@deprecated" "@require" "@ensure" "@pure"))

View file

@ -0,0 +1,5 @@
([
(line_comment)
(block_comment)
] @injection.content
(#set! injection.language "comment"))