Title: "Designing and Implementing a New Highlighting Engine for GtkSourceView" Authors: Emanuele Aina Marco Barisione Paolo Maggi (Politecnico di Torino) Abstract: GtkSourceView is a widget that extends the standard GTK+ 2.x text widget by implementing syntax highlighting and other features typical of a source editor. It is part of the GNOME desktop environment and it is currently being used by gedit, MonoDevelop, Screem, Conglomerate, gnome-db and several other projects. Although GtkSourceView has proved to be a good solution for simple syntax highlighting, it is not yet on par with widgets such as Scintilla or KDE's Kate widget. The current highlighting engine has several limitations principally due to the fact that it is able to highlight only very simple expressions and that it ignores the structure of the document it is highlighting. To overcome these limitations, we are developing a new highlighting engine, based on a state machine, which can split documents in nested contexts. The new engine will provide a more correct and precise syntax highlighting, since it will be able to handle cases that an engine based on simple regular expressions (like the current one) cannot handle. For example, it will be possible to highlight "%" directives in format strings or manage "#if/#endif" blocks nested inside an "#if 0/#endif" block. To make this possible, we will also introduced a new XML-based syntax definition language with a greatly increased expressiveness. The new syntax definition files will feature the possibility to inherit parts of other syntax files (in order to reduce code duplication) and will also be able to include different languages in specific sub-contexts (e.g. Javascript in HTML). Both these features were not available with the old syntax definition format. To achieve backward compatibility, the old syntax highlighting engine will not be replaced, but it will be used to highlight those files for which a syntax definition file using the new format is not available. In the future, it will even be possible to use the new engine with the old syntax definition files, but this feature will be implemented in a second step. By splitting the document in nested contexts, it will also be possible to use the information generated by the new engine to mark "foldable"regions for each supported language. In this paper, we will first describe the current version of GtkSourceView and its main limitations. Then we will present the design and the implementation of the new highlighting engine. To conclude, we will compare it with the engine of widgets contained in other open source libraries.