OpenEdge ABL syntax highlighting and GitHub support

2 minute read

GitHub Octocat logo

As I had written in my last blog post, in order to upgrade my blog from Wordpress to a static site like Octopress, I decided that while performing the migration I would improve the syntax highlighting of OpenEdge ABL code snippets. Obviously I’m no fan of the language, but it’s baggage that I’m burdened to carry so I thought I might as well carry it with me in style.

Being an esoteric and proprietary language, ABL doesn’t have much mainstream support for things like syntax highlighting. When my blog was using Wordpress, I had to add support myself to the de-facto Wordpress syntax highlighting library, Alex Gorbachev’s SyntaxHighlighter. I never really liked it though, as SyntaxHighlighter is a JavaScript library and its modus operandi is to make the client browser perform the syntax highlighting when the page is loaded. This means if the page is a little slow to load, the code would not be highlighted immediately. Also, due to ABL’s criminal overuse of keywords, the syntax highlighting code was massive, weighing in around 31.5KiB even after being minified!

Pygments lexer

Syntax highlighting is really something that should be done at compile-time, so I was keen to get rid of the JavaScript solution. Octopress, which is what I currently use for blogging, uses a Python library called Pygments for syntax highlighting. Pygments is basically the defacto library for syntax highlighting. It supports a huge number of languages, supports a wide array of output formats, including HTML, ANSI (console), LaTeX, and RTF, and the lexer base classes it comes with allow one to write the lexer in the most flexible manner, including even mixing different lexer types together (the most common being regex with a simple stack, necessary for handling state such as for nested comments)!

Therefore, I had to write an OpenEdge lexer myself for Pygments. This lexer has since been included in the recent Pygments 1.5 release, so is available for download and use right now.

GitHub support

I was happy to learn that GitHub’s syntax highlighting is also done using Pygments. They use a custom gem called linguist for this purpose. Linguist itself uses another gem called pygments.rb for calling out to Pygments by using the RubyPython library, which actually embeds a Python interpreter inside of Ruby using FFI (very cool, and also fast!).

I went ahead and wrote the linguist support for OpenEdge, the update to pygments.rb to update its Pygments version, and also helped out a bit on the linguist issues list by adding Coq lexer support (requested by someone), improving the PowerShell lexer, and guiding some others through the process of adding support for their language (making sure all the tests pass, etc.) and answering misc. questions.

As a result, OpenEdge ABL is now on GitHub’s language list, and it is now possible to write gists in ABL with syntax highlighting. Pretty hip for such an old and crappy language.

It was very cool to go through the process of writing some code that will actually be running on GitHub’s core infrastructure, even though it’s just a little piece. :-) It also feels nice to write open source software. I hope that when my wife finally finishes medical school and becomes a doctor and after my daughter grows a bit older that I will have more time to contribute to it.

Updated: