Slight updates to haskell.vim

Since the Vim syntax file for Haskell was last updated, there have been a bunch of syntax extensions in GHC1, like rank-n types, arrow syntax, and allsorts. I decided to add a few of these.

You can get it here. You might want to back up your old one; I’m pretty sure I haven’t broken anything, but my testing wasn’t exactly thorough (mostly consisting of checking the new syntax worked, rather than whether the old syntax was broken).

Update! if anyone’s seen this yet, then please download it again. The first time, (#) would make the # part of an unboxed tuple bracket. That’s fixed now. (See: lack of testing.)


So far:

forall a b. whatever highlighted

This is extremely simple so far; it just looks for the word forall followed somewhere by a dot on the same line. Since the existing highlighting doesn’t distinguish between types and definitions, it may also find variables called forall that you may have. (It’s only supposed to be a keyword in types, like qualified and friends in imports, but the highlighting doesn’t check that.)

Imports don’t kill the rest of the line’s highlighting

I know that you probably won’t ever another statement following an import on the same line, but if you want to, it’ll be highlighted now. More usefully, though, the contents of the brackets in import Control.Applicative ((<$>)) are highlighted, and so are the brackets themselves if you have g:hs_highlight_delimiters set.

Magic hash/unboxed tuples

Identifiers are allowed to end in #. Since it doesn’t know when magic hash is meant to be on, it might get this wrong sometimes. Currently, (assuming my regex is right) it assumes the # is part of the identifier, unless another word follows with no space. So:

a#+b#   == a# + b#
a#b     == a # b
a#(b)   == a# (b)
(#a,b#) == parse error -- (# a, b# )

A couple of the rules are a little arbitrary, perhaps, but they’re what GHC does. (And, conveniently, what was easiest to make a regex for.) Also, 1# and 1##, highlight as hsNumber and 1.0#/1.0## as hsFloat (which look the same by default).

Arrow syntax

proc and rec highlight the same colour and things like if and do, and (|a|) works. As do (||True) and (4<|), i.e. sections on operators that have | next to a bracket. As in GHC (and as common sense predicts…), you can have spaces between banana brackets as (| a |). Stuff like -< already worked since reserved operators are highlighted the same as regular ones anyway.

mdo

Um, mdo is highlighted. That’s pretty much it.

FFI

FFI declarations are coloured using the same highlighting as import. The means of getting the type signature highlighted is a bit of a hack, and probably missed some things out (it just says that the hsFFI region contains hsType, hsVarSym, hsConSym, and hsString).

CPP

This was in it already, but seems to have been removed in the version on vim.org. So I put it back in.

Other stuff..?

A bunch of this I did months ago but didn’t feel it was worth blogging. So there may be other additions, which can be a wonderful surprise when you discover them. There is no Template Haskell support; maybe I’ll add it in later if I remember.


  1. If you don’t use GHC perhaps these updates won’t be very useful… 

Leave a Reply

You must be logged in to post a comment.