Tree-sitter grammar for the MIPS assembly language.
![](https://private-user-images.githubusercontent.com/135001586/398930971-f5f2332e-72c8-40b0-b452-98d741cada66.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MjY1NzAsIm5iZiI6MTczOTYyNjI3MCwicGF0aCI6Ii8xMzUwMDE1ODYvMzk4OTMwOTcxLWY1ZjIzMzJlLTcyYzgtNDBiMC1iNDUyLTk4ZDc0MWNhZGE2Ni5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNVQxMzMxMTBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mNzkwNzA3M2YwMDA0NDI1ODZjNmM0ZGExZGRjMjBlNWVjZWM4NjFiNjQ2NGRkYTAxM2Y4MDJkM2ZlOTllZTUyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.C9Zyo52UghFbToIK7Me08GosX-NzvOJpchdY4gs3uMM)
First, run npm install
to install the tree-sitter cli
. Next, build the grammar using npm run build
, which generates the necessary parser files, or use it to parse a file with npm run parse $file
.
Install tree-sitter (e.g. nix-shell -p tree-sitter
).
Build the grammar using tree-sitter generate
and parse a file with tree-sitter parse $file
.
To use tree-sitter-mips in neovim, the plugin nvim-treesitter is required.
Installing the lastest grammar from this repo involves the following three steps:
- Update your Neovim config for nvim-treesitter to refer to tree-sitter-mips. Add this to your tree-sitter config in neovim:
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
parser_config.mips = {
install_info = {
url = 'https://github.com/omeyenburg/tree-sitter-mips', -- You can use a local path
branch = 'main',
files = { 'src/parser.c' },
generate_requires_npm = false,
requires_generate_from_grammar = false,
},
filetype = 'asm',
}
- Tree-sitter should automatically install tree-sitter-mips for you when you open a
.asm
file. If not, run:TSInstall mips
inside Neovim. - Copy the files from
./queries/
to the neovim config directory at$XDG_CONFIG_HOME/nvim/queries/mips/
- see the Adding queries section of the nvim-treesitter README. They are required to enable highlighting.
mkdir -p $XDG_CONFIG_HOME/nvim/queries/mips/
cp ./queries/* $XDG_CONFIG_HOME/nvim/queries/mips/
If you are looking for a more general grammar for assembly, check out tree-sitter-asm which supports features of other instruction sets, yet it lacks some specific features of MIPS.