Adding Scintilla-Supported Lexers to PN

I wrote this a little while back as a simple explanation of the way to add support for languages supported by Scintilla to PN2.

The editing component underneath PN2 is Scintilla, and this includes a number of built-in lexers, the difficulty being that each one has it’s own style keys/numbers and they each need configuring as .scheme files to bring them into PN.

The list of lexers available looks a bit like this (the names are not necessarily correct for these!):

Ada, ADPL, Asm, AU3, AVE, Baan, Bash, Bullant, CLW, configuration files, CPP (thus Java, JavaScript and similar), Crontab, CSS, Eiffel, Erlang, Escript (ecmascript?), Forth, Fortran, Gui4CLI, HTML, Kix, Lisp, Lout, LUA, Matlab, Metapost, MMIXAL, MPT, MSSQL, NSIS, Pascal, PowerBasic, Perl, POV, PS (postscript?), Python, Ruby, Scriptol, Specman, SQL, TeX, VB, Verilog, VHDL, YAML.

That’s a lot more than are surfaced in PN!

I got this list by looking at the Scintilla source code. The way I get all the style numbers for the schemes is to look at the property files that ship with SciTE (the scintilla demonstration text editor). These files have lines like this:

<code># Default
# White space
# Line Comment
# Number
# Keyword

Which define some styles for lisp and would translate to:

<code><style name="Default" key="32" />
<style name="Whitespace" key="0" />
<style name="Line Comment" key="1" class="commentline" />
<style name="Number" key="2" class="number" />
<style name="Keyword" key="3" class="keyword"/> ...</code>

The style.lisp bit indicates that these are styles for the “lisp” lexer, so that then goes in the lexer line in the style configuration:

<lexer name="lisp"/>

Handily, the SciTE config files also include keyword lists and things like that. It’s a matter of a few minutes to translate a SciTE config into a good PN scheme, and the XML for .scheme files is fairly simple so most people should be able to work out the conversion. If you’re trying to do this and get stuck join the pn-discuss list and ask for help.

PN also supports custom scheme definitions (like the VHDL included with PN as vhdl.schemedef). I’ll try and provide some more documentation about this soon.