Skip to content

omeyenburg/tree-sitter-mips

Repository files navigation

tree-sitter-mips

Tree-sitter grammar for the MIPS assembly language.

Getting started

Building with npm

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.

Building without npm

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.

Integration in Neovim

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:

  1. 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',
}
  1. Tree-sitter should automatically install tree-sitter-mips for you when you open a .asm file. If not, run :TSInstall mips inside Neovim.
  2. 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/

Alternatives

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.

Further resources

About

MIPS assembly grammar for tree-sitter

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published