jgm / skylighting

A Haskell syntax highlighting library with tokenizers derived from KDE syntax highlighting descriptions
194 stars 62 forks source link

Fix abysmal highlighting for Haskell chars (which often breaks -XDataKinds) #40

Closed neongreen closed 6 years ago

neongreen commented 6 years ago

Highlighting for Haskell char literals treats them basically as strings, which breaks in presence of -XDataKinds:

image

This PR fixes it by using a (somewhat crude) regex for chars instead of “everything between two apostrophes”.

jgm commented 6 years ago

Good, thanks. You might consider submitting this upstream to KDE, since presumably it also affects rendering in the Kate editor.

jgm commented 6 years ago

It might also be worth improving the regex:

(\\'|\\[^']+|[^\\\n])

You probably need a \r in the last character class, for Windows. And what if the character is a control character (a literal tab or something like BEL)?

neongreen commented 6 years ago

And what if the character is a control character (a literal tab or something like BEL)?

Yes, the regex doesn't take that into account. I think the right thing to do is to take the Haskell Report and just encode the definition from there, but I stared at it for two minutes and gave up :(

As for \r, I'm not sure even the \n is necessary there (I've no idea how stuff like #stay works). It might be prudent to add \r to the patched file in skylighting, yeah.