Skip to content

c3lang/tree-sitter-c3

Repository files navigation

tree-sitter-c3

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.

Playground

Check out the tree-sitter-c3 playground here: https://c3lang.github.io/tree-sitter-c3/

Notes

  • This is in some cases a less strict version of the "true" grammar.
  • Tree structure and node naming is still subject to change.

Editors

Emacs 29+

https://github.com/c3lang/c3-ts-mode

Neovim

  1. Install the nvim-treesitter plugin
  2. 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",
  },
}
  1. Run :TSInstall c3
  2. Follow the steps for adding queries to install queries/highlights.scm.
    For example, copy tree-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.

Helix

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:

  1. 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"
  1. Run hx -g fetch, which will fetch all the grammars (you can exclude grammars with use-grammars.only or use-grammars.except in languages.toml).
  2. Run hx -g build (you need to have gcc/clang installed on your system and possibly gnumake).
  3. 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
  1. Now you can write c3 in Helix Editor with highlighting and LSP support!

About

C3 grammar for tree-sitter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published