A quick tutorial: How to use the Colorer-take5 (from now on, simply C5) library to implement syntax colouring with eclipse to new language. This tutorial uses P-Cube’s SML language as an example, and was written by Ron Mertens (ronm@p-cube.com).

Install the C5 eclipse plug-in

The plug-in can be installed automatically using Eclipse’s update manager. Point the manager to http://colorer.sf.net/eclipsecolorer/ And install the plug-in.

Add the P-Cube SML prototype to the Color5 main HRC file

The HRC is a ‘language’ used to describe languages in C5, and is based on XML formats. We will use two HRC files – one is the ‘main’ one, that contains language prototypes declarations. The other one is a detailed HRC, used to describe a language.

If you installed the plug-in in c:\eclipse, for example, the C5 main HRC file is located in – C:\eclipse\plugins\net.sf.colorer_0.6.0\colorer\hrc\colorer.hrc If you open this file, you’ll notice a list of prototypes of languages, such as C, Pascal, java and ADA. You’ll have to insert the prototype of your language here. Let’s view the P-Cube SML prototype –
<prototype name="PSML" group="rare" description="P-Cube SML">

<location link="sml/sml.hrc"/>

<filename>/\.(san|swip)$/ifilename>

<parameters>

<param name="P-Cube SML packages" value="true" description="P-Cube SML packages (P-Cube INC)."/>

</parameters> </prototype>

This is pretty straightforward, but we’ll explain it anyway –

  1. Prototype tag. Includes the language’s name, the group (rare, main, etc.) and description.

  2. Location – this is the location of your detailed HRC file. The next section describes how to create this file.

  3. The filename is important – this example shows that any file with a .san or.swip extension is part of the P-Cube SML language.

Prepare your detailed HRC file

P-Cube SML is somewhat similar to java. We based our HRC file on java’s language, so we didn’t need to write everything from scratch.

All the internal HRC files in the C5 library are in the common.jar file, located in the same directory as the colorer.hrc file. Jar files are simply zip files, so you can open them, and extract the java.hrc file. In our example we renamed it to sml.hrc.

We will not go into detail on how to edit those files here. It is pretty straightforward – this files include keyword for syntax colouring, and stuff like that.

Associate your files with the color5 plug-in

The last stage is to tell eclipse to open files using this plug-in. In eclipse preferences, under workspace, you can set file association (Window/Preferences/Workbench/File Associations). In our example, we have set up eclipse to use the Color5 editor when opening .san and .swip file.

That’s it!

Eclipse is now ready to use the Color5 plug-in to display your language, and syntax-colour it. Not very complicated once you know how to do it.

More information

The C5 homepage
Eclipse organization homepage
P-Cube Inc
Enjoy,
Ron M.
P-Cube Inc, http://www.p-cube.com