|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a XML lexer with some additional methods. |
|
8 """ |
|
9 |
|
10 import contextlib |
|
11 |
|
12 from PyQt6.Qsci import QsciLexerXML |
|
13 |
|
14 from .Lexer import Lexer |
|
15 import Preferences |
|
16 |
|
17 |
|
18 class LexerXML(Lexer, QsciLexerXML): |
|
19 """ |
|
20 Subclass to implement some additional lexer dependant methods. |
|
21 """ |
|
22 def __init__(self, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param parent parent widget of this lexer |
|
27 """ |
|
28 QsciLexerXML.__init__(self, parent) |
|
29 Lexer.__init__(self) |
|
30 |
|
31 self.streamCommentString = { |
|
32 'start': '<!-- ', |
|
33 'end': ' -->' |
|
34 } |
|
35 |
|
36 self.keywordSetDescriptions = [ |
|
37 self.tr(""), |
|
38 self.tr(""), |
|
39 self.tr(""), |
|
40 self.tr(""), |
|
41 self.tr(""), |
|
42 self.tr("SGML and DTD keywords"), |
|
43 ] |
|
44 |
|
45 def initProperties(self): |
|
46 """ |
|
47 Public slot to initialize the properties. |
|
48 """ |
|
49 self.setFoldPreprocessor(Preferences.getEditor("HtmlFoldPreprocessor")) |
|
50 self.setCaseSensitiveTags( |
|
51 Preferences.getEditor("HtmlCaseSensitiveTags")) |
|
52 self.setFoldCompact(Preferences.getEditor("AllFoldCompact")) |
|
53 with contextlib.suppress(AttributeError): |
|
54 self.setFoldScriptComments( |
|
55 Preferences.getEditor("HtmlFoldScriptComments")) |
|
56 self.setFoldScriptHeredocs( |
|
57 Preferences.getEditor("HtmlFoldScriptHeredocs")) |
|
58 self.setScriptsStyled(Preferences.getEditor("XMLStyleScripts")) |
|
59 |
|
60 def isCommentStyle(self, style): |
|
61 """ |
|
62 Public method to check, if a style is a comment style. |
|
63 |
|
64 @param style style to check (integer) |
|
65 @return flag indicating a comment style (boolean) |
|
66 """ |
|
67 return style in [QsciLexerXML.HTMLComment, |
|
68 QsciLexerXML.ASPXCComment, |
|
69 QsciLexerXML.SGMLComment, |
|
70 QsciLexerXML.SGMLParameterComment, |
|
71 QsciLexerXML.JavaScriptComment, |
|
72 QsciLexerXML.JavaScriptCommentDoc, |
|
73 QsciLexerXML.JavaScriptCommentLine, |
|
74 QsciLexerXML.ASPJavaScriptComment, |
|
75 QsciLexerXML.ASPJavaScriptCommentDoc, |
|
76 QsciLexerXML.ASPJavaScriptCommentLine, |
|
77 QsciLexerXML.VBScriptComment, |
|
78 QsciLexerXML.ASPVBScriptComment, |
|
79 QsciLexerXML.PythonComment, |
|
80 QsciLexerXML.ASPPythonComment, |
|
81 QsciLexerXML.PHPComment] |
|
82 |
|
83 def isStringStyle(self, style): |
|
84 """ |
|
85 Public method to check, if a style is a string style. |
|
86 |
|
87 @param style style to check (integer) |
|
88 @return flag indicating a string style (boolean) |
|
89 """ |
|
90 return style in [QsciLexerXML.HTMLDoubleQuotedString, |
|
91 QsciLexerXML.HTMLSingleQuotedString, |
|
92 QsciLexerXML.SGMLDoubleQuotedString, |
|
93 QsciLexerXML.SGMLSingleQuotedString, |
|
94 QsciLexerXML.JavaScriptDoubleQuotedString, |
|
95 QsciLexerXML.JavaScriptSingleQuotedString, |
|
96 QsciLexerXML.JavaScriptUnclosedString, |
|
97 QsciLexerXML.ASPJavaScriptDoubleQuotedString, |
|
98 QsciLexerXML.ASPJavaScriptSingleQuotedString, |
|
99 QsciLexerXML.ASPJavaScriptUnclosedString, |
|
100 QsciLexerXML.VBScriptString, |
|
101 QsciLexerXML.VBScriptUnclosedString, |
|
102 QsciLexerXML.ASPVBScriptString, |
|
103 QsciLexerXML.ASPVBScriptUnclosedString, |
|
104 QsciLexerXML.PythonDoubleQuotedString, |
|
105 QsciLexerXML.PythonSingleQuotedString, |
|
106 QsciLexerXML.PythonTripleDoubleQuotedString, |
|
107 QsciLexerXML.PythonTripleSingleQuotedString, |
|
108 QsciLexerXML.ASPPythonDoubleQuotedString, |
|
109 QsciLexerXML.ASPPythonSingleQuotedString, |
|
110 QsciLexerXML.ASPPythonTripleDoubleQuotedString, |
|
111 QsciLexerXML.ASPPythonTripleSingleQuotedString, |
|
112 QsciLexerXML.PHPDoubleQuotedString, |
|
113 QsciLexerXML.PHPSingleQuotedString] |
|
114 |
|
115 def defaultKeywords(self, kwSet): |
|
116 """ |
|
117 Public method to get the default keywords. |
|
118 |
|
119 @param kwSet number of the keyword set (integer) |
|
120 @return string giving the keywords (string) or None |
|
121 """ |
|
122 return QsciLexerXML.keywords(self, kwSet) |