A tree-sitter grammar for MLIR, derived from the MLIR language reference rather than a list of dialects.
A tree-sitter grammar for MLIR, the Multi-Level Intermediate Representation. The grammar follows the generic MLIR textual format of the MLIR Language Reference, and handles the custom operation formats of dialects without enumerating the dialects.
The existing parser works from a fixed list of dialects and their grammars. This one asks whether a parser derived from MLIR’s EBNF alone can handle arbitrary dialects; the blog post tells the story. It has been tested, but not exhaustively.
"opname"(args) {attrs} : functype form.tensor, memref,
vector, complex, tuple), dialect types (!namespace.name<...>), type
aliases, and function types.dense, dense_resource,
sparse, opaque, strided, affine_map, affine_set, array,
dictionary), dialect attributes, and attribute aliases.%id, result lists, and block arguments with their types
and attributes.@name, with nested :: qualification.Highlighting, SSA value scopes for rename and go to definition, indentation,
folds, symbol tags, and text objects, in queries/.
In Neovim with nvim-treesitter (main branch), register the parser in a
User TSUpdate autocommand:
vim.api.nvim_create_autocmd("User", {
pattern = "TSUpdate",
callback = function()
require("nvim-treesitter.parsers").mlir = {
install_info = {
url = "https://github.com/tkamucheka/tree-sitter-mlir",
queries = "queries",
generate = true,
},
}
end,
})
Bindings for Python and Rust, and the development workflow, are described in the README.