favicon here hometagsblogmicrobio cvtech cvgpg keys

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.

Solution§

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

Some Thoughts on the Twitter Mass Exodus

Another wave of Twitter users are jettisoning the social media website in favor of alternatives. Some are landing in the Fediverse (Mastodon and other ActivityPub-enabled software). Others are going to BlueSky. Some are just outright abandoning social medi…

via Dhole MomentsNovember 19, 2024

hyper in curl Needs a Champion

tl;dr - hyper in curl is nearly complete, but it needs a champion. Without a partner actively engaged that wants to enable and ship, it’s now on the path for being deprecated and removed. It needs a champion, a backing vendor or distro. Will that be you? …

via seanmonstarNovember 19, 2024

Swift observations from a reluctant Rustacean

Recently I've been thinking about Swift in terms of Rust, & have appreciated anew some of the choices made. In Rust. There's been a proliferation of X vs Y posts on the web, especially since the advent of LLM AI, so I try to resist the format. It's often e…

via Mike KreuzerNovember 16, 2024

Go Concurrency Patterns

Goroutines Channels Select Statement Wait Groups Mutex Conditions Atomic Operations Once Context Map Real Examples Goroutines The go keyword is used to start a goroutine. A goroutine is a lightweight, managed thread used by the Go runtime to run functions …

via Posts on integralistNovember 15, 2024

anarchism starts in the now: hope for a better future

there is still time

via maia blogNovember 14, 2024

Why I Will Always Be Angry About Software Engineering

Why do I bother getting angry about software? When I started writing, it came from a place of ennui — absolute despair at the amount of waste I was seeing in the technology sector since leaving university. I was paid spectacularly well, but nothing I produ…

via LudicityNovember 12, 2024

Generated by openring-rs

favicon here hometagsblogmicrobio cvtech cvgpg keys