favicon here hometagsblogmicrobio cvtech cvatuin server

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

Synergy Greg

Synergy Greg would like to see you in His office, it is the one down the hall, past the cubicles and dreary faces, uplifted only when He deigns to venture forth. You will know Him when you see Him, He is the one composed, of a thousand writhing forms,…

via LudicityJune 22, 2024

Status update, June 2024

Hi all! This status update will be shorter than usual because I had a lot less free time for my open-source projects than usual this month. Indeed, I recently joined SNCF Réseau (the company responsible for the French railway infrastructure) to work on OSR…

via emersionJune 18, 2024

SolarWinds Serv-U (CVE-2024-28995) exploitation: We see you!

On June 5, 2024, SolarWinds published an advisory detailing CVE-2024-28995 - a path-traversal vulnerability in Serv-U, discovered by Hussein Daher. The affected versions are: SolarWinds Serv-U 15.4.2 HF 1 and earlier are affected SolarWinds Serv-U 15.4.2 …

via GreyNoise LabsJune 18, 2024

Why People are Angry over Go 1.23 Iterators

NOTE: This is based on, but completely rewritten, from a Twitter post: https://x.com/TheGingerBill/status/1802645945642799423 TL;DR It makes Go feel too “functional” rather than being an unabashed imperative language. I recently saw a post on Twitter showi…

via Articles on gingerBillJune 17, 2024

Programming at the edge with Fastly Compute

So you’ve heard about computing at the edge, and you’ve heard that Fastly let’s you run JavaScript, Go, Rust and any other language that compiles to Wasm at the edge… well, let’s take a look and while we’re at it let’s try and understand how caching works …

via Posts on integralistJune 12, 2024

israeli national police found trying to purchase stalkerware - #FuckStalkerware pt. 7

they're in pleasant company with other governments, intelligence companies, and data brokers

via maia blogJune 09, 2024

Generated by openring-rs