Numbat is a statically typed programming language for scientific computations with first class support for physical dimensions and units.
Requirements
tree-sitter-cli must be installed and available on the path. This can be installed using npm -g install tree-sitter-cli or volta install tree-sitter-cli.
Itโs also assumed that nvim-treesitter is already set up and working in Neovim for general tree-sitter support of other common languages, and weโre just extending it to work with Numbat.
Basic Setup
In init.lua or somewhere else in nvim-treesitter config, add the following lines:
Then restart Neovim (or execute the above Lua code) and run :TSInstall numbat, which should download and install the parser.
lazy.nvim setup
Put the above parser config code into an opts function of the plugin spec for nvim-treesitter, and also add an entry to the ensure_installed table.
{ "nvim-treesitter/nvim-treesitter", opts = function(_, opts) -- [insert all of the parser_config code from above right here] if type(opts.ensure_installed) == "table" then vim.list_extend(opts.ensure_installed, { "numbat" }) end end}
Syntax Highlighting
The above adds basic tree-sitter parsing, but weโre still missing highlights. To fix this:
Find the nvim-treesitter\queries directory inside the nvim-data folder (probably ~\AppData\Local\nvim-data\lazy\nvim-treesitter) and make a new directory under there called numbat
Download the numbat highlights.scm file from GitHub into that directory
If there are more .scm files available on GitHub, download them too and put them in the same place
You may need to restart Neovim again
To test if installation was successful, open any .nbt file and:
running the command :set filetype should return filetype=numbat
:InspectTree should show an abstract syntax tree
you should see syntax highlighting
Bonus Tip
You can visually select any Numbat code in Neovim and run :'<,'>!numbat to pipe it to numbat and replace the contents in the buffer with the result. If the whole buffer is Numbat code, run :%!numbat to do the same. Note that this works in any file, not just .nbt files.