Building a custom lexer involves several steps. We’ll go through them one-by-one. The lexer we’re going to build here will be very simple. It’s sole purpose is showing you the basics.
Everything starts at the
__init__(: The constructor is typically where you create style-objects. self, parent)
language(: This method must return the name of the language. You have to implement it, but what it actually gets used for is unclear to me. self)
description(: Returns the descriptive name for a given style. self, style_nr)
styleText(: Gets called everytime editors text has changed. Here you implement syntax highlighting! self, start, end)
class MyLexer(QsciLexerCustom): def __init__(
self, parent): super(MyLexer, self).__init__( parent) [...] '''''' def language( self): [...] '''''' def description( self, style): [...] '''''' def styleText( self, start, end): # Called everytime the editors text has changed [...] '''''' '''--- end class ---'''
The following pages treat these topics one-by-one.