Add A Language To The Tree-sitter CLi Tool
I'm working on the Tree-sitterts parser and syntax highlighter for Neopolitanneo. One feature of the format is the ability to embed other languages. It took me a while to figure out that in order for the injected langauges to highlight properly I had to install each language for the CLI tool individually.
I did this in my tree-sitter config.json file which is here on my mac:
~/Library/Application Support/tree-sitter/config.json
Installation
Installation took two steps
- Clone the repo for the desired language
-
Update
parser-directories
array in the config.json file to add the parent directory above the repo
For example, I installed the HTML language parser/highlighter in my ~/workshop directory with:
cd ~/workshop
git clone git@github.com:tree-sitter/tree-sitter-html.git
Then I added this
Running The Example
With that in place, this works and highlights the HTML properly
tree-sitter highlight example.neo
References
My mardkdown-like plain-text file format
A parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited
The HTML language parser/highlighter repo for Tree-sitter