Jerith online [entries|archive|friends|userinfo]
jerith

[ website | jerith.za.net ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Happy hacking [Aug. 19th, 2007|06:22 pm]
[Tags|, , , , , ]

I wrote a satisfying amount of Python this weekend. I am currently in the throes of rewriting bits of my website backend, and one of the things I'm replacing is the syntax highlighting code. The present system shells out to vim and munges the HTML it gets back into a useful form. The new plan is to use pygments, a python syntax highlighting library. The problem with pygments is that it doesn't handle all the languages I want to display.

One of these languages is Erlang, which I have a tendency to wax enthusiastic about. Since there are unlikely to be too many other people who want to highlight it in a Python library (although Haskell's there, so maybe not) I decided it would be worth the effort of writing a lexer for it. This was easier said than done, however. The vim and emacs syntax files were both slightly broken (I'll be looking at them next) so I ended up doing a lot of the work by referring to the docs and experimenting with the interpreter.

Along the way, I ran into an issue with the Java lexer. Some badly formatted code tickled a pathological case in one of the regular expressions and took exponential time in the length of an exception class name. Anything longer than about 24 characters (which includes a lot of Java's standard exceptions) and the lexer would never come back. This was resolved with the help of the people on #pocoo (pocoo is pygments' parent project) and ended up in a simplification of and fix to the Java and C# lexers.

Anyways, I've submitted the patch for the Erlang lexer and I'll see if it gets into trunk. It was a fun experience, combining two of my favourite languages.
Link1 comment|Leave a comment

navigation
[ viewing | most recent entries ]

Advertisement