Add A Language To The Tree-sitter CLi Tool
I'm working on the Tree-sitter^ts^^ parser and syntax highlighter for Neopolitan^neo^^. 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
{
"parser-directories": [
"/Users/alan/workshop"
],
"other_config_stuff": {}
}
Running The Example
With that in place, this works and highlights the HTML properly
tree-sitter highlight example.neo
Reference
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