Is it possible to generate a tree-sitter grammar file from a lezer grammar file?

Hello, Marijn, congrats on building such an amazing project, the components/modules appear to be very well designed and thought out together, a feat that could’ve only been done by a thoughtful, smart and capable person. and the docs are amazingly written. :slightly_smiling_face:

After reading the docs for the Lezer parser (but not yet building a parser with Lezer), and having read the tree-sitter docs, and having created a small and incomplete tree-sitter parser for my (lisp like) language, a week ago: it appears to me that a Lezer grammar is a superset of a tree-sitter grammar, i.e. you can use a Lezer grammar file to compile a Tree-sitter grammar file, but not vice-versa, am I correct in this observation?

I am interested in writing and maintaining only a Lezer grammar file, and use the Lezer grammar file to compile a tree-sitter grammar file. I love the designed syntax of the grammar language, much better than writing a JS object structure for a tree-sitter grammar.

I prefer doing it this way because I have an important goal of using CodeMirror for a web/online code editor environment for my language, and also want to provide syntax highlighting support in code editors for my language, in code editors like VSCode, Neovim and Emacs, using tree-sitter.
(I also think I would enjoy writing and maintaining Lezer .grammar files more than I think I would writing a tree-sitter grammar.js grammar files)

There are some differences, like how Lezer conflict markers are per-position and Tree-Sitter marks whole rules. But I think something like this would be possible. It doesn’t exist yet though. There’s a crude tree-sitter-to-lezer tool here, but that is meant more as a way to generate an initial file to hand-edit than as a fully automatic solution.

1 Like