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:

local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
---@diagnostic disable-next-line: inject-field
parser_config.numbat = {
  install_info = {
	url = "https://github.com/irevoire/tree-sitter-numbat",
	files = { "src/parser.c", "src/scanner.c" },
	branch = "main",
	generate_requires_npm = false,
	requires_generate_from_grammar = false,
  },
  filetype = "numbat",
}
vim.filetype.add({
  extension = {
	nbt = "numbat",
  },
})
vim.treesitter.language.register("numbat", "numbat")

Then restart Neovim (or execute the above Lua code) and run :TSInstall numbat, which should download and install the parser.

Syntax Highlighting

The above adds basic tree-sitter parsing, but weโ€™re still missing highlights. To fix this:

  1. Find the nvim-treesitter\queries directory inside your nvim-data folder (probably ~\AppData\Local\nvim-data\lazy\nvim-treesitter) and make a new directory under there called numbat
  2. Download the numbat highlights.scm file from GitHub into that directory
  3. If there are more .scm files available on GitHub, download them too and put them in the same place
  4. 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.