Wednesday, March 30, 2011

Syntax Highlighting for Smalltalk

In discussions about software it is nice to show code. It can drive an abstract point home by giving an example.

I have some experience with Alex Gorbatchev's SyntaxHighlighter. It is a javascript based syntax highlighter with customizable brushes. The downside: no Smalltalk brush.

So I set out to create a Smalltalk brush for SyntaxHighlighter. The git repository SyntaxHighlighter-Smalltalk-Brush holds the result. As a test case I used the Smalltalk syntax on a postcard example. You can see an example below.

exampleWithNumber: x
   "A method that illustrates every part of Smalltalk method syntax
   except primitives. It has unary, binary, and keyword messages,
   declares arguments and temporaries, accesses a global variable
   (but not and instance variable), uses literals (array, character,
   symbol, string, integer, float), uses the pseudo variables
   true false, nil, self, and super, and has sequence, assignment,
   return and cascade. It has both zero argument and one argument blocks."


   true & false not & (nil isNil) ifFalse: [self halt].
   y := self size + super size.
   #($a #a "a" 1 1.0)
    do: [:each | Transcript show: (each class name);
          show: ' '].
   ^ x < y


  1. Awesome! Will you submit this to the main SyntaxHighlighter project? I'd love to have this in WordPress by default.

  2. I will try to get this brush submitted to the main SyntaxHighlighter project.

    I can't make any promises because Alex Gorbatchev has the final say.