17 |
17 |
18 class LexerCPP(SubstyledLexer, QsciLexerCPP): |
18 class LexerCPP(SubstyledLexer, QsciLexerCPP): |
19 """ |
19 """ |
20 Subclass to implement some additional lexer dependant methods. |
20 Subclass to implement some additional lexer dependant methods. |
21 """ |
21 """ |
|
22 |
22 def __init__(self, parent=None, caseInsensitiveKeywords=False): |
23 def __init__(self, parent=None, caseInsensitiveKeywords=False): |
23 """ |
24 """ |
24 Constructor |
25 Constructor |
25 |
26 |
26 @param parent parent widget of this lexer |
27 @param parent parent widget of this lexer |
27 @param caseInsensitiveKeywords flag indicating keywords are case |
28 @param caseInsensitiveKeywords flag indicating keywords are case |
28 insensitive (boolean) |
29 insensitive (boolean) |
29 """ |
30 """ |
30 QsciLexerCPP.__init__(self, parent, caseInsensitiveKeywords) |
31 QsciLexerCPP.__init__(self, parent, caseInsensitiveKeywords) |
31 SubstyledLexer.__init__(self) |
32 SubstyledLexer.__init__(self) |
32 |
33 |
33 self.commentString = "//" |
34 self.commentString = "//" |
34 self.streamCommentString = { |
35 self.streamCommentString = {"start": "/* ", "end": " */"} |
35 'start': '/* ', |
36 self.boxCommentString = {"start": "/* ", "middle": " * ", "end": " */"} |
36 'end': ' */' |
37 |
37 } |
|
38 self.boxCommentString = { |
|
39 'start': '/* ', |
|
40 'middle': ' * ', |
|
41 'end': ' */' |
|
42 } |
|
43 |
|
44 self.keywordSetDescriptions = [ |
38 self.keywordSetDescriptions = [ |
45 self.tr("Primary keywords and identifiers"), |
39 self.tr("Primary keywords and identifiers"), |
46 self.tr("Secondary keywords and identifiers"), |
40 self.tr("Secondary keywords and identifiers"), |
47 self.tr("Documentation comment keywords"), |
41 self.tr("Documentation comment keywords"), |
48 self.tr("Global classes and typedefs"), |
42 self.tr("Global classes and typedefs"), |
49 self.tr("Preprocessor definitions"), |
43 self.tr("Preprocessor definitions"), |
50 self.tr("Task marker and error marker keywords"), |
44 self.tr("Task marker and error marker keywords"), |
51 ] |
45 ] |
52 |
46 |
53 ############################################################## |
47 ############################################################## |
54 ## default sub-style definitions |
48 ## default sub-style definitions |
55 ############################################################## |
49 ############################################################## |
56 |
50 |
57 diffToSecondary = 0x40 |
51 diffToSecondary = 0x40 |
58 # This may need to be changed to be in line with Scintilla C++ lexer. |
52 # This may need to be changed to be in line with Scintilla C++ lexer. |
59 |
53 |
60 # list of style numbers, that support sub-styling |
54 # list of style numbers, that support sub-styling |
61 self.baseStyles = [11, 17, 11 + diffToSecondary, 17 + diffToSecondary] |
55 self.baseStyles = [11, 17, 11 + diffToSecondary, 17 + diffToSecondary] |
62 |
56 |
63 self.defaultSubStyles = { |
57 self.defaultSubStyles = { |
64 11: { |
58 11: { |
65 0: { |
59 0: { |
66 "Description": self.tr("Additional Identifier"), |
60 "Description": self.tr("Additional Identifier"), |
67 "Words": "std map string vector", |
61 "Words": "std map string vector", |
68 "Style": { |
62 "Style": { |
69 "fore": 0xEE00AA, |
63 "fore": 0xEE00AA, |
70 } |
64 }, |
71 }, |
65 }, |
72 }, |
66 }, |
73 17: { |
67 17: { |
74 0: { |
68 0: { |
75 "Description": self.tr("Additional JavaDoc keyword"), |
69 "Description": self.tr("Additional JavaDoc keyword"), |
76 "Words": "check", |
70 "Words": "check", |
77 "Style": { |
71 "Style": { |
78 "fore": 0x00AAEE, |
72 "fore": 0x00AAEE, |
79 } |
73 }, |
80 }, |
74 }, |
81 }, |
75 }, |
82 11 + diffToSecondary: { |
76 11 |
|
77 + diffToSecondary: { |
83 0: { |
78 0: { |
84 "Description": self.tr("Inactive additional identifier"), |
79 "Description": self.tr("Inactive additional identifier"), |
85 "Words": "std map string vector", |
80 "Words": "std map string vector", |
86 "Style": { |
81 "Style": { |
87 "fore": 0xBB6666, |
82 "fore": 0xBB6666, |
88 } |
83 }, |
89 }, |
84 }, |
90 }, |
85 }, |
91 17 + diffToSecondary: { |
86 17 |
|
87 + diffToSecondary: { |
92 0: { |
88 0: { |
93 "Description": self.tr( |
89 "Description": self.tr("Inactive additional JavaDoc keyword"), |
94 "Inactive additional JavaDoc keyword"), |
|
95 "Words": "check", |
90 "Words": "check", |
96 "Style": { |
91 "Style": { |
97 "fore": 0x6699AA, |
92 "fore": 0x6699AA, |
98 } |
93 }, |
99 }, |
94 }, |
100 }, |
95 }, |
101 } |
96 } |
102 |
97 |
103 def initProperties(self): |
98 def initProperties(self): |
115 self.setAutoIndentStyle(indentStyle) |
110 self.setAutoIndentStyle(indentStyle) |
116 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
111 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
117 with contextlib.suppress(AttributeError): |
112 with contextlib.suppress(AttributeError): |
118 self.setDollarsAllowed(Preferences.getEditor("CppDollarsAllowed")) |
113 self.setDollarsAllowed(Preferences.getEditor("CppDollarsAllowed")) |
119 with contextlib.suppress(AttributeError): |
114 with contextlib.suppress(AttributeError): |
120 self.setStylePreprocessor( |
115 self.setStylePreprocessor(Preferences.getEditor("CppStylePreprocessor")) |
121 Preferences.getEditor("CppStylePreprocessor")) |
|
122 with contextlib.suppress(AttributeError): |
116 with contextlib.suppress(AttributeError): |
123 self.setHighlightTripleQuotedStrings( |
117 self.setHighlightTripleQuotedStrings( |
124 Preferences.getEditor("CppHighlightTripleQuotedStrings")) |
118 Preferences.getEditor("CppHighlightTripleQuotedStrings") |
|
119 ) |
125 with contextlib.suppress(AttributeError): |
120 with contextlib.suppress(AttributeError): |
126 self.setHighlightHashQuotedStrings( |
121 self.setHighlightHashQuotedStrings( |
127 Preferences.getEditor("CppHighlightHashQuotedStrings")) |
122 Preferences.getEditor("CppHighlightHashQuotedStrings") |
|
123 ) |
128 with contextlib.suppress(AttributeError): |
124 with contextlib.suppress(AttributeError): |
129 self.setHighlightBackQuotedStrings( |
125 self.setHighlightBackQuotedStrings( |
130 Preferences.getEditor("CppHighlightBackQuotedStrings")) |
126 Preferences.getEditor("CppHighlightBackQuotedStrings") |
|
127 ) |
131 with contextlib.suppress(AttributeError): |
128 with contextlib.suppress(AttributeError): |
132 self.setHighlightEscapeSequences( |
129 self.setHighlightEscapeSequences( |
133 Preferences.getEditor("CppHighlightEscapeSequences")) |
130 Preferences.getEditor("CppHighlightEscapeSequences") |
|
131 ) |
134 with contextlib.suppress(AttributeError): |
132 with contextlib.suppress(AttributeError): |
135 self.setVerbatimStringEscapeSequencesAllowed( |
133 self.setVerbatimStringEscapeSequencesAllowed( |
136 Preferences.getEditor( |
134 Preferences.getEditor("CppVerbatimStringEscapeSequencesAllowed") |
137 "CppVerbatimStringEscapeSequencesAllowed")) |
135 ) |
138 |
136 |
139 def autoCompletionWordSeparators(self): |
137 def autoCompletionWordSeparators(self): |
140 """ |
138 """ |
141 Public method to return the list of separators for autocompletion. |
139 Public method to return the list of separators for autocompletion. |
142 |
140 |
143 @return list of separators (list of strings) |
141 @return list of separators (list of strings) |
144 """ |
142 """ |
145 return ['::', '->', '.'] |
143 return ["::", "->", "."] |
146 |
144 |
147 def isCommentStyle(self, style): |
145 def isCommentStyle(self, style): |
148 """ |
146 """ |
149 Public method to check, if a style is a comment style. |
147 Public method to check, if a style is a comment style. |
150 |
148 |
151 @param style style to check (integer) |
149 @param style style to check (integer) |
152 @return flag indicating a comment style (boolean) |
150 @return flag indicating a comment style (boolean) |
153 """ |
151 """ |
154 return style in [QsciLexerCPP.Comment, |
152 return style in [ |
155 QsciLexerCPP.CommentDoc, |
153 QsciLexerCPP.Comment, |
156 QsciLexerCPP.CommentLine, |
154 QsciLexerCPP.CommentDoc, |
157 QsciLexerCPP.CommentLineDoc] |
155 QsciLexerCPP.CommentLine, |
158 |
156 QsciLexerCPP.CommentLineDoc, |
|
157 ] |
|
158 |
159 def isStringStyle(self, style): |
159 def isStringStyle(self, style): |
160 """ |
160 """ |
161 Public method to check, if a style is a string style. |
161 Public method to check, if a style is a string style. |
162 |
162 |
163 @param style style to check (integer) |
163 @param style style to check (integer) |
164 @return flag indicating a string style (boolean) |
164 @return flag indicating a string style (boolean) |
165 """ |
165 """ |
166 return style in [QsciLexerCPP.DoubleQuotedString, |
166 return style in [ |
167 QsciLexerCPP.SingleQuotedString, |
167 QsciLexerCPP.DoubleQuotedString, |
168 QsciLexerCPP.UnclosedString, |
168 QsciLexerCPP.SingleQuotedString, |
169 QsciLexerCPP.VerbatimString] |
169 QsciLexerCPP.UnclosedString, |
170 |
170 QsciLexerCPP.VerbatimString, |
|
171 ] |
|
172 |
171 def defaultKeywords(self, kwSet): |
173 def defaultKeywords(self, kwSet): |
172 """ |
174 """ |
173 Public method to get the default keywords. |
175 Public method to get the default keywords. |
174 |
176 |
175 @param kwSet number of the keyword set (integer) |
177 @param kwSet number of the keyword set (integer) |
176 @return string giving the keywords (string) or None |
178 @return string giving the keywords (string) or None |
177 """ |
179 """ |
178 return QsciLexerCPP.keywords(self, kwSet) |
180 return QsciLexerCPP.keywords(self, kwSet) |
179 |
181 |
180 def maximumKeywordSet(self): |
182 def maximumKeywordSet(self): |
181 """ |
183 """ |
182 Public method to get the maximum keyword set. |
184 Public method to get the maximum keyword set. |
183 |
185 |
184 @return maximum keyword set (integer) |
186 @return maximum keyword set (integer) |
185 """ |
187 """ |
186 return 4 |
188 return 4 |