go-internal icon indicating copy to clipboard operation
go-internal copied to clipboard

testscript: formal grammar for txtar syntax highlight

Open abitrolly opened this issue 9 months ago • 3 comments

I miss syntax highlighting for testscript files. While I would enjoy crafting the highlight files myself, the pressure of converting time to money forces me to leave this task to automatic converters, which accept some kind of formal grammar or meta definition of the language (list of keywords in machine readable format etc.) for input.

abitrolly avatar Apr 11 '25 08:04 abitrolly

The syntax is extremely simple. One way of describing it formally is with a regular expression. This, for example:

^(.*\n)*?.*?(\n-- .+ --(\n.*)*?)*\n?$

Alternatively, one could just say that a file boundary is described by the regular expression:

^-- (.+) --$

The more interesting part of syntax highlighting with respect to txtar is that ideally the individual file parts get their own file-specific syntax highlighting according to the file extension of that part. I suspect that might be a challenge to implement depending on the capabilities of the editor's highlighting system.

rogpeppe avatar Apr 16 '25 17:04 rogpeppe

See also https://github.com/rogpeppe/go-internal/issues/97

myitcv avatar Apr 16 '25 18:04 myitcv

#97 indeed contains separate implementations written by hand. The formal grammar helps autogenerate highlighters that identify errors and highlight proper keywords. At least the keyword definitions and their grammar would be nice.

abitrolly avatar Jun 15 '25 18:06 abitrolly