|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a base class for custom lexers. |
|
8 """ |
|
9 |
|
10 from PyQt5.Qsci import QsciLexer |
|
11 |
|
12 from .Lexer import Lexer |
|
13 |
|
14 |
|
15 class LexerContainer(Lexer, QsciLexer): |
|
16 """ |
|
17 Subclass as a base for the implementation of custom lexers. |
|
18 """ |
|
19 def __init__(self, parent=None): |
|
20 """ |
|
21 Constructor |
|
22 |
|
23 @param parent parent widget of this lexer |
|
24 """ |
|
25 QsciLexer.__init__(self, parent) |
|
26 Lexer.__init__(self) |
|
27 |
|
28 self.editor = parent |
|
29 |
|
30 def language(self): |
|
31 """ |
|
32 Public method returning the language of the lexer. |
|
33 |
|
34 @return language of the lexer (string) |
|
35 """ |
|
36 return "Container" |
|
37 |
|
38 def lexer(self): |
|
39 """ |
|
40 Public method returning the type of the lexer. |
|
41 |
|
42 @return type of the lexer (string) |
|
43 """ |
|
44 if hasattr(self, 'lexerId'): |
|
45 return None |
|
46 else: |
|
47 return "container" |
|
48 |
|
49 def description(self, style): |
|
50 """ |
|
51 Public method returning the descriptions of the styles supported |
|
52 by the lexer. |
|
53 |
|
54 <b>Note</b>: This methods needs to be overridden by the lexer class. |
|
55 |
|
56 @param style style number (integer) |
|
57 @return description for the given style (string) |
|
58 """ |
|
59 return "" |
|
60 |
|
61 def styleText(self, start, end): |
|
62 """ |
|
63 Public method to perform the styling. |
|
64 |
|
65 @param start position of first character to be styled (integer) |
|
66 @param end position of last character to be styled (integer) |
|
67 """ |
|
68 self.editor.startStyling(start, 0x1f) |
|
69 self.editor.setStyling(end - start + 1, 0) |
|
70 |
|
71 def keywords(self, kwSet): |
|
72 """ |
|
73 Public method to get the keywords. |
|
74 |
|
75 @param kwSet number of the keyword set (integer) |
|
76 @return string giving the keywords (string) or None |
|
77 """ |
|
78 return Lexer.keywords(self, kwSet) |