Mercurial > octave
comparison libgui/languages/build_ts/octave-qsci/qscilexerperl.cpp @ 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 module implements the QsciLexerPerl 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 #include "Qsci/qscilexerperl.h" | |
22 | |
23 #include <qcolor.h> | |
24 #include <qfont.h> | |
25 #include <qsettings.h> | |
26 | |
27 | |
28 // The ctor. | |
29 QsciLexerPerl::QsciLexerPerl(QObject *parent) | |
30 : QsciLexer(parent), | |
31 fold_atelse(false), fold_comments(false), fold_compact(true), | |
32 fold_packages(true), fold_pod_blocks(true) | |
33 { | |
34 } | |
35 | |
36 | |
37 // The dtor. | |
38 QsciLexerPerl::~QsciLexerPerl() | |
39 { | |
40 } | |
41 | |
42 | |
43 // Returns the language name. | |
44 const char *QsciLexerPerl::language() const | |
45 { | |
46 return "Perl"; | |
47 } | |
48 | |
49 | |
50 // Returns the lexer name. | |
51 const char *QsciLexerPerl::lexer() const | |
52 { | |
53 return "perl"; | |
54 } | |
55 | |
56 | |
57 // Return the set of character sequences that can separate auto-completion | |
58 // words. | |
59 QStringList QsciLexerPerl::autoCompletionWordSeparators() const | |
60 { | |
61 QStringList wl; | |
62 | |
63 wl << "::" << "->"; | |
64 | |
65 return wl; | |
66 } | |
67 | |
68 | |
69 // Return the list of characters that can start a block. | |
70 const char *QsciLexerPerl::blockStart(int *style) const | |
71 { | |
72 if (style) | |
73 *style = Operator; | |
74 | |
75 return "{"; | |
76 } | |
77 | |
78 | |
79 // Return the list of characters that can end a block. | |
80 const char *QsciLexerPerl::blockEnd(int *style) const | |
81 { | |
82 if (style) | |
83 *style = Operator; | |
84 | |
85 return "}"; | |
86 } | |
87 | |
88 | |
89 // Return the style used for braces. | |
90 int QsciLexerPerl::braceStyle() const | |
91 { | |
92 return Operator; | |
93 } | |
94 | |
95 | |
96 // Return the string of characters that comprise a word. | |
97 const char *QsciLexerPerl::wordCharacters() const | |
98 { | |
99 return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$@%&"; | |
100 } | |
101 | |
102 | |
103 // Returns the foreground colour of the text for a style. | |
104 QColor QsciLexerPerl::defaultColor(int style) const | |
105 { | |
106 switch (style) | |
107 { | |
108 case Default: | |
109 return QColor(0x80,0x80,0x80); | |
110 | |
111 case Error: | |
112 case Backticks: | |
113 case QuotedStringQX: | |
114 return QColor(0xff,0xff,0x00); | |
115 | |
116 case Comment: | |
117 return QColor(0x00,0x7f,0x00); | |
118 | |
119 case POD: | |
120 case PODVerbatim: | |
121 return QColor(0x00,0x40,0x00); | |
122 | |
123 case Number: | |
124 return QColor(0x00,0x7f,0x7f); | |
125 | |
126 case Keyword: | |
127 return QColor(0x00,0x00,0x7f); | |
128 | |
129 case DoubleQuotedString: | |
130 case SingleQuotedString: | |
131 case SingleQuotedHereDocument: | |
132 case DoubleQuotedHereDocument: | |
133 case BacktickHereDocument: | |
134 case QuotedStringQ: | |
135 case QuotedStringQQ: | |
136 return QColor(0x7f,0x00,0x7f); | |
137 | |
138 case Operator: | |
139 case Identifier: | |
140 case Scalar: | |
141 case Array: | |
142 case Hash: | |
143 case SymbolTable: | |
144 case Regex: | |
145 case Substitution: | |
146 case HereDocumentDelimiter: | |
147 case QuotedStringQR: | |
148 case QuotedStringQW: | |
149 case SubroutinePrototype: | |
150 case Translation: | |
151 return QColor(0x00,0x00,0x00); | |
152 | |
153 case DataSection: | |
154 return QColor(0x60,0x00,0x00); | |
155 | |
156 case FormatIdentifier: | |
157 case FormatBody: | |
158 return QColor(0xc0,0x00,0xc0); | |
159 | |
160 case DoubleQuotedStringVar: | |
161 case RegexVar: | |
162 case SubstitutionVar: | |
163 case BackticksVar: | |
164 case DoubleQuotedHereDocumentVar: | |
165 case BacktickHereDocumentVar: | |
166 case QuotedStringQQVar: | |
167 case QuotedStringQXVar: | |
168 case QuotedStringQRVar: | |
169 return QColor(0xd0, 0x00, 0x00); | |
170 } | |
171 | |
172 return QsciLexer::defaultColor(style); | |
173 } | |
174 | |
175 | |
176 // Returns the end-of-line fill for a style. | |
177 bool QsciLexerPerl::defaultEolFill(int style) const | |
178 { | |
179 switch (style) | |
180 { | |
181 case POD: | |
182 case DataSection: | |
183 case SingleQuotedHereDocument: | |
184 case DoubleQuotedHereDocument: | |
185 case BacktickHereDocument: | |
186 case PODVerbatim: | |
187 case FormatBody: | |
188 case DoubleQuotedHereDocumentVar: | |
189 case BacktickHereDocumentVar: | |
190 return true; | |
191 } | |
192 | |
193 return QsciLexer::defaultEolFill(style); | |
194 } | |
195 | |
196 | |
197 // Returns the font of the text for a style. | |
198 QFont QsciLexerPerl::defaultFont(int style) const | |
199 { | |
200 QFont f; | |
201 | |
202 switch (style) | |
203 { | |
204 case Comment: | |
205 #if defined(Q_OS_WIN) | |
206 f = QFont("Comic Sans MS",9); | |
207 #elif defined(Q_OS_MAC) | |
208 f = QFont("Comic Sans MS", 12); | |
209 #else | |
210 f = QFont("Bitstream Vera Serif",9); | |
211 #endif | |
212 break; | |
213 | |
214 case POD: | |
215 #if defined(Q_OS_WIN) | |
216 f = QFont("Times New Roman",11); | |
217 #elif defined(Q_OS_MAC) | |
218 f = QFont("Times New Roman", 12); | |
219 #else | |
220 f = QFont("Bitstream Charter",10); | |
221 #endif | |
222 break; | |
223 | |
224 case Keyword: | |
225 case Operator: | |
226 case DoubleQuotedHereDocument: | |
227 case FormatIdentifier: | |
228 case RegexVar: | |
229 case SubstitutionVar: | |
230 case BackticksVar: | |
231 case DoubleQuotedHereDocumentVar: | |
232 case BacktickHereDocumentVar: | |
233 case QuotedStringQXVar: | |
234 case QuotedStringQRVar: | |
235 f = QsciLexer::defaultFont(style); | |
236 f.setBold(true); | |
237 break; | |
238 | |
239 case DoubleQuotedString: | |
240 case SingleQuotedString: | |
241 case QuotedStringQQ: | |
242 case PODVerbatim: | |
243 #if defined(Q_OS_WIN) | |
244 f = QFont("Courier New",10); | |
245 #elif defined(Q_OS_MAC) | |
246 f = QFont("Courier", 12); | |
247 #else | |
248 f = QFont("Bitstream Vera Sans Mono",9); | |
249 #endif | |
250 break; | |
251 | |
252 case BacktickHereDocument: | |
253 case SubroutinePrototype: | |
254 f = QsciLexer::defaultFont(style); | |
255 f.setItalic(true); | |
256 break; | |
257 | |
258 case DoubleQuotedStringVar: | |
259 case QuotedStringQQVar: | |
260 #if defined(Q_OS_WIN) | |
261 f = QFont("Courier New",10); | |
262 #elif defined(Q_OS_MAC) | |
263 f = QFont("Courier", 12); | |
264 #else | |
265 f = QFont("Bitstream Vera Sans Mono",9); | |
266 #endif | |
267 f.setBold(true); | |
268 break; | |
269 | |
270 default: | |
271 f = QsciLexer::defaultFont(style); | |
272 } | |
273 | |
274 return f; | |
275 } | |
276 | |
277 | |
278 // Returns the set of keywords. | |
279 const char *QsciLexerPerl::keywords(int set) const | |
280 { | |
281 if (set == 1) | |
282 return | |
283 "NULL __FILE__ __LINE__ __PACKAGE__ __DATA__ __END__ " | |
284 "AUTOLOAD BEGIN CORE DESTROY END EQ GE GT INIT LE LT " | |
285 "NE CHECK abs accept alarm and atan2 bind binmode " | |
286 "bless caller chdir chmod chomp chop chown chr chroot " | |
287 "close closedir cmp connect continue cos crypt " | |
288 "dbmclose dbmopen defined delete die do dump each " | |
289 "else elsif endgrent endhostent endnetent endprotoent " | |
290 "endpwent endservent eof eq eval exec exists exit exp " | |
291 "fcntl fileno flock for foreach fork format formline " | |
292 "ge getc getgrent getgrgid getgrnam gethostbyaddr " | |
293 "gethostbyname gethostent getlogin getnetbyaddr " | |
294 "getnetbyname getnetent getpeername getpgrp getppid " | |
295 "getpriority getprotobyname getprotobynumber " | |
296 "getprotoent getpwent getpwnam getpwuid getservbyname " | |
297 "getservbyport getservent getsockname getsockopt glob " | |
298 "gmtime goto grep gt hex if index int ioctl join keys " | |
299 "kill last lc lcfirst le length link listen local " | |
300 "localtime lock log lstat lt m map mkdir msgctl " | |
301 "msgget msgrcv msgsnd my ne next no not oct open " | |
302 "opendir or ord our pack package pipe pop pos print " | |
303 "printf prototype push q qq qr quotemeta qu qw qx " | |
304 "rand read readdir readline readlink readpipe recv " | |
305 "redo ref rename require reset return reverse " | |
306 "rewinddir rindex rmdir s scalar seek seekdir select " | |
307 "semctl semget semop send setgrent sethostent " | |
308 "setnetent setpgrp setpriority setprotoent setpwent " | |
309 "setservent setsockopt shift shmctl shmget shmread " | |
310 "shmwrite shutdown sin sleep socket socketpair sort " | |
311 "splice split sprintf sqrt srand stat study sub " | |
312 "substr symlink syscall sysopen sysread sysseek " | |
313 "system syswrite tell telldir tie tied time times tr " | |
314 "truncate uc ucfirst umask undef unless unlink unpack " | |
315 "unshift untie until use utime values vec wait " | |
316 "waitpid wantarray warn while write x xor y"; | |
317 | |
318 return 0; | |
319 } | |
320 | |
321 | |
322 // Returns the user name of a style. | |
323 QString QsciLexerPerl::description(int style) const | |
324 { | |
325 switch (style) | |
326 { | |
327 case Default: | |
328 return tr("Default"); | |
329 | |
330 case Error: | |
331 return tr("Error"); | |
332 | |
333 case Comment: | |
334 return tr("Comment"); | |
335 | |
336 case POD: | |
337 return tr("POD"); | |
338 | |
339 case Number: | |
340 return tr("Number"); | |
341 | |
342 case Keyword: | |
343 return tr("Keyword"); | |
344 | |
345 case DoubleQuotedString: | |
346 return tr("Double-quoted string"); | |
347 | |
348 case SingleQuotedString: | |
349 return tr("Single-quoted string"); | |
350 | |
351 case Operator: | |
352 return tr("Operator"); | |
353 | |
354 case Identifier: | |
355 return tr("Identifier"); | |
356 | |
357 case Scalar: | |
358 return tr("Scalar"); | |
359 | |
360 case Array: | |
361 return tr("Array"); | |
362 | |
363 case Hash: | |
364 return tr("Hash"); | |
365 | |
366 case SymbolTable: | |
367 return tr("Symbol table"); | |
368 | |
369 case Regex: | |
370 return tr("Regular expression"); | |
371 | |
372 case Substitution: | |
373 return tr("Substitution"); | |
374 | |
375 case Backticks: | |
376 return tr("Backticks"); | |
377 | |
378 case DataSection: | |
379 return tr("Data section"); | |
380 | |
381 case HereDocumentDelimiter: | |
382 return tr("Here document delimiter"); | |
383 | |
384 case SingleQuotedHereDocument: | |
385 return tr("Single-quoted here document"); | |
386 | |
387 case DoubleQuotedHereDocument: | |
388 return tr("Double-quoted here document"); | |
389 | |
390 case BacktickHereDocument: | |
391 return tr("Backtick here document"); | |
392 | |
393 case QuotedStringQ: | |
394 return tr("Quoted string (q)"); | |
395 | |
396 case QuotedStringQQ: | |
397 return tr("Quoted string (qq)"); | |
398 | |
399 case QuotedStringQX: | |
400 return tr("Quoted string (qx)"); | |
401 | |
402 case QuotedStringQR: | |
403 return tr("Quoted string (qr)"); | |
404 | |
405 case QuotedStringQW: | |
406 return tr("Quoted string (qw)"); | |
407 | |
408 case PODVerbatim: | |
409 return tr("POD verbatim"); | |
410 | |
411 case SubroutinePrototype: | |
412 return tr("Subroutine prototype"); | |
413 | |
414 case FormatIdentifier: | |
415 return tr("Format identifier"); | |
416 | |
417 case FormatBody: | |
418 return tr("Format body"); | |
419 | |
420 case DoubleQuotedStringVar: | |
421 return tr("Double-quoted string (interpolated variable)"); | |
422 | |
423 case Translation: | |
424 return tr("Translation"); | |
425 | |
426 case RegexVar: | |
427 return tr("Regular expression (interpolated variable)"); | |
428 | |
429 case SubstitutionVar: | |
430 return tr("Substitution (interpolated variable)"); | |
431 | |
432 case BackticksVar: | |
433 return tr("Backticks (interpolated variable)"); | |
434 | |
435 case DoubleQuotedHereDocumentVar: | |
436 return tr("Double-quoted here document (interpolated variable)"); | |
437 | |
438 case BacktickHereDocumentVar: | |
439 return tr("Backtick here document (interpolated variable)"); | |
440 | |
441 case QuotedStringQQVar: | |
442 return tr("Quoted string (qq, interpolated variable)"); | |
443 | |
444 case QuotedStringQXVar: | |
445 return tr("Quoted string (qx, interpolated variable)"); | |
446 | |
447 case QuotedStringQRVar: | |
448 return tr("Quoted string (qr, interpolated variable)"); | |
449 } | |
450 | |
451 return QString(); | |
452 } | |
453 | |
454 | |
455 // Returns the background colour of the text for a style. | |
456 QColor QsciLexerPerl::defaultPaper(int style) const | |
457 { | |
458 switch (style) | |
459 { | |
460 case Error: | |
461 return QColor(0xff,0x00,0x00); | |
462 | |
463 case POD: | |
464 return QColor(0xe0,0xff,0xe0); | |
465 | |
466 case Scalar: | |
467 return QColor(0xff,0xe0,0xe0); | |
468 | |
469 case Array: | |
470 return QColor(0xff,0xff,0xe0); | |
471 | |
472 case Hash: | |
473 return QColor(0xff,0xe0,0xff); | |
474 | |
475 case SymbolTable: | |
476 return QColor(0xe0,0xe0,0xe0); | |
477 | |
478 case Regex: | |
479 return QColor(0xa0,0xff,0xa0); | |
480 | |
481 case Substitution: | |
482 case Translation: | |
483 return QColor(0xf0,0xe0,0x80); | |
484 | |
485 case Backticks: | |
486 case BackticksVar: | |
487 case QuotedStringQXVar: | |
488 return QColor(0xa0,0x80,0x80); | |
489 | |
490 case DataSection: | |
491 return QColor(0xff,0xf0,0xd8); | |
492 | |
493 case HereDocumentDelimiter: | |
494 case SingleQuotedHereDocument: | |
495 case DoubleQuotedHereDocument: | |
496 case BacktickHereDocument: | |
497 case DoubleQuotedHereDocumentVar: | |
498 case BacktickHereDocumentVar: | |
499 return QColor(0xdd,0xd0,0xdd); | |
500 | |
501 case PODVerbatim: | |
502 return QColor(0xc0,0xff,0xc0); | |
503 | |
504 case FormatBody: | |
505 return QColor(0xff,0xf0,0xff); | |
506 } | |
507 | |
508 return QsciLexer::defaultPaper(style); | |
509 } | |
510 | |
511 | |
512 // Refresh all properties. | |
513 void QsciLexerPerl::refreshProperties() | |
514 { | |
515 setAtElseProp(); | |
516 setCommentProp(); | |
517 setCompactProp(); | |
518 setPackagesProp(); | |
519 setPODBlocksProp(); | |
520 } | |
521 | |
522 | |
523 // Read properties from the settings. | |
524 bool QsciLexerPerl::readProperties(QSettings &qs,const QString &prefix) | |
525 { | |
526 int rc = true; | |
527 | |
528 fold_atelse = qs.value(prefix + "foldatelse", false).toBool(); | |
529 fold_comments = qs.value(prefix + "foldcomments", false).toBool(); | |
530 fold_compact = qs.value(prefix + "foldcompact", true).toBool(); | |
531 fold_packages = qs.value(prefix + "foldpackages", true).toBool(); | |
532 fold_pod_blocks = qs.value(prefix + "foldpodblocks", true).toBool(); | |
533 | |
534 return rc; | |
535 } | |
536 | |
537 | |
538 // Write properties to the settings. | |
539 bool QsciLexerPerl::writeProperties(QSettings &qs,const QString &prefix) const | |
540 { | |
541 int rc = true; | |
542 | |
543 qs.setValue(prefix + "foldatelse", fold_atelse); | |
544 qs.setValue(prefix + "foldcomments", fold_comments); | |
545 qs.setValue(prefix + "foldcompact", fold_compact); | |
546 qs.setValue(prefix + "foldpackages", fold_packages); | |
547 qs.setValue(prefix + "foldpodblocks", fold_pod_blocks); | |
548 | |
549 return rc; | |
550 } | |
551 | |
552 | |
553 // Return true if comments can be folded. | |
554 bool QsciLexerPerl::foldComments() const | |
555 { | |
556 return fold_comments; | |
557 } | |
558 | |
559 | |
560 // Set if comments can be folded. | |
561 void QsciLexerPerl::setFoldComments(bool fold) | |
562 { | |
563 fold_comments = fold; | |
564 | |
565 setCommentProp(); | |
566 } | |
567 | |
568 | |
569 // Set the "fold.comment" property. | |
570 void QsciLexerPerl::setCommentProp() | |
571 { | |
572 emit propertyChanged("fold.comment",(fold_comments ? "1" : "0")); | |
573 } | |
574 | |
575 | |
576 // Return true if folds are compact. | |
577 bool QsciLexerPerl::foldCompact() const | |
578 { | |
579 return fold_compact; | |
580 } | |
581 | |
582 | |
583 // Set if folds are compact | |
584 void QsciLexerPerl::setFoldCompact(bool fold) | |
585 { | |
586 fold_compact = fold; | |
587 | |
588 setCompactProp(); | |
589 } | |
590 | |
591 | |
592 // Set the "fold.compact" property. | |
593 void QsciLexerPerl::setCompactProp() | |
594 { | |
595 emit propertyChanged("fold.compact",(fold_compact ? "1" : "0")); | |
596 } | |
597 | |
598 | |
599 // Return true if packages can be folded. | |
600 bool QsciLexerPerl::foldPackages() const | |
601 { | |
602 return fold_packages; | |
603 } | |
604 | |
605 | |
606 // Set if packages can be folded. | |
607 void QsciLexerPerl::setFoldPackages(bool fold) | |
608 { | |
609 fold_packages = fold; | |
610 | |
611 setPackagesProp(); | |
612 } | |
613 | |
614 | |
615 // Set the "fold.perl.package" property. | |
616 void QsciLexerPerl::setPackagesProp() | |
617 { | |
618 emit propertyChanged("fold.perl.package",(fold_packages ? "1" : "0")); | |
619 } | |
620 | |
621 | |
622 // Return true if POD blocks can be folded. | |
623 bool QsciLexerPerl::foldPODBlocks() const | |
624 { | |
625 return fold_pod_blocks; | |
626 } | |
627 | |
628 | |
629 // Set if POD blocks can be folded. | |
630 void QsciLexerPerl::setFoldPODBlocks(bool fold) | |
631 { | |
632 fold_pod_blocks = fold; | |
633 | |
634 setPODBlocksProp(); | |
635 } | |
636 | |
637 | |
638 // Set the "fold.perl.pod" property. | |
639 void QsciLexerPerl::setPODBlocksProp() | |
640 { | |
641 emit propertyChanged("fold.perl.pod",(fold_pod_blocks ? "1" : "0")); | |
642 } | |
643 | |
644 | |
645 // Set if else can be folded. | |
646 void QsciLexerPerl::setFoldAtElse(bool fold) | |
647 { | |
648 fold_atelse = fold; | |
649 | |
650 setAtElseProp(); | |
651 } | |
652 | |
653 | |
654 // Set the "fold.perl.at.else" property. | |
655 void QsciLexerPerl::setAtElseProp() | |
656 { | |
657 emit propertyChanged("fold.perl.at.else",(fold_atelse ? "1" : "0")); | |
658 } |