eric6/QScintilla/Lexers/LexerCPP.py

changeset 6942
2602857055c5
parent 6874
5a3a39442711
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a CPP lexer with some additional methods.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.Qsci import QsciLexerCPP, QsciScintilla
13
14 from .SubstyledLexer import SubstyledLexer
15 import Preferences
16
17
18 class LexerCPP(SubstyledLexer, QsciLexerCPP):
19 """
20 Subclass to implement some additional lexer dependant methods.
21 """
22 def __init__(self, parent=None, caseInsensitiveKeywords=False):
23 """
24 Constructor
25
26 @param parent parent widget of this lexer
27 @param caseInsensitiveKeywords flag indicating keywords are case
28 insensitive (boolean)
29 """
30 QsciLexerCPP.__init__(self, parent, caseInsensitiveKeywords)
31 SubstyledLexer.__init__(self)
32
33 self.commentString = "//"
34 self.streamCommentString = {
35 'start': '/* ',
36 'end': ' */'
37 }
38 self.boxCommentString = {
39 'start': '/* ',
40 'middle': ' * ',
41 'end': ' */'
42 }
43
44 self.keywordSetDescriptions = [
45 self.tr("Primary keywords and identifiers"),
46 self.tr("Secondary keywords and identifiers"),
47 self.tr("Documentation comment keywords"),
48 self.tr("Global classes and typedefs"),
49 self.tr("Preprocessor definitions"),
50 self.tr("Task marker and error marker keywords"),
51 ]
52
53 ##############################################################
54 ## default sub-style definitions
55 ##############################################################
56
57 diffToSecondary = 0x40
58 # This may need to be changed to be in line with Scintilla C++ lexer.
59
60 # list of style numbers, that support sub-styling
61 self.baseStyles = [11, 17, 11 + diffToSecondary, 17 + diffToSecondary]
62
63 self.defaultSubStyles = {
64 11: {
65 0: {
66 "Description": self.tr("Additional Identifier"),
67 "Words": "std map string vector",
68 "Style": {
69 "fore": 0xEE00AA,
70 }
71 },
72 },
73 17: {
74 0: {
75 "Description": self.tr("Additional JavaDoc keyword"),
76 "Words": "check",
77 "Style": {
78 "fore": 0x00AAEE,
79 }
80 },
81 },
82 11 + diffToSecondary: {
83 0: {
84 "Description": self.tr("Inactive additional identifier"),
85 "Words": "std map string vector",
86 "Style": {
87 "fore": 0xBB6666,
88 }
89 },
90 },
91 17 + diffToSecondary: {
92 0: {
93 "Description": self.tr(
94 "Inactive additional JavaDoc keyword"),
95 "Words": "check",
96 "Style": {
97 "fore": 0x6699AA,
98 }
99 },
100 },
101 }
102
103 def initProperties(self):
104 """
105 Public slot to initialize the properties.
106 """
107 self.setFoldComments(Preferences.getEditor("CppFoldComment"))
108 self.setFoldPreprocessor(Preferences.getEditor("CppFoldPreprocessor"))
109 self.setFoldAtElse(Preferences.getEditor("CppFoldAtElse"))
110 indentStyle = 0
111 if Preferences.getEditor("CppIndentOpeningBrace"):
112 indentStyle |= QsciScintilla.AiOpening
113 if Preferences.getEditor("CppIndentClosingBrace"):
114 indentStyle |= QsciScintilla.AiClosing
115 self.setAutoIndentStyle(indentStyle)
116 self.setFoldCompact(Preferences.getEditor("AllFoldCompact"))
117 try:
118 self.setDollarsAllowed(Preferences.getEditor("CppDollarsAllowed"))
119 except AttributeError:
120 pass
121 try:
122 self.setStylePreprocessor(
123 Preferences.getEditor("CppStylePreprocessor"))
124 except AttributeError:
125 pass
126 try:
127 self.setHighlightTripleQuotedStrings(
128 Preferences.getEditor("CppHighlightTripleQuotedStrings"))
129 except AttributeError:
130 pass
131 try:
132 self.setHighlightHashQuotedStrings(
133 Preferences.getEditor("CppHighlightHashQuotedStrings"))
134 except AttributeError:
135 pass
136 try:
137 self.setHighlightBackQuotedStrings(
138 Preferences.getEditor("CppHighlightBackQuotedStrings"))
139 except AttributeError:
140 pass
141 try:
142 self.setHighlightEscapeSequences(
143 Preferences.getEditor("CppHighlightEscapeSequences"))
144 except AttributeError:
145 pass
146 try:
147 self.setVerbatimStringEscapeSequencesAllowed(
148 Preferences.getEditor(
149 "CppVerbatimStringEscapeSequencesAllowed"))
150 except AttributeError:
151 pass
152
153 def autoCompletionWordSeparators(self):
154 """
155 Public method to return the list of separators for autocompletion.
156
157 @return list of separators (list of strings)
158 """
159 return ['::', '->', '.']
160
161 def isCommentStyle(self, style):
162 """
163 Public method to check, if a style is a comment style.
164
165 @param style style to check (integer)
166 @return flag indicating a comment style (boolean)
167 """
168 return style in [QsciLexerCPP.Comment,
169 QsciLexerCPP.CommentDoc,
170 QsciLexerCPP.CommentLine,
171 QsciLexerCPP.CommentLineDoc]
172
173 def isStringStyle(self, style):
174 """
175 Public method to check, if a style is a string style.
176
177 @param style style to check (integer)
178 @return flag indicating a string style (boolean)
179 """
180 return style in [QsciLexerCPP.DoubleQuotedString,
181 QsciLexerCPP.SingleQuotedString,
182 QsciLexerCPP.UnclosedString,
183 QsciLexerCPP.VerbatimString]
184
185 def defaultKeywords(self, kwSet):
186 """
187 Public method to get the default keywords.
188
189 @param kwSet number of the keyword set (integer)
190 @return string giving the keywords (string) or None
191 """
192 return QsciLexerCPP.keywords(self, kwSet)
193
194 def maximumKeywordSet(self):
195 """
196 Public method to get the maximum keyword set.
197
198 @return maximum keyword set (integer)
199 """
200 return 4

eric ide

mercurial