This repository contains the Tree-sitter grammar and highlighting configuration for Koala, a toy programming language designed for learning and experimenting with interpreters and tooling.
✨ You can try Koala here: Koala playground
I've been fascinated by the tooling ecosystem that Neovim uses, but I never really felt motivated enough to write a tree-sitter grammar or LSP for an existing language. After working on Koala though, I found this motivation.
Primarily because, even though I was just writing .kol files for testing purposes, editing the file on the left doesn't feel like you're writing code. It just doesn't scratch that itch. So I wrote this grammar to enable the highlighting you see on the file on the right:
- Syntax tree generation
- Syntax highlighting for keywords, operators, literals, comments, and more
- Smart indentation on newline (C-like behavior)
Follow the steps below to get tree-sitter support for Koala in Neovim:
git clone https://github.com/hsnavihS/tree-sitter-koala.gitAdd the following lines to your init.lua to register the Koala grammar with Neovim’s Tree-sitter plugin:
require('nvim-treesitter.parsers').get_parser_configs().koala = {
install_info = {
url = 'path/to/cloned/repo/tree-sitter-koala',
files = { 'src/parser.c' },
},
filetype = 'koala',
}
vim.filetype.add {
extension = {
kol = 'koala',
},
}This registers the grammar and maps .kol files to the koala filetype.
Tree-sitter looks for highlight and indent queries inside the Neovim runtime. You can link them like this:
mkdir -p ~/.config/nvim/queries/koala
# Link highlight and indent queries
ln -s path/to/cloned/repo/tree-sitter-koala/queries/highlights.scm ~/.config/nvim/queries/koala/highlights.scm
ln -s path/to/cloned/repo/tree-sitter-koala/queries/indents.scm ~/.config/nvim/queries/koala/indents.scmRestart Neovim, open a .kol file and you should see syntax highlighting in action!
Not required if you don't plan on tinkering with the defined grammar. But if you do, you’ll need the tree-sitter CLI to generate the parser:
npm install -g tree-sitter-cliThen, once you're done making changes in the grammar, run this command at the root:
tree-sitter generateThis creates src/parser.c (and some other files) using grammar.js.
These things would be cool to have, but since this is just a toy language, I think these would be overkill and I'd rather work on the LSP
- Support for editors that work on TextMate grammars for highlighting (VSCode being the major one I wanted to have support for)
- Add support for more queries like folding, and locals
- Tests for every rule in the grammar, and a CI pipeline to run these on every push
Tree-sitter wouldn't pick up the changes I made to the grammar because of a couple of cached files. I had to remove these manually every time to see updates:
cd .local/share/nvim && rm ./lazy/nvim-treesitter/parser/koala.so && rm ./lazy/nvim-treesitter/parser-info/koala.revision:Inspect and :InspectTree are really cool commands, I found being able to look at the generated AST really helpful.

