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