home tags blog microbio cv tech cv

Writing my own tree-sitter grammar

Soc Virnyl Estela | 2022-12-14 | updated: 2023-04-02 | reading time: ~3min

Tree-sitter is an incremental parsing system that allows developers to add syntax highlighting and tree-sitter regex search for easy navigation.

The project is heavily used among popular editors such as neovim, and helix.

The issue§

As a volunteer packager for openSUSE, I read rpm specfiles to add, update, and/or modify a package. It was fine with neovim at first but I use helix now as my main editor for modifying specfiles and for doing some changes.

A comparison between helix right and neovim left:

comparing helix and neovim syntax highlighting of rpm

As you can see from the image above, helix does not have a syntax highlighter for rpm. Neovim and Vim do but they do not use tree-sitter for the highlighting of code. I am no expert of how neovim and vim do that without tree-sitter but I can link you to a blog which summarizes how it works by implementing syntax highlighting for Bril.

This poses a problem§

Well... for me, not sure for other people. The role of syntax highlighting is to allow us to see each part of the syntax differently e.g. function, module, variable, etcetera. This increases readability and the time to recognize parts of code is lessened to an extent. Although, it is not a big deal in most cases because RPM specfiles are usually less than 200 lines, it gets too complicated for packaging software that have different needs and limitations e.g. julia, and rust. Check out the specfiles for julia and rust and you will see what I mean.


Again, I mainly use helix now as my main editor. And helix does not have the same syntax highlighting functionality like vim's or neovim's. It uses tree-sitter to do the syntax highlighting. Therefore, I have taken the initiative to write an RPM grammar for tree-sitter to solve my problems reading specfiles. For now the project is an empty repository - https://codeberg.org/uncomfyhalomacro/tree-sitter-rpm.

I will update later in the future blogs on the progress of this. It's my first time writing a grammar for tree-sitter after all. 😁

Articles from blogs I follow around the net

Decrypting FortiOS 7.0.x

Introduction Decrypting Fortinet’s FortiGate FortiOS firmware is a topic that has been thoroughly covered, in part because of the many variants and permutations of FortiOS firmware, all differing based on hardware architecture and versioning — we may have …

via GreyNoise Labs April 23, 2024

Copyleft licenses are not “restrictive”

One may observe an axis, or a “spectrum”, along which free and open source software licenses can be organized, where one end is “permissive” and the other end is “copyleft”. It is important to acknowledge, however, that though copyleft can be found at the …

via Drew DeVault's blog April 19, 2024

What Precious Things Does The Corporate World Steal From Us?

It has been about a year and a half of working three days a week in response to burnout. It took me six months to regain the ability to do anything beyond resting the moment I was done working, and in the past year I have recovered much of my ability to fu…

via Ludicity April 15, 2024

Generated by openring-rs