This is a complete implementation of the current C3 grammar for tree-sitter, usable for syntax highlighting, indentation, folding, code analysis, header/doc generation, and more.
The latest version supports C3 0.6.5 and is not compatible with C3 < 0.6.4.
Check out the tree-sitter-c3 playground here: https://c3lang.github.io/tree-sitter-c3/
- This is in some cases a less strict version of the "true" grammar.
- Tree structure and node naming is still subject to change.
https://github.com/c3lang/c3-ts-mode
- Install the nvim-treesitter plugin
- Add the following to your
init.lua
:
vim.filetype.add({
extension = {
c3 = "c3",
c3i = "c3",
c3t = "c3",
},
})
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.c3 = {
install_info = {
url = "https://github.com/c3lang/tree-sitter-c3",
files = {"src/parser.c", "src/scanner.c"},
branch = "main",
},
}
- Run
:TSInstall c3
- Follow the steps for adding queries to install
queries/highlights.scm
.
For example, copytree-sitter-c3/queries/*
to~/.config/nvim/queries/c3/
(replace~/.config/nvim
with your runtime path), such that you end up with the highlights file at~/.config/nvim/queries/c3/highlights.scm
.
Right now there is a proposal for adding c3 language support, but there is still no support. To get started with c3 in helix editor:
- Add this to
languages.toml
:
[[grammar]]
name = "c3"
[grammar.source]
git = "https://github.com/c3lang/tree-sitter-c3.git"
rev = "main"
[[language]]
name = "c3"
scope = "source.c3"
file-types = ["c3", "c3i"]
roots = ["project.json"]
comment-token = "//"
language-servers = ["c3-lsp"] #if you want LSP support
[language.block-comment-tokens]
end = "*/"
start = "/*"
#LSP support
[language-server.c3-lsp]
command = "c3-lsp"
- Run
hx -g fetch
, which will fetch all the grammars (you can exclude grammars withuse-grammars.only
oruse-grammars.except
inlanguages.toml
). - Run
hx -g build
(you need to havegcc
/clang
installed on your system and possiblygnumake
). - Add queries from
$XDG_CONFIG_HOME/helix/runtime/grammars/sources/c3/queries
to$XDG_CONFIG_HOME/helix/runtime/queries/c3
:
mkdir $XDG_CONFIG_HOME/helix/runtime/queries
cp -r $XDG_CONFIG_HOME/helix/runtime/grammars/sources/c3/queries $XDG_CONFIG_HOME/helix/runtime/queries/c3
- Now you can write
c3
in Helix Editor with highlighting and LSP support!