diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index af9071ee..f5d07240 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -19,6 +19,7 @@ | bovex | ✓ | | | | ✓ | | | c | ✓ | ✓ | ✓ | ✓ | ✓ | `clangd` | | c-sharp | ✓ | ✓ | | ✓ | | `OmniSharp`, `csharp-ls` | +| c3 | ✓ | | | | | `c3-lsp` | | cabal | | | | | | `haskell-language-server-wrapper` | | caddyfile | ✓ | ✓ | ✓ | | | | | cairo | ✓ | ✓ | ✓ | | | `cairo-language-server` | diff --git a/languages.toml b/languages.toml index eff1f9f5..35fb91a9 100644 --- a/languages.toml +++ b/languages.toml @@ -20,6 +20,7 @@ beancount-language-server = { command = "beancount-language-server" } bicep-langserver = { command = "bicep-langserver" } bitbake-language-server = { command = "bitbake-language-server" } buf = { command = "buf", args = ["lsp", "serve", "--timeout", "0"] } +c3-lsp = { command = "c3-lsp" } cairo-language-server = { command = "cairo-language-server", args = [] } circom-lsp = { command = "circom-lsp" } cl-lsp = { command = "cl-lsp" } @@ -777,6 +778,47 @@ args = { processId = "{0}" } name = "c-sharp" source = { git = "https://github.com/tree-sitter/tree-sitter-c-sharp", rev = "b5eb5742f6a7e9438bee22ce8026d6b927be2cd7" } +[[language]] +name = "c3" +scope = "source.c3" +injection-regex = "c3" +file-types = [ "c3", "c3i", "c3t" ] +roots = [ "project.json" ] +comment-token = "//" +block-comment-tokens = [ + { start = "/*", end = "*/" }, + { start = "<*", end = "*>" }, +] +indent = { tab-width = 4, unit = "\t" } +language-servers = [ "c3-lsp" ] + +[language.debugger] +name = "lldb-dap" +transport = "stdio" +command = "lldb-dap" + +[[language.debugger.templates]] +name = "binary" +request = "launch" +completion = [ { name = "binary", completion = "filename" } ] +args = { console = "internalConsole", program = "{0}" } + +[[language.debugger.templates]] +name = "attach" +request = "attach" +completion = [ "pid" ] +args = { console = "internalConsole", pid = "{0}" } + +[[language.debugger.templates]] +name = "gdbserver attach" +request = "attach" +completion = [ { name = "lldb connect url", default = "connect://localhost:3333" }, { name = "file", completion = "filename" }, "pid" ] +args = { console = "internalConsole", attachCommands = [ "platform select remote-gdb-server", "platform connect {0}", "file {1}", "attach {2}" ] } + +[[grammar]] +name = "c3" +source = { git = "https://github.com/c3lang/tree-sitter-c3", rev = "15d3502510af0a6c888c663ec8d6aca8791216ce" } + [[language]] name = "cel" scope = "source.cel" diff --git a/runtime/queries/c3/highlights.scm b/runtime/queries/c3/highlights.scm new file mode 100644 index 00000000..0bd71409 --- /dev/null +++ b/runtime/queries/c3/highlights.scm @@ -0,0 +1,412 @@ +; Punctuation +[ + "(" + ")" + "[" + "]" + "{" + "}" + "[<" + ">]" +] @punctuation.bracket + +[ + ";" + "," + ":" + "::" +] @punctuation.delimiter + +; Constant +(const_ident) @constant + +[ + "true" + "false" +] @constant.builtin.boolean + +"null" @constant.builtin + +; Variable +[ + (ident) + (ct_ident) + (hash_ident) +] @variable + +; 1) Member +(field_expr + field: (access_ident + (ident) @variable.other.member)) + +(struct_member_declaration + (ident) @variable.other.member) + +(struct_member_declaration + (identifier_list + (ident) @variable.other.member)) + +(bitstruct_member_declaration + (ident) @variable.other.member) + +(initializer_list + (initializer_element + (param_path + (param_path_element + (access_ident + (ident) @variable.other.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" + "$kindof" + "$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.control.return + +[ + "import" + "module" +] @keyword.control.import + +[ + "bitstruct" + "enum" + "faultdef" + "interface" + "struct" + "typedef" + "union" +] @keyword.storage.type + +[ + "case" + "default" + "else" + "if" + "nextcase" + "switch" +] @keyword.control.conditional + +[ + "break" + "continue" + "do" + "for" + "foreach" + "foreach_r" + "while" +] @keyword.control.repeat + +[ + "const" + "extern" + "inline" + "static" + "tlocal" +] @keyword.storage.modifier + +; Operator (from `c3c --list-operators`) +[ + "&" + "!" + "~" + "|" + "^" + "=" + ">" + "/" + "." + "<" + "-" + "%" + "+" + "?" + "*" + "&&" + "!!" + "&=" + "|=" + "^=" + "/=" + ".." + "?:" + "==" + ">=" + "=>" + "<=" + "-=" + "--" + "%=" + "*=" + "!=" + "||" + "+=" + "++" + "??" + "<<" + ">>" + "..." + "<<=" + ">>=" + "&&&" + "+++" + "|||" + "???" + "+++=" +] @operator + +(range_expr + ":" @operator) + +(foreach_cond + ":" @operator) + +(ct_foreach_cond + ":" @operator) + +(ternary_expr + [ + "?" + "???" + ":" + ] @keyword.control.conditional.ternary) + +(elvis_orelse_expr + [ + "?:" + "??" + ] @keyword.control.conditional.ternary) + +; Literal +(integer_literal) @constant.numeric.integer + +(real_literal) @constant.numeric.float + +(char_literal) @constant.character + +(bytes_literal) @constant.numeric + +; String +(string_literal) @string + +(raw_string_literal) @string + +; Escape Sequence +(escape_sequence) @constant.character.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" "set" + "tagof" "has_tagof" "values" "typeid"))) + +; Label +(label + (const_ident) @label) + +(label_target + (const_ident) @label) + +; Module +(module_resolution + (ident) @namespace) + +(module_declaration + (path_ident + (ident) @namespace)) + +(import_path + (path_ident + (ident) @namespace)) + +; Attribute +(attribute + name: (at_ident) @attribute) + +(at_type_ident) @attribute + +(call_inline_attributes + (at_ident) @attribute) + +(type_suffix + (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_expr + function: (trailing_generic_expr + argument: (ident_expr + [ + (ident) + (at_ident) + ] @function))) + +; Method call +(call_expr + function: (field_expr + field: (access_ident + [ + (ident) + (at_ident) + ] @function))) + +; Method on type +(call_expr + function: (type_access_expr + field: (access_ident + [ + (ident) + (at_ident) + ] @function))) + +; 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) @comment.line +(block_comment) @comment.block +(doc_comment) @comment.block.documentation + +(doc_comment_contract + name: (_) @attribute) + +(doc_comment_contract + parameter: [ + (ident) + (ct_ident) + (hash_ident) + ] @variable.parameter) + +(doc_comment_contract + [ + ":" + "?" + ] @comment.block.documentation) + +(doc_comment_contract + description: (string_expr + [ + (string_literal) + (raw_string_literal) + ] @comment.block.documentation)) diff --git a/runtime/queries/c3/injections.scm b/runtime/queries/c3/injections.scm new file mode 100644 index 00000000..7cf9cdc5 --- /dev/null +++ b/runtime/queries/c3/injections.scm @@ -0,0 +1,5 @@ +([ + (line_comment) + (block_comment) +] @injection.content + (#set! injection.language "comment")) \ No newline at end of file