Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Writting A Neovim Syntax Highlighter For Neopolitan In Tree - Sitter

Introduction

I spent the past few days learning how to make a Tree - sitter parser to add neopolitan syntax highlighting to Neovim. It was an adventure but I'm happy with where I ended up.

Languages And Parsing

Tree - sitter's default parsing is done with JavaScript regex. Unfortunately, some regex features (like lookahead matches) aren't available. It has something to do with the way the parser works. I don't know the details. Regardless, I needed lookahead so I needed another option.

It turns out you can extend Tree - sitter by making custom parsers written in C or C++. Two languages I've never used. Some parts of Tree - sitter are written in Rust (which I do know a little) so I was hoping I could find a way to use that. I don't know if it's possible, but if it is I couldn't figure it out. So, I dug into C on the Learn X In Y Minutes site. I didn't really learn the language, but I figured out enough to get a parser working.

How's It Look

I'm writing up how I built the parser in another post. For now, here's an example of the how it looks in Neovim.

I'm really happy with how this turned out. I've been working on the format and corresponding site generator for a year. I've been using them for a few months, but this syntax highlighting makes it feel real.

It's also very cool because the concrete syntax tree generated can be accessed from other Neovim plugins. That means I can use it to add functionality that executes code blocks and puts the output directly inside the files (similar to org - mode on emacs).

That's gonna take things to the next level.

References

Footnotes And References