A lexer is an object governing the styling of the various elements of the source code. In other words it is the “syntax highlighting” that discover elements in the text and applies styles.
The Lexer classes simply encapsulates various style elements [1] for example:
Take the LexerPython, it has various attributes... it can recognize in the document the “commentline”, “commands”, “number”, and apply styles to them. In the attribute is defined the style.
>>> lp = LexerPython()
>>> lp.comment
< TextStyle >
To set a lexer:
>>> s = Scintilla()
>>> s.set_lexer("python")
>>> s.set_lexer(LexerPython()) # alternative
To customize a lexer with styles that you want you have to subclass it in this manner:
class customLexer(LexerPython):
def __init__(self):
super(customLexer,self).__init__()
self.comment = TextStyle(color = "blue", bold = True, italic = True)
self.number = TextStyle(color = "green")
and then you have to apply the lexer:
>>> s.set_lexer(customLexer())
[1] | Lexer class is a mere data container, the styles are applied with the set_lexer() method |