# tree-sitter-mips
A [tree-sitter](https://github.com/tree-sitter/tree-sitter) parser for the MIPS assembly language.
[](https://github.com/omeyenburg/tree-sitter-mips/actions/workflows/ci.yml)
[](https://crates.io/crates/tree-sitter-mips)
[](https://www.npmjs.com/package/tree-sitter-mips)
[](https://pypi.org/project/tree-sitter-mips)

## Integration in NeoVim
To use `tree-sitter-mips` in NeoVim, the plugin [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) is required.
>[!IMPORTANT]
> This will **only** work on the **[master branch of nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)** and not on the **main branch**!
1. Add this to your `nvim-treesitter` config:
```lua
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
parser_config.mips = {
install_info = {
url = 'https://github.com/omeyenburg/tree-sitter-mips',
branch = 'main',
files = { 'src/parser.c', 'src/scanner.c' },
generate_requires_npm = false,
requires_generate_from_grammar = false,
},
filetype = { 'asm', 'vmasm' },
}
```
2. Run `:TSInstall mips` to install the parser.
3. Copy the queries to enable highlighting. See [Adding queries](https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#adding-queries) for more information.
<details>
<summary>Unix</summary>
```sh
mkdir -p "$XDG_CONFIG_HOME/nvim/queries/mips"
curl -L -o "$XDG_CONFIG_HOME/nvim/queries/mips/highlights.scm" https://raw.githubusercontent.com/omeyenburg/tree-sitter-mips/main/queries/highlights.scm
curl -L -o "$XDG_CONFIG_HOME/nvim/queries/mips/indents.scm" https://raw.githubusercontent.com/omeyenburg/tree-sitter-mips/main/queries/indents.scm
```
</details>
<details>
<summary>Windows (cmd.exe)</summary>
```sh
mkdir "%LOCALAPPDATA%\nvim\queries\mips"
curl -L -o "%LOCALAPPDATA%\nvim\queries\mips\highlights.scm" https://raw.githubusercontent.com/omeyenburg/tree-sitter-mips/main/queries/highlights.scm
curl -L -o "%LOCALAPPDATA%\nvim\queries\mips\indents.scm" https://raw.githubusercontent.com/omeyenburg/tree-sitter-mips/main/queries/indents.scm
```
</details>
Alternative: If you are looking for a more general grammar for assembly, check out [tree-sitter-asm](https://github.com/RubixDev/tree-sitter-asm) which supports features of other instruction sets, yet it lacks some specific features of MIPS.
## Language integration
### Javascript
Install `tree-sitter` and `tree-sitter-mips`:
```sh
npm install tree-sitter@^0.25.0 tree-sitter-mips
```
Or using `bun` (or `yarn` or `pnpm`):
```sh
bun add tree-sitter@^0.25.0 tree-sitter-mips
```
<details>
<summary>Example code</summary>
```javascript
const Parser = require('tree-sitter');
const mips = require('tree-sitter-mips');
const code = "li $t0, 2";
const parser = new Parser();
parser.setLanguage(mips);
const tree = parser.parse(code);
console.log(tree.rootNode.toString());
// Output: (program (instruction opcode: (opcode) operands: (operands (register) (decimal))))
```
</details>
### Python
Install `tree-sitter` and `tree-sitter-mips`:
```
pip install tree-sitter tree-sitter-mips
```
<details>
<summary>Example code</summary>
```python
import tree_sitter
from tree_sitter_mips import language
source = b"li $t0, 2"
parser = tree_sitter.Parser()
parser.language = tree_sitter.Language(language())
tree = parser.parse(source)
def to_string(node):
return "(" + " ".join([node.type, *map(to_string, node.named_children)]) + ")"
print(to_string(tree.root_node))
# Output: (program (instruction (opcode) (operands (register) (decimal))))
```
</details>
### Rust
This parser works with `tree-sitter` version `0.23.0` or higher.
To use it in your project, add these dependencies to your `Cargo.toml`:
```toml
tree-sitter = "0.25.8" # or any version >= 0.23.0
tree-sitter-mips = "0.1.4"
```
<details>
<summary>Example code</summary>
```rs
use tree_sitter::Parser;
fn main() {
let code = b"li $t0, 2";
let mut parser = Parser::new();
parser
.set_language(&tree_sitter_mips::LANGUAGE.into())
.expect("Error loading Mips parser");
let tree = parser.parse(code, None).unwrap();
println!("{}", tree.root_node().to_sexp());
// Output: (program (instruction opcode: (opcode) operands: (operands (register) (decimal))))
}
```
</details>
### Go
This parser is compatible with Go>=1.22.
To use it in your project, add these dependencies to your `go.mod`:
```gomod
require github.com/tree-sitter/go-tree-sitter v0.24.0
require github.com/omeyenburg/tree-sitter-mips v0.1.4
```
<details>
<summary>Example code</summary>
```go
package main
import (
"fmt"
tree_sitter "github.com/tree-sitter/go-tree-sitter"
tree_sitter_mips "github.com/omeyenburg/tree-sitter-mips/bindings/go"
)
func main() {
code := []byte("li $t0, 2")
parser := tree_sitter.NewParser()
defer parser.Close()
parser.SetLanguage(tree_sitter.NewLanguage(tree_sitter_mips.Language()))
tree := parser.Parse(code, nil)
defer tree.Close()
root := tree.RootNode()
fmt.Println(root.ToSexp())
// Output: (program (instruction opcode: (opcode) operands: (operands (register) (decimal))))
}
```
</details>
## Development
This grammar is best built with `tree-sitter-cli@0.24.7` (Some package managers refer to it as `tree-sitter` instead of `tree-sitter-cli`).
### Building with npm
First, install the dependencies:
```
npm install
```
This will install `tree-sitter-cli`.
Now you can generate the grammar:
```
npx tree-sitter generate
```
Test the grammar:
```
npx tree-sitter test
```
And parse files:
```
npx tree-sitter parse file.asm
```
## Further reading
- https://www.cs.cornell.edu/courses/cs3410/2008fa/MIPS_Vol2.pdf
- http://www.cs.unibo.it/~solmi/teaching/arch_2002-2003/AssemblyLanguageProgDoc.pdf
- https://en.wikibooks.org/wiki/MIPS_Assembly/Instruction_Formats
Raw data
{
"_id": null,
"home_page": null,
"name": "tree-sitter-mips",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "incremental, parsing, tree-sitter, mips",
"author": null,
"author_email": "Oskar Meyenburg <oskar.meyenburg@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/ce/39/1604b6afb203a92c15242142acc94110e60636245618f60adff5c7f43188/tree_sitter_mips-0.1.4.tar.gz",
"platform": null,
"description": "# tree-sitter-mips\n\nA [tree-sitter](https://github.com/tree-sitter/tree-sitter) parser for the MIPS assembly language.\n\n[](https://github.com/omeyenburg/tree-sitter-mips/actions/workflows/ci.yml)\n[](https://crates.io/crates/tree-sitter-mips)\n[](https://www.npmjs.com/package/tree-sitter-mips)\n[](https://pypi.org/project/tree-sitter-mips)\n\n\n\n## Integration in NeoVim\n\nTo use `tree-sitter-mips` in NeoVim, the plugin [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) is required.\n\n>[!IMPORTANT]\n> This will **only** work on the **[master branch of nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter)** and not on the **main branch**!\n\n1. Add this to your `nvim-treesitter` config:\n ```lua\n local parser_config = require('nvim-treesitter.parsers').get_parser_configs()\n parser_config.mips = {\n install_info = {\n url = 'https://github.com/omeyenburg/tree-sitter-mips',\n branch = 'main',\n files = { 'src/parser.c', 'src/scanner.c' },\n generate_requires_npm = false,\n requires_generate_from_grammar = false,\n },\n filetype = { 'asm', 'vmasm' },\n }\n ```\n2. Run `:TSInstall mips` to install the parser.\n3. Copy the queries to enable highlighting. See [Adding queries](https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#adding-queries) for more information.\n <details>\n <summary>Unix</summary>\n\n ```sh\n mkdir -p \"$XDG_CONFIG_HOME/nvim/queries/mips\"\n curl -L -o \"$XDG_CONFIG_HOME/nvim/queries/mips/highlights.scm\" https://raw.githubusercontent.com/omeyenburg/tree-sitter-mips/main/queries/highlights.scm\n curl -L -o \"$XDG_CONFIG_HOME/nvim/queries/mips/indents.scm\" https://raw.githubusercontent.com/omeyenburg/tree-sitter-mips/main/queries/indents.scm\n ```\n </details>\n <details>\n <summary>Windows (cmd.exe)</summary>\n\n ```sh\n mkdir \"%LOCALAPPDATA%\\nvim\\queries\\mips\"\n curl -L -o \"%LOCALAPPDATA%\\nvim\\queries\\mips\\highlights.scm\" https://raw.githubusercontent.com/omeyenburg/tree-sitter-mips/main/queries/highlights.scm\n curl -L -o \"%LOCALAPPDATA%\\nvim\\queries\\mips\\indents.scm\" https://raw.githubusercontent.com/omeyenburg/tree-sitter-mips/main/queries/indents.scm\n ```\n </details>\n\nAlternative: If you are looking for a more general grammar for assembly, check out [tree-sitter-asm](https://github.com/RubixDev/tree-sitter-asm) which supports features of other instruction sets, yet it lacks some specific features of MIPS.\n\n\n## Language integration\n\n### Javascript\n\nInstall `tree-sitter` and `tree-sitter-mips`:\n```sh\nnpm install tree-sitter@^0.25.0 tree-sitter-mips\n```\nOr using `bun` (or `yarn` or `pnpm`):\n```sh\nbun add tree-sitter@^0.25.0 tree-sitter-mips\n```\n\n<details>\n<summary>Example code</summary>\n\n```javascript\nconst Parser = require('tree-sitter');\nconst mips = require('tree-sitter-mips');\n\nconst code = \"li $t0, 2\";\n\nconst parser = new Parser();\nparser.setLanguage(mips);\n\nconst tree = parser.parse(code);\n\nconsole.log(tree.rootNode.toString());\n// Output: (program (instruction opcode: (opcode) operands: (operands (register) (decimal))))\n```\n</details>\n\n### Python\n\nInstall `tree-sitter` and `tree-sitter-mips`:\n```\npip install tree-sitter tree-sitter-mips\n```\n\n<details>\n<summary>Example code</summary>\n\n```python\nimport tree_sitter\nfrom tree_sitter_mips import language\n\nsource = b\"li $t0, 2\"\n\nparser = tree_sitter.Parser()\nparser.language = tree_sitter.Language(language())\ntree = parser.parse(source)\n\ndef to_string(node):\n return \"(\" + \" \".join([node.type, *map(to_string, node.named_children)]) + \")\"\n\nprint(to_string(tree.root_node))\n# Output: (program (instruction (opcode) (operands (register) (decimal))))\n```\n</details>\n\n### Rust\n\nThis parser works with `tree-sitter` version `0.23.0` or higher.\n\nTo use it in your project, add these dependencies to your `Cargo.toml`:\n```toml\ntree-sitter = \"0.25.8\" # or any version >= 0.23.0\ntree-sitter-mips = \"0.1.4\"\n```\n\n<details>\n<summary>Example code</summary>\n\n```rs\nuse tree_sitter::Parser;\n\nfn main() {\n let code = b\"li $t0, 2\";\n\n let mut parser = Parser::new();\n parser\n .set_language(&tree_sitter_mips::LANGUAGE.into())\n .expect(\"Error loading Mips parser\");\n\n let tree = parser.parse(code, None).unwrap();\n\n println!(\"{}\", tree.root_node().to_sexp());\n // Output: (program (instruction opcode: (opcode) operands: (operands (register) (decimal))))\n}\n```\n</details>\n\n### Go\n\nThis parser is compatible with Go>=1.22.\n\nTo use it in your project, add these dependencies to your `go.mod`:\n```gomod\nrequire github.com/tree-sitter/go-tree-sitter v0.24.0\nrequire github.com/omeyenburg/tree-sitter-mips v0.1.4\n```\n\n<details>\n<summary>Example code</summary>\n\n```go\npackage main\n\nimport (\n \"fmt\"\n\n tree_sitter \"github.com/tree-sitter/go-tree-sitter\"\n tree_sitter_mips \"github.com/omeyenburg/tree-sitter-mips/bindings/go\"\n)\n\nfunc main() {\n code := []byte(\"li $t0, 2\")\n\n parser := tree_sitter.NewParser()\n defer parser.Close()\n parser.SetLanguage(tree_sitter.NewLanguage(tree_sitter_mips.Language()))\n\n tree := parser.Parse(code, nil)\n defer tree.Close()\n\n root := tree.RootNode()\n\n fmt.Println(root.ToSexp())\n // Output: (program (instruction opcode: (opcode) operands: (operands (register) (decimal))))\n}\n```\n</details>\n\n## Development\n\nThis grammar is best built with `tree-sitter-cli@0.24.7` (Some package managers refer to it as `tree-sitter` instead of `tree-sitter-cli`).\n\n### Building with npm\n\nFirst, install the dependencies:\n```\nnpm install\n```\nThis will install `tree-sitter-cli`.\n\nNow you can generate the grammar:\n```\nnpx tree-sitter generate\n```\n\nTest the grammar:\n```\nnpx tree-sitter test\n```\n\nAnd parse files:\n```\nnpx tree-sitter parse file.asm\n```\n\n## Further reading\n\n- https://www.cs.cornell.edu/courses/cs3410/2008fa/MIPS_Vol2.pdf\n- http://www.cs.unibo.it/~solmi/teaching/arch_2002-2003/AssemblyLanguageProgDoc.pdf\n- https://en.wikibooks.org/wiki/MIPS_Assembly/Instruction_Formats\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A syntax parser for the MIPS Instruction Set Architecture.",
"version": "0.1.4",
"project_urls": {
"Homepage": "https://github.com/omeyenburg/tree-sitter-mips"
},
"split_keywords": [
"incremental",
" parsing",
" tree-sitter",
" mips"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "846151f5818688fff2344dec2e2f4a7cbed676cd315b520361bd2a54e3a8037f",
"md5": "a1a51744600e6417356b7289751ed885",
"sha256": "769a4ddac058f68164b67555235ec5af88a8d8fb244f635106c098539c54deeb"
},
"downloads": -1,
"filename": "tree_sitter_mips-0.1.4-cp39-abi3-macosx_10_9_x86_64.whl",
"has_sig": false,
"md5_digest": "a1a51744600e6417356b7289751ed885",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 31226,
"upload_time": "2025-08-15T20:17:18",
"upload_time_iso_8601": "2025-08-15T20:17:18.967260Z",
"url": "https://files.pythonhosted.org/packages/84/61/51f5818688fff2344dec2e2f4a7cbed676cd315b520361bd2a54e3a8037f/tree_sitter_mips-0.1.4-cp39-abi3-macosx_10_9_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "39803dc3a4fd231bea8a0100e320ce5712fbedc2ba169c4458ec2ea0f2e4cf6c",
"md5": "0ae5123d3aa006acff65a366e2efe516",
"sha256": "2311f2e78365914476b94291e8566ffb1f907bd8c901d8ee8a873e116bec73c8"
},
"downloads": -1,
"filename": "tree_sitter_mips-0.1.4-cp39-abi3-macosx_11_0_arm64.whl",
"has_sig": false,
"md5_digest": "0ae5123d3aa006acff65a366e2efe516",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 31731,
"upload_time": "2025-08-15T20:17:20",
"upload_time_iso_8601": "2025-08-15T20:17:20.317362Z",
"url": "https://files.pythonhosted.org/packages/39/80/3dc3a4fd231bea8a0100e320ce5712fbedc2ba169c4458ec2ea0f2e4cf6c/tree_sitter_mips-0.1.4-cp39-abi3-macosx_11_0_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "746ac5ca4e34e441ae7dfd761380246596382dbb216e5b9ac7cd29d7c2011fe7",
"md5": "c8413e221c52103076f0f77bf5798860",
"sha256": "698663ed7b2055d45e1e61d0361200719cc897ac4e761a784087fa5a6055bdf2"
},
"downloads": -1,
"filename": "tree_sitter_mips-0.1.4-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl",
"has_sig": false,
"md5_digest": "c8413e221c52103076f0f77bf5798860",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 56615,
"upload_time": "2025-08-15T20:17:22",
"upload_time_iso_8601": "2025-08-15T20:17:22.509908Z",
"url": "https://files.pythonhosted.org/packages/74/6a/c5ca4e34e441ae7dfd761380246596382dbb216e5b9ac7cd29d7c2011fe7/tree_sitter_mips-0.1.4-cp39-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "be270c5ce39340df26c48c6fea60312eec93c509c16182791f56a57d08f66d95",
"md5": "f4ce9a3925c0b6598ffc4bc98af14276",
"sha256": "9a0054bc58db28878313f1d5e04ca9433d21ebc68575c51d860f3a39c0bf6efd"
},
"downloads": -1,
"filename": "tree_sitter_mips-0.1.4-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl",
"has_sig": false,
"md5_digest": "f4ce9a3925c0b6598ffc4bc98af14276",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 58280,
"upload_time": "2025-08-15T20:17:23",
"upload_time_iso_8601": "2025-08-15T20:17:23.810776Z",
"url": "https://files.pythonhosted.org/packages/be/27/0c5ce39340df26c48c6fea60312eec93c509c16182791f56a57d08f66d95/tree_sitter_mips-0.1.4-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "dc70a7e5c1f89600445e50add59bbe0ac5e52381ce873da48b8093bb6dca24e8",
"md5": "97cf7419d29a6177c2ee692007273a3b",
"sha256": "a63b615cacbef34cbdbc708aa401f2d2efdcc2371bf1e6a8ea57fb6cb614cbe3"
},
"downloads": -1,
"filename": "tree_sitter_mips-0.1.4-cp39-abi3-musllinux_1_2_x86_64.whl",
"has_sig": false,
"md5_digest": "97cf7419d29a6177c2ee692007273a3b",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 55376,
"upload_time": "2025-08-15T20:17:24",
"upload_time_iso_8601": "2025-08-15T20:17:24.817962Z",
"url": "https://files.pythonhosted.org/packages/dc/70/a7e5c1f89600445e50add59bbe0ac5e52381ce873da48b8093bb6dca24e8/tree_sitter_mips-0.1.4-cp39-abi3-musllinux_1_2_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "68e4e44b016d368537452413bae12e2e41f8b4f7825d79d83fa464363c954732",
"md5": "f890ad4189d42054fc86d52d34d968f0",
"sha256": "f57f9cf54f23b14955c5e18bdc98549e6312231971de5ba74b72264fc261587f"
},
"downloads": -1,
"filename": "tree_sitter_mips-0.1.4-cp39-abi3-win_amd64.whl",
"has_sig": false,
"md5_digest": "f890ad4189d42054fc86d52d34d968f0",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 31979,
"upload_time": "2025-08-15T20:17:26",
"upload_time_iso_8601": "2025-08-15T20:17:26.069762Z",
"url": "https://files.pythonhosted.org/packages/68/e4/e44b016d368537452413bae12e2e41f8b4f7825d79d83fa464363c954732/tree_sitter_mips-0.1.4-cp39-abi3-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c5ad84fa38f42ac086c281dc5a0c9d6165ebbe09e6af4389a71226a75790fcd5",
"md5": "408df6e0769c3495c8bbad1bb081e04d",
"sha256": "4520c10359417494c1012bbd1aa55f4e0804a44d7b47b662deeefea139ed5a49"
},
"downloads": -1,
"filename": "tree_sitter_mips-0.1.4-cp39-abi3-win_arm64.whl",
"has_sig": false,
"md5_digest": "408df6e0769c3495c8bbad1bb081e04d",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.9",
"size": 30895,
"upload_time": "2025-08-15T20:17:26",
"upload_time_iso_8601": "2025-08-15T20:17:26.978391Z",
"url": "https://files.pythonhosted.org/packages/c5/ad/84fa38f42ac086c281dc5a0c9d6165ebbe09e6af4389a71226a75790fcd5/tree_sitter_mips-0.1.4-cp39-abi3-win_arm64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ce391604b6afb203a92c15242142acc94110e60636245618f60adff5c7f43188",
"md5": "7214174650e3f75442dcae533f4abab5",
"sha256": "6cd9da9671dde33401af90d53f34b1e813549e6b66956f3cf4ac7eaaf689b8ca"
},
"downloads": -1,
"filename": "tree_sitter_mips-0.1.4.tar.gz",
"has_sig": false,
"md5_digest": "7214174650e3f75442dcae533f4abab5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 46373,
"upload_time": "2025-08-15T20:17:28",
"upload_time_iso_8601": "2025-08-15T20:17:28.175366Z",
"url": "https://files.pythonhosted.org/packages/ce/39/1604b6afb203a92c15242142acc94110e60636245618f60adff5c7f43188/tree_sitter_mips-0.1.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-15 20:17:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "omeyenburg",
"github_project": "tree-sitter-mips",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "tree-sitter-mips"
}