Mercurial > octave
comparison libgui/languages/build_ts/octave-qsci/Qsci/qscilexerpython.h @ 31537:5ceb4bfcdb0f stable
add tools and files for updating the gui's language files for translation
* libgui/languages/build_ts/README.md: readme for updating language files
* libgui/languages/build_ts/octave-qsci: QScintilla source files for
languages without translation provided by QScintilla
* libgui/languages/build_ts/octave-qt: Qt source files for languages
without translation provided by Qt
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Thu, 24 Nov 2022 06:48:25 +0100 |
parents | |
children | dd5ece3664ed |
comparison
equal
deleted
inserted
replaced
31535:4b80982e0af8 | 31537:5ceb4bfcdb0f |
---|---|
1 // This defines the interface to the QsciLexerPython class. | |
2 // | |
3 // Copyright (c) 2019 Riverbank Computing Limited <info@riverbankcomputing.com> | |
4 // | |
5 // This file is part of QScintilla. | |
6 // | |
7 // This file may be used under the terms of the GNU General Public License | |
8 // version 3.0 as published by the Free Software Foundation and appearing in | |
9 // the file LICENSE included in the packaging of this file. Please review the | |
10 // following information to ensure the GNU General Public License version 3.0 | |
11 // requirements will be met: http://www.gnu.org/copyleft/gpl.html. | |
12 // | |
13 // If you do not wish to use this file under the terms of the GPL version 3.0 | |
14 // then you may purchase a commercial license. For more information contact | |
15 // info@riverbankcomputing.com. | |
16 // | |
17 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
18 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
19 | |
20 | |
21 #ifndef QSCILEXERPYTHON_H | |
22 #define QSCILEXERPYTHON_H | |
23 | |
24 #include <QObject> | |
25 | |
26 #include <Qsci/qsciglobal.h> | |
27 #include <Qsci/qscilexer.h> | |
28 #include "Qsci/qsciscintillabase.h" | |
29 | |
30 | |
31 //! \brief The QsciLexerPython class encapsulates the Scintilla Python lexer. | |
32 class QSCINTILLA_EXPORT QsciLexerPython : public QsciLexer | |
33 { | |
34 Q_OBJECT | |
35 | |
36 public: | |
37 //! This enum defines the meanings of the different styles used by the | |
38 //! Python lexer. | |
39 enum { | |
40 //! The default. | |
41 Default = 0, | |
42 | |
43 //! A comment. | |
44 Comment = 1, | |
45 | |
46 //! A number. | |
47 Number = 2, | |
48 | |
49 //! A double-quoted string. | |
50 DoubleQuotedString = 3, | |
51 | |
52 //! A single-quoted string. | |
53 SingleQuotedString = 4, | |
54 | |
55 //! A keyword. | |
56 Keyword = 5, | |
57 | |
58 //! A triple single-quoted string. | |
59 TripleSingleQuotedString = 6, | |
60 | |
61 //! A triple double-quoted string. | |
62 TripleDoubleQuotedString = 7, | |
63 | |
64 //! The name of a class. | |
65 ClassName = 8, | |
66 | |
67 //! The name of a function or method. | |
68 FunctionMethodName = 9, | |
69 | |
70 //! An operator. | |
71 Operator = 10, | |
72 | |
73 //! An identifier | |
74 Identifier = 11, | |
75 | |
76 //! A comment block. | |
77 CommentBlock = 12, | |
78 | |
79 //! The end of a line where a string is not closed. | |
80 UnclosedString = 13, | |
81 | |
82 //! A highlighted identifier. These are defined by keyword set | |
83 //! 2. Reimplement keywords() to define keyword set 2. | |
84 HighlightedIdentifier = 14, | |
85 | |
86 //! A decorator. | |
87 Decorator = 15, | |
88 | |
89 //! A double-quoted f-string. | |
90 DoubleQuotedFString = 16, | |
91 | |
92 //! A single-quoted f-string. | |
93 SingleQuotedFString = 17, | |
94 | |
95 //! A triple single-quoted f-string. | |
96 TripleSingleQuotedFString = 18, | |
97 | |
98 //! A triple double-quoted f-string. | |
99 TripleDoubleQuotedFString = 19, | |
100 }; | |
101 | |
102 //! This enum defines the different conditions that can cause | |
103 //! indentations to be displayed as being bad. | |
104 enum IndentationWarning { | |
105 //! Bad indentation is not displayed differently. | |
106 NoWarning = 0, | |
107 | |
108 //! The indentation is inconsistent when compared to the | |
109 //! previous line, ie. it is made up of a different combination | |
110 //! of tabs and/or spaces. | |
111 Inconsistent = 1, | |
112 | |
113 //! The indentation is made up of spaces followed by tabs. | |
114 TabsAfterSpaces = 2, | |
115 | |
116 //! The indentation contains spaces. | |
117 Spaces = 3, | |
118 | |
119 //! The indentation contains tabs. | |
120 Tabs = 4 | |
121 }; | |
122 | |
123 //! Construct a QsciLexerPython with parent \a parent. \a parent is | |
124 //! typically the QsciScintilla instance. | |
125 QsciLexerPython(QObject *parent = 0); | |
126 | |
127 //! Destroys the QsciLexerPython instance. | |
128 virtual ~QsciLexerPython(); | |
129 | |
130 //! Returns the name of the language. | |
131 const char *language() const; | |
132 | |
133 //! Returns the name of the lexer. Some lexers support a number of | |
134 //! languages. | |
135 const char *lexer() const; | |
136 | |
137 //! \internal Returns the character sequences that can separate | |
138 //! auto-completion words. | |
139 QStringList autoCompletionWordSeparators() const; | |
140 | |
141 //! \internal Returns the number of lines prior to the current one when | |
142 //! determining the scope of a block when auto-indenting. | |
143 int blockLookback() const; | |
144 | |
145 //! \internal Returns a space separated list of words or characters in | |
146 //! a particular style that define the start of a block for | |
147 //! auto-indentation. The styles is returned via \a style. | |
148 const char *blockStart(int *style = 0) const; | |
149 | |
150 //! \internal Returns the style used for braces for brace matching. | |
151 int braceStyle() const; | |
152 | |
153 //! Returns the foreground colour of the text for style number \a style. | |
154 //! | |
155 //! \sa defaultPaper() | |
156 QColor defaultColor(int style) const; | |
157 | |
158 //! Returns the end-of-line fill for style number \a style. | |
159 bool defaultEolFill(int style) const; | |
160 | |
161 //! Returns the font for style number \a style. | |
162 QFont defaultFont(int style) const; | |
163 | |
164 //! Returns the background colour of the text for style number \a style. | |
165 //! | |
166 //! \sa defaultColor() | |
167 QColor defaultPaper(int style) const; | |
168 | |
169 //! \internal Returns the view used for indentation guides. | |
170 virtual int indentationGuideView() const; | |
171 | |
172 //! Returns the set of keywords for the keyword set \a set recognised | |
173 //! by the lexer as a space separated string. | |
174 const char *keywords(int set) const; | |
175 | |
176 //! Returns the descriptive name for style number \a style. If the | |
177 //! style is invalid for this language then an empty QString is returned. | |
178 //! This is intended to be used in user preference dialogs. | |
179 QString description(int style) const; | |
180 | |
181 //! Causes all properties to be refreshed by emitting the | |
182 //! propertyChanged() signal as required. | |
183 void refreshProperties(); | |
184 | |
185 //! Returns true if indented comment blocks can be folded. | |
186 //! | |
187 //! \sa setFoldComments() | |
188 bool foldComments() const {return fold_comments;} | |
189 | |
190 //! If \a fold is true then trailing blank lines are included in a fold | |
191 //! block. The default is true. | |
192 //! | |
193 //! \sa foldCompact() | |
194 void setFoldCompact(bool fold); | |
195 | |
196 //! Returns true if trailing blank lines are included in a fold block. | |
197 //! | |
198 //! \sa setFoldCompact() | |
199 bool foldCompact() const {return fold_compact;} | |
200 | |
201 //! Returns true if triple quoted strings can be folded. | |
202 //! | |
203 //! \sa setFoldQuotes() | |
204 bool foldQuotes() const {return fold_quotes;} | |
205 | |
206 //! Returns the condition that will cause bad indentations to be | |
207 //! displayed. | |
208 //! | |
209 //! \sa setIndentationWarning() | |
210 QsciLexerPython::IndentationWarning indentationWarning() const {return indent_warn;} | |
211 | |
212 //! If \a enabled is true then sub-identifiers defined in keyword set 2 | |
213 //! will be highlighted. For example, if it is false and "open" is defined | |
214 //! in keyword set 2 then "foo.open" will not be highlighted. The default | |
215 //! is true. | |
216 //! | |
217 //! \sa highlightSubidentifiers() | |
218 void setHighlightSubidentifiers(bool enabled); | |
219 | |
220 //! Returns true if string literals are allowed to span newline characters. | |
221 //! | |
222 //! \sa setHighlightSubidentifiers() | |
223 bool highlightSubidentifiers() const {return highlight_subids;} | |
224 | |
225 //! If \a allowed is true then string literals are allowed to span newline | |
226 //! characters. The default is false. | |
227 //! | |
228 //! \sa stringsOverNewlineAllowed() | |
229 void setStringsOverNewlineAllowed(bool allowed); | |
230 | |
231 //! Returns true if string literals are allowed to span newline characters. | |
232 //! | |
233 //! \sa setStringsOverNewlineAllowed() | |
234 bool stringsOverNewlineAllowed() const {return strings_over_newline;} | |
235 | |
236 //! If \a allowed is true then Python v2 unicode string literals (e.g. | |
237 //! u"utf8") are allowed. The default is true. | |
238 //! | |
239 //! \sa v2UnicodeAllowed() | |
240 void setV2UnicodeAllowed(bool allowed); | |
241 | |
242 //! Returns true if Python v2 unicode string literals (e.g. u"utf8") are | |
243 //! allowed. | |
244 //! | |
245 //! \sa setV2UnicodeAllowed() | |
246 bool v2UnicodeAllowed() const {return v2_unicode;} | |
247 | |
248 //! If \a allowed is true then Python v3 binary and octal literals (e.g. | |
249 //! 0b1011, 0o712) are allowed. The default is true. | |
250 //! | |
251 //! \sa v3BinaryOctalAllowed() | |
252 void setV3BinaryOctalAllowed(bool allowed); | |
253 | |
254 //! Returns true if Python v3 binary and octal literals (e.g. 0b1011, | |
255 //! 0o712) are allowed. | |
256 //! | |
257 //! \sa setV3BinaryOctalAllowed() | |
258 bool v3BinaryOctalAllowed() const {return v3_binary_octal;} | |
259 | |
260 //! If \a allowed is true then Python v3 bytes string literals (e.g. | |
261 //! b"bytes") are allowed. The default is true. | |
262 //! | |
263 //! \sa v3BytesAllowed() | |
264 void setV3BytesAllowed(bool allowed); | |
265 | |
266 //! Returns true if Python v3 bytes string literals (e.g. b"bytes") are | |
267 //! allowed. | |
268 //! | |
269 //! \sa setV3BytesAllowed() | |
270 bool v3BytesAllowed() const {return v3_bytes;} | |
271 | |
272 public slots: | |
273 //! If \a fold is true then indented comment blocks can be folded. The | |
274 //! default is false. | |
275 //! | |
276 //! \sa foldComments() | |
277 virtual void setFoldComments(bool fold); | |
278 | |
279 //! If \a fold is true then triple quoted strings can be folded. The | |
280 //! default is false. | |
281 //! | |
282 //! \sa foldQuotes() | |
283 virtual void setFoldQuotes(bool fold); | |
284 | |
285 //! Sets the condition that will cause bad indentations to be | |
286 //! displayed. | |
287 //! | |
288 //! \sa indentationWarning() | |
289 virtual void setIndentationWarning(QsciLexerPython::IndentationWarning warn); | |
290 | |
291 protected: | |
292 //! The lexer's properties are read from the settings \a qs. \a prefix | |
293 //! (which has a trailing '/') should be used as a prefix to the key of | |
294 //! each setting. true is returned if there is no error. | |
295 //! | |
296 bool readProperties(QSettings &qs,const QString &prefix); | |
297 | |
298 //! The lexer's properties are written to the settings \a qs. | |
299 //! \a prefix (which has a trailing '/') should be used as a prefix to | |
300 //! the key of each setting. true is returned if there is no error. | |
301 //! | |
302 bool writeProperties(QSettings &qs,const QString &prefix) const; | |
303 | |
304 private: | |
305 void setCommentProp(); | |
306 void setCompactProp(); | |
307 void setQuotesProp(); | |
308 void setTabWhingeProp(); | |
309 void setStringsOverNewlineProp(); | |
310 void setV2UnicodeProp(); | |
311 void setV3BinaryOctalProp(); | |
312 void setV3BytesProp(); | |
313 void setHighlightSubidsProp(); | |
314 | |
315 bool fold_comments; | |
316 bool fold_compact; | |
317 bool fold_quotes; | |
318 IndentationWarning indent_warn; | |
319 bool strings_over_newline; | |
320 bool v2_unicode; | |
321 bool v3_binary_octal; | |
322 bool v3_bytes; | |
323 bool highlight_subids; | |
324 | |
325 friend class QsciLexerHTML; | |
326 | |
327 static const char *keywordClass; | |
328 | |
329 QsciLexerPython(const QsciLexerPython &); | |
330 QsciLexerPython &operator=(const QsciLexerPython &); | |
331 }; | |
332 | |
333 #endif |