|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing an IDL lexer with some additional methods. |
|
8 """ |
|
9 |
|
10 from PyQt6.Qsci import QsciLexerIDL, QsciScintilla |
|
11 |
|
12 from eric7 import Preferences |
|
13 from eric7.QScintilla.Lexers.Lexer import Lexer |
|
14 |
|
15 |
|
16 class LexerIDL(Lexer, QsciLexerIDL): |
|
17 """ |
|
18 Subclass to implement some additional lexer dependant methods. |
|
19 """ |
|
20 |
|
21 def __init__(self, parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param parent parent widget of this lexer |
|
26 """ |
|
27 QsciLexerIDL.__init__(self, parent) |
|
28 Lexer.__init__(self) |
|
29 |
|
30 self.commentString = "//" |
|
31 self.streamCommentString = {"start": "/* ", "end": " */"} |
|
32 self.boxCommentString = {"start": "/* ", "middle": " * ", "end": " */"} |
|
33 |
|
34 self.keywordSetDescriptions = [ |
|
35 self.tr("Primary keywords and identifiers"), |
|
36 self.tr("Secondary keywords and identifiers"), |
|
37 self.tr("Documentation comment keywords"), |
|
38 self.tr("Global classes and typedefs"), |
|
39 self.tr("Preprocessor definitions"), |
|
40 self.tr("Task marker and error marker keywords"), |
|
41 ] |
|
42 |
|
43 def initProperties(self): |
|
44 """ |
|
45 Public slot to initialize the properties. |
|
46 """ |
|
47 self.setFoldComments(Preferences.getEditor("CppFoldComment")) |
|
48 self.setFoldPreprocessor(Preferences.getEditor("CppFoldPreprocessor")) |
|
49 self.setFoldAtElse(Preferences.getEditor("CppFoldAtElse")) |
|
50 indentStyle = 0 |
|
51 if Preferences.getEditor("CppIndentOpeningBrace"): |
|
52 indentStyle |= QsciScintilla.AiOpening |
|
53 if Preferences.getEditor("CppIndentClosingBrace"): |
|
54 indentStyle |= QsciScintilla.AiClosing |
|
55 self.setAutoIndentStyle(indentStyle) |
|
56 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
|
57 |
|
58 def isCommentStyle(self, style): |
|
59 """ |
|
60 Public method to check, if a style is a comment style. |
|
61 |
|
62 @param style style to check (integer) |
|
63 @return flag indicating a comment style (boolean) |
|
64 """ |
|
65 return style in [ |
|
66 QsciLexerIDL.Comment, |
|
67 QsciLexerIDL.CommentDoc, |
|
68 QsciLexerIDL.CommentLine, |
|
69 QsciLexerIDL.CommentLineDoc, |
|
70 ] |
|
71 |
|
72 def isStringStyle(self, style): |
|
73 """ |
|
74 Public method to check, if a style is a string style. |
|
75 |
|
76 @param style style to check (integer) |
|
77 @return flag indicating a string style (boolean) |
|
78 """ |
|
79 return style in [ |
|
80 QsciLexerIDL.DoubleQuotedString, |
|
81 QsciLexerIDL.SingleQuotedString, |
|
82 QsciLexerIDL.UnclosedString, |
|
83 QsciLexerIDL.VerbatimString, |
|
84 ] |
|
85 |
|
86 def defaultKeywords(self, kwSet): |
|
87 """ |
|
88 Public method to get the default keywords. |
|
89 |
|
90 @param kwSet number of the keyword set (integer) |
|
91 @return string giving the keywords (string) or None |
|
92 """ |
|
93 return QsciLexerIDL.keywords(self, kwSet) |
|
94 |
|
95 def maximumKeywordSet(self): |
|
96 """ |
|
97 Public method to get the maximum keyword set. |
|
98 |
|
99 @return maximum keyword set (integer) |
|
100 """ |
|
101 return 4 |