Irrational Exuberance!

Erlang Brush for SyntaxHighlighter

September 15, 2009. Filed under erlangpitancesyntaxhighlighter

After the first public display of Pitance, one of the initial weaknesses that Luke Hatcher mentioned was the lack of syntax highlighting. I suggested this was difficult because I was unaware of any Erlang-based1 lexer & formatting packages, making it rather hard.

Luke, on the other hand, suggested it was rather easy.

With that exchange in mind, I took a look at SyntaxHighlighter, which is a JavaScript based highlighting tool. It suited my needs pretty well, but was missing an Erlang lexer (well, lexer used in a very loose sense, since it is really just a collection of regular expressions).

I found an already made Erlang brush (SyntaxHighlighter term for lexer) courtesy of Steve Gilham, but had some trouble getting it working (perhaps his was based on SyntaxHighlighter version 1? Perhaps it was because he was operating in a different namespace? Perhaps I copied and pasted it incorrectly?), so rolled my own version.

You can see a highlighted template here.

SyntaxHighlighter.brushes.Erlang = function() {
    this.regexList = [
        { regex: /<|\>/gm ,css: 'plain' },
        { regex: /[a-z](a-zA-Z0-9)*/gm, css: "color2"},
        { regex: /%(.*)$/gm, css: "comments"},
        { regex: /"(.*)"/gm, css: "string"},
        { regex: /[A-Z](\w*)/gm, css: "value"},
        { regex: /\??[A-Z][A-Z0-9]+/gm, css: 'keyword' }
    ];
}
SyntaxHighlighter.brushes.Erlang.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.Erlang.aliases = ['erlang', 'erl'];

You can grab the latest version of the Erlang brush on Pitance..


  1. Pitance is Erlang all the way down, and to some reasonable extent I'd like to keep it that way.