This is fork of https://github.com/emacs-tree-sitter/tree-sitter-langs that includes more parsers.
This is a convenient language bundle for the Emacs package tree-sitter. It serves as an interim distribution mechanism, until tree-sitter
is widespread enough for language-specific major modes to incorporate its functionalities.
For each supported language, this package provides:
- Pre-compiled grammar binaries for 3 major platforms: macOS, Linux and Windows, on x86_64. In the future,
tree-sitter-langs
may provide tooling for major modes to do this on their own. - An optional
highlights.scm
file that provides highlighting patterns. This is mainly intended for major modes that are not aware oftree-sitter
. A language major mode that wants to usetree-sitter
for syntax highlighting should instead provide the query patterns on its own, using the mechanisms defined by tree-sitter-hl. - Optional query patterns for other minor modes that provide high-level functionalities on top of
tree-sitter
, such as code folding, evil text objects… As with highlighting patterns, major modes that are directly aware oftree-sitter
should provide the query patterns on their own.
Highlighting query patterns for a language are in the file queries/<lang>/highlights.scm
. Most of them are intentionally different from those from upstream repositories, which are more geared towards GitHub's use cases. We try to be more consistent with Emacs's existing conventions. (For some languages, this is WIP, so their patterns may look similar to upstream's.)
In general, try to follow what the docstrings of treesit-face-
faces say. Most importantly:
- Definitions and uses should be differentiated:
@function
vs.@function.call
.@method
vs.@method.call
.@type.parameter
vs.@type.argument
.
@variable
and@variable.parameter
should be applied only to declarations/definitions/bindings/mutations (writes), not usage (reads).- Special faces should have high priority (placed earlier in the pattern list):
@function.macro
,@type.builtin
,@variable.special
. - Patterns whose internals may be highlighted should have low priority (placed towards the end). Example: strings with interpolation.
Some languages are associated with multiple major modes. Mode-specific highlighting patterns are provided by the files queries/<lang>/highlights.<major-mode>.scm
. These are combined with the base highlighting patterns in queries/<lang>/highlights.scm
, but have higher precedence.
- Install NodeJS. It is needed to generate the grammar code from the JavaScript DSL. The recommended tool to manage NodeJS is volta.
- Install tree-sitter CLI tool. (Its binary can also be downloaded directly from GitHub.)
To build a specific language's grammar, run script/compile
. (See the list of registered languages in treesit-langs-source-alist
.) For example:
script/compile rust
To build all registered languages, and creating the bundle:
script/compile all
- Add a new entry in
treesit-langs-source-alist
andgrammars
. The entry is in the format of(lang :url <git-url> :rev <revision> :src <src-dir>)
. - Add the
(major-mode . language)
to thetreesit-major-mode-language-alist
- Add the highlighting rules to the
queries/<lang>/highlights.scm