Fossil User Forum

Fossil wiki Tree-sitter parser
Login

Fossil wiki Tree-sitter parser

Fossil wiki Tree-sitter parser

(1) By Simon Bates (sbates) on 2025-04-25 20:22:17 [source]

I have recently started writing notes for one of my projects as versioned Fossil wiki markup. And I was thinking that I'd like to have syntax highlighting in my text editor. In the editor that I'm using, Tree-sitter is the best supported option for adding syntax highlighting for a new language.

This week I have started making a Tree-sitter parser for Fossil wiki markup. It's on GitHub:

https://github.com/simonbates/tree-sitter-fossil_wiki

It's very much a work in progress and currently has a number of limitations and things that aren't done yet. I'll continue to work on it and I thought I'd share it here in case it's of interest.

Current limitations are at least the following:

  • It only knows about 10 of the Fossil wiki-supported HTML elements (a, code, h1, h2, h3, h4, h5, h6, p, title) and doesn't yet handle elements that don't have a closing tag (like <br>)
  • HTML empty attribute syntax isn't supported
  • HTML unquoted attribute value syntax isn't supported
  • The </verbatim> end tag isn't case-insensitive and can't contain whitespace
  • I haven't yet explored combinations of markup nesting; I'll need to ensure that the nesting supported by this parser is consistent with the actual parser in Fossil

If you are looking at the repo, there are a lot of files and almost all of them are generated by Tree-sitter. The files that are authored by me that define the parser are:

  • grammar.js: the main grammar definition
  • src/scanner.c: an external scanner to handle verbatim content
  • test/corpus/html.txt
  • test/corpus/links.txt
  • test/corpus/verbatim.txt

The tests show some of the supported structures and how they are parsed.

Simon