"Fossies" - the Fresh Open Source Software Archive

Member "wscite/SciTELexer.html" (11 Sep 2020, 3735 Bytes) of package /windows/misc/wscite445.zip:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the project site itself.

Scintilla icon Add a lexer to Scintilla and SciTE

Lexer addition.

The process of adding a new lexer to both Scintilla and SciTE is fairly long. Here is my response when asked how to add a lexer for Apache CONF files to SciTE. There is more information on writing the lexer code (steps 4 and 5, here) in the documentation for Scintilla.

Don't bother about steps which are for configurations you don't use all 6 makefiles - I'll patch them up later if you want to contribute the lexer.

  1. In scintilla/include/Scintilla.iface, add a lexer ID value:
    val SCLEX_CONF=17
  2. And any lexical class IDs:
    val SCE_CONF_DEFAULT=0
    val SCE_CONF_COMMENT=1
  3. In the scintilla/scripts directory run HFacer.py to regenerate the SciLexer.h file. Alternatively (if you don't want to run a Python script) just add these values to SciLexer.h as #defines and I'll put them in Scintilla.iface.
  4. In the scintilla/src/LexOthers.cxx write a ColouriseConfDoc function similar to one of the other functions such as ColouriseLatexDoc.
    static void ColouriseConfDoc (unsigned int startPos, int length, int initStyle, WordList *[], Accessor &styler) {
  5. At the end of the file associate the lexer ID and name with the function:
    LexerModule lmConf(SCLEX_CONF, ColouriseConfDoc, "conf");
  6. If this is a complex lexer then it may be better off in its own file, in which case clone one of the current files. In the scite/scripts directory run RegenerateSource.py to add the new lexer file to each make file.
  7. To the scite/src/others.properties add an entry to associate the file extension with the lexer:
    lexer.*.conf=conf
    If a new lexer file was created instead of adding to LexOthers, then a new properties file should be created by cloning scite/src/others.properties and modifying that file in the following steps.
  8. Set up the styles:
    # Default
    style.conf.0=fore:#FF0000,bold
    # Comment
    style.conf.1=fore:#007F7F,$(font.comment)
  9. A filter should be added for conf files in scite/src/others.properties: filter.conf=Configuration (.conf)|*.conf|
  10. In scite/src/SciTEGlobal.properties add $(filter.conf) to the definition of open.filter.
  11. To add this language to the Language menu of SciTE, add an entry to the menu.language property including the name of the language and the file extension used most commonly for it.
  12. Build both Scintilla and SciTE.
  13. Share and enjoy

For more extensive information on building lexers, see the instructions in the Scintilla documentation.