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

Agile is a tainted term

Oh no, not another agile article. But at least this one isn't attempting to teach or reconcile. I'm not going to talk about the difference between agile and Agile™ nor will I try to convince you of my favorite flavor of Agile™. Instead, I'm here to assert …

via pcloadletter February 16, 2024

You Must Read At Least One Book To Ride

Two things are true. The first is going to sound bad in a culture where engineers are encouraged to apologize for existing while it is totally acceptable for a grifter that can't code to insist that they're a "thought leader". It is that, in my immediate p…

via Ludicity February 15, 2024

Code injection or backdoor: A new look at Ivanti’s CVE-2021-44529

This is yet another, “Ron got nerdsniped by a thing and wasted enough time that he needs something to show for it” blog. Which, come to think of it, are pretty much all my blogs. :) Recently, a tweet from Steven Seeley (ϻг_ϻε) caught my eye - an exploit fo…

via GreyNoise Labs February 15, 2024

Generated by openring-rs