Monday, September 21, 2015

SuperBASIC Syntax Highlighting in Notepad++

Having always needed to read and edit files from QL, PC, Mac and Unix, I’ve always used programmer’s editors that as a minimum support files with different character encodings and different line endings.

In the past I’ve used software like BBEdit, UltraEdit and jEdit, but my current favorite is Notepad++, a free text editor available for Windows. In addition to the usual features expected from code editors, it has all kinds of plug-ins available for specific tasks like for example pretty-printing XML and of course it has built-in syntax highlighting for the most common programming languages.

Syntax highlighting draws various words and elements of the source code using different colors, based on their function in the language (e.g. keywords vs. strings). It improves the readability of the code.

Notepad++ offers an easy and quick way of adding syntax highlighting for new languages by filling in some pre-defined fields with the lists of different types of keywords and operators and assigning a color to each one of them.
This is a portion of the language definition window:

Notepad++ SuperBASIC definition

It took about 30 minutes to enter all the keywords and operators from the QL and the keywords from the Toolkit II and the Turbo Toolkit.

I assigned different colors to SuperBASIC constructs and operators, QL keywords, Toolkit keywords, numbers, comments and strings. User-defined symbols have no style defined and are shown in black.

Here is how a procedure from the Turbo source code now looks in Notepad++ with the SuperBASIC syntax highlighting (click on the picture to see it full size):

SuperBASIC syntax highlighting

Now I find it easier to read and edit SuperBASIC code! (Q-emuLator runs most of my QL programs from Windows directories, so I can have them open in a Windows editor at the same time.)

The only thing I miss is the RENUM command, but implementing that in Notepad++ would require writing a plug-in.

The SuperBASIC definition for Notepad++ is available for download here.
To install it, unzip the file, then in the Language menu in Notepad++ select ‘Define your  language…’ and click on the ‘Import…’ button to load the definition file.
To try it out, load some SuperBASIC code and select the ‘SuperBASIC’ language from the bottom of the Language menu.