comparison libgui/languages/build_ts/octave-qsci/qscilexercpp.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 QsciLexerCPP 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/qscilexercpp.h"
22
23 #include <qcolor.h>
24 #include <qfont.h>
25 #include <qsettings.h>
26
27
28 // The ctor.
29 QsciLexerCPP::QsciLexerCPP(QObject *parent, bool caseInsensitiveKeywords)
30 : QsciLexer(parent),
31 fold_atelse(false), fold_comments(false), fold_compact(true),
32 fold_preproc(true), style_preproc(false), dollars(true),
33 highlight_triple(false), highlight_hash(false), highlight_back(false),
34 highlight_escape(false), vs_escape(false),
35 nocase(caseInsensitiveKeywords)
36 {
37 }
38
39
40 // The dtor.
41 QsciLexerCPP::~QsciLexerCPP()
42 {
43 }
44
45
46 // Returns the language name.
47 const char *QsciLexerCPP::language() const
48 {
49 return "C++";
50 }
51
52
53 // Returns the lexer name.
54 const char *QsciLexerCPP::lexer() const
55 {
56 return (nocase ? "cppnocase" : "cpp");
57 }
58
59
60 // Return the set of character sequences that can separate auto-completion
61 // words.
62 QStringList QsciLexerCPP::autoCompletionWordSeparators() const
63 {
64 QStringList wl;
65
66 wl << "::" << "->" << ".";
67
68 return wl;
69 }
70
71
72 // Return the list of keywords that can start a block.
73 const char *QsciLexerCPP::blockStartKeyword(int *style) const
74 {
75 if (style)
76 *style = Keyword;
77
78 return "case catch class default do else finally for if private "
79 "protected public struct try union while";
80 }
81
82
83 // Return the list of characters that can start a block.
84 const char *QsciLexerCPP::blockStart(int *style) const
85 {
86 if (style)
87 *style = Operator;
88
89 return "{";
90 }
91
92
93 // Return the list of characters that can end a block.
94 const char *QsciLexerCPP::blockEnd(int *style) const
95 {
96 if (style)
97 *style = Operator;
98
99 return "}";
100 }
101
102
103 // Return the style used for braces.
104 int QsciLexerCPP::braceStyle() const
105 {
106 return Operator;
107 }
108
109
110 // Return the string of characters that comprise a word.
111 const char *QsciLexerCPP::wordCharacters() const
112 {
113 return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_#";
114 }
115
116
117 // Returns the foreground colour of the text for a style.
118 QColor QsciLexerCPP::defaultColor(int style) const
119 {
120 switch (style)
121 {
122 case Default:
123 return QColor(0x80, 0x80, 0x80);
124
125 case Comment:
126 case CommentLine:
127 return QColor(0x00, 0x7f, 0x00);
128
129 case CommentDoc:
130 case CommentLineDoc:
131 case PreProcessorCommentLineDoc:
132 return QColor(0x3f, 0x70, 0x3f);
133
134 case Number:
135 return QColor(0x00, 0x7f, 0x7f);
136
137 case Keyword:
138 return QColor(0x00, 0x00, 0x7f);
139
140 case DoubleQuotedString:
141 case SingleQuotedString:
142 case RawString:
143 return QColor(0x7f, 0x00, 0x7f);
144
145 case PreProcessor:
146 return QColor(0x7f, 0x7f, 0x00);
147
148 case Operator:
149 case UnclosedString:
150 return QColor(0x00, 0x00, 0x00);
151
152 case VerbatimString:
153 case TripleQuotedVerbatimString:
154 case HashQuotedString:
155 return QColor(0x00, 0x7f, 0x00);
156
157 case Regex:
158 return QColor(0x3f, 0x7f, 0x3f);
159
160 case CommentDocKeyword:
161 return QColor(0x30, 0x60, 0xa0);
162
163 case CommentDocKeywordError:
164 return QColor(0x80, 0x40, 0x20);
165
166 case PreProcessorComment:
167 return QColor(0x65, 0x99, 0x00);
168
169 case InactiveDefault:
170 case InactiveUUID:
171 case InactiveCommentLineDoc:
172 case InactiveKeywordSet2:
173 case InactiveCommentDocKeyword:
174 case InactiveCommentDocKeywordError:
175 case InactivePreProcessorCommentLineDoc:
176 return QColor(0xc0, 0xc0, 0xc0);
177
178 case InactiveComment:
179 case InactiveCommentLine:
180 case InactiveNumber:
181 case InactiveVerbatimString:
182 case InactiveTripleQuotedVerbatimString:
183 case InactiveHashQuotedString:
184 return QColor(0x90, 0xb0, 0x90);
185
186 case InactiveCommentDoc:
187 return QColor(0xd0, 0xd0, 0xd0);
188
189 case InactiveKeyword:
190 return QColor(0x90, 0x90, 0xb0);
191
192 case InactiveDoubleQuotedString:
193 case InactiveSingleQuotedString:
194 case InactiveRawString:
195 return QColor(0xb0, 0x90, 0xb0);
196
197 case InactivePreProcessor:
198 return QColor(0xb0, 0xb0, 0x90);
199
200 case InactiveOperator:
201 case InactiveIdentifier:
202 case InactiveGlobalClass:
203 return QColor(0xb0, 0xb0, 0xb0);
204
205 case InactiveUnclosedString:
206 return QColor(0x00, 0x00, 0x00);
207
208 case InactiveRegex:
209 return QColor(0x7f, 0xaf, 0x7f);
210
211 case InactivePreProcessorComment:
212 return QColor(0xa0, 0xc0, 0x90);
213
214 case UserLiteral:
215 return QColor(0xc0, 0x60, 0x00);
216
217 case InactiveUserLiteral:
218 return QColor(0xd7, 0xa0, 0x90);
219
220 case TaskMarker:
221 return QColor(0xbe, 0x07, 0xff);
222
223 case InactiveTaskMarker:
224 return QColor(0xc3, 0xa1, 0xcf);
225 }
226
227 return QsciLexer::defaultColor(style);
228 }
229
230
231 // Returns the end-of-line fill for a style.
232 bool QsciLexerCPP::defaultEolFill(int style) const
233 {
234 switch (style)
235 {
236 case UnclosedString:
237 case InactiveUnclosedString:
238 case VerbatimString:
239 case InactiveVerbatimString:
240 case Regex:
241 case InactiveRegex:
242 case TripleQuotedVerbatimString:
243 case InactiveTripleQuotedVerbatimString:
244 case HashQuotedString:
245 case InactiveHashQuotedString:
246 return true;
247 }
248
249 return QsciLexer::defaultEolFill(style);
250 }
251
252
253 // Returns the font of the text for a style.
254 QFont QsciLexerCPP::defaultFont(int style) const
255 {
256 QFont f;
257
258 switch (style)
259 {
260 case Comment:
261 case InactiveComment:
262 case CommentLine:
263 case InactiveCommentLine:
264 case CommentDoc:
265 case InactiveCommentDoc:
266 case CommentLineDoc:
267 case InactiveCommentLineDoc:
268 case CommentDocKeyword:
269 case InactiveCommentDocKeyword:
270 case CommentDocKeywordError:
271 case InactiveCommentDocKeywordError:
272 case TaskMarker:
273 case InactiveTaskMarker:
274 #if defined(Q_OS_WIN)
275 f = QFont("Comic Sans MS",9);
276 #elif defined(Q_OS_MAC)
277 f = QFont("Comic Sans MS", 12);
278 #else
279 f = QFont("Bitstream Vera Serif",9);
280 #endif
281 break;
282
283 case Keyword:
284 case InactiveKeyword:
285 case Operator:
286 case InactiveOperator:
287 f = QsciLexer::defaultFont(style);
288 f.setBold(true);
289 break;
290
291 case DoubleQuotedString:
292 case InactiveDoubleQuotedString:
293 case SingleQuotedString:
294 case InactiveSingleQuotedString:
295 case UnclosedString:
296 case InactiveUnclosedString:
297 case VerbatimString:
298 case InactiveVerbatimString:
299 case Regex:
300 case InactiveRegex:
301 case TripleQuotedVerbatimString:
302 case InactiveTripleQuotedVerbatimString:
303 case HashQuotedString:
304 case InactiveHashQuotedString:
305 #if defined(Q_OS_WIN)
306 f = QFont("Courier New",10);
307 #elif defined(Q_OS_MAC)
308 f = QFont("Courier", 12);
309 #else
310 f = QFont("Bitstream Vera Sans Mono",9);
311 #endif
312 break;
313
314 default:
315 f = QsciLexer::defaultFont(style);
316 }
317
318 return f;
319 }
320
321
322 // Returns the set of keywords.
323 const char *QsciLexerCPP::keywords(int set) const
324 {
325 if (set == 1)
326 return
327 "and and_eq asm auto bitand bitor bool break case "
328 "catch char class compl const const_cast continue "
329 "default delete do double dynamic_cast else enum "
330 "explicit export extern false float for friend goto if "
331 "inline int long mutable namespace new not not_eq "
332 "operator or or_eq private protected public register "
333 "reinterpret_cast return short signed sizeof static "
334 "static_cast struct switch template this throw true "
335 "try typedef typeid typename union unsigned using "
336 "virtual void volatile wchar_t while xor xor_eq";
337
338 if (set == 3)
339 return
340 "a addindex addtogroup anchor arg attention author b "
341 "brief bug c class code date def defgroup deprecated "
342 "dontinclude e em endcode endhtmlonly endif "
343 "endlatexonly endlink endverbatim enum example "
344 "exception f$ f[ f] file fn hideinitializer "
345 "htmlinclude htmlonly if image include ingroup "
346 "internal invariant interface latexonly li line link "
347 "mainpage name namespace nosubgrouping note overload "
348 "p page par param post pre ref relates remarks return "
349 "retval sa section see showinitializer since skip "
350 "skipline struct subsection test throw todo typedef "
351 "union until var verbatim verbinclude version warning "
352 "weakgroup $ @ \\ & < > # { }";
353
354 return 0;
355 }
356
357
358 // Returns the user name of a style.
359 QString QsciLexerCPP::description(int style) const
360 {
361 switch (style)
362 {
363 case Default:
364 return tr("Default");
365
366 case InactiveDefault:
367 return tr("Inactive default");
368
369 case Comment:
370 return tr("C comment");
371
372 case InactiveComment:
373 return tr("Inactive C comment");
374
375 case CommentLine:
376 return tr("C++ comment");
377
378 case InactiveCommentLine:
379 return tr("Inactive C++ comment");
380
381 case CommentDoc:
382 return tr("JavaDoc style C comment");
383
384 case InactiveCommentDoc:
385 return tr("Inactive JavaDoc style C comment");
386
387 case Number:
388 return tr("Number");
389
390 case InactiveNumber:
391 return tr("Inactive number");
392
393 case Keyword:
394 return tr("Keyword");
395
396 case InactiveKeyword:
397 return tr("Inactive keyword");
398
399 case DoubleQuotedString:
400 return tr("Double-quoted string");
401
402 case InactiveDoubleQuotedString:
403 return tr("Inactive double-quoted string");
404
405 case SingleQuotedString:
406 return tr("Single-quoted string");
407
408 case InactiveSingleQuotedString:
409 return tr("Inactive single-quoted string");
410
411 case UUID:
412 return tr("IDL UUID");
413
414 case InactiveUUID:
415 return tr("Inactive IDL UUID");
416
417 case PreProcessor:
418 return tr("Pre-processor block");
419
420 case InactivePreProcessor:
421 return tr("Inactive pre-processor block");
422
423 case Operator:
424 return tr("Operator");
425
426 case InactiveOperator:
427 return tr("Inactive operator");
428
429 case Identifier:
430 return tr("Identifier");
431
432 case InactiveIdentifier:
433 return tr("Inactive identifier");
434
435 case UnclosedString:
436 return tr("Unclosed string");
437
438 case InactiveUnclosedString:
439 return tr("Inactive unclosed string");
440
441 case VerbatimString:
442 return tr("C# verbatim string");
443
444 case InactiveVerbatimString:
445 return tr("Inactive C# verbatim string");
446
447 case Regex:
448 return tr("JavaScript regular expression");
449
450 case InactiveRegex:
451 return tr("Inactive JavaScript regular expression");
452
453 case CommentLineDoc:
454 return tr("JavaDoc style C++ comment");
455
456 case InactiveCommentLineDoc:
457 return tr("Inactive JavaDoc style C++ comment");
458
459 case KeywordSet2:
460 return tr("Secondary keywords and identifiers");
461
462 case InactiveKeywordSet2:
463 return tr("Inactive secondary keywords and identifiers");
464
465 case CommentDocKeyword:
466 return tr("JavaDoc keyword");
467
468 case InactiveCommentDocKeyword:
469 return tr("Inactive JavaDoc keyword");
470
471 case CommentDocKeywordError:
472 return tr("JavaDoc keyword error");
473
474 case InactiveCommentDocKeywordError:
475 return tr("Inactive JavaDoc keyword error");
476
477 case GlobalClass:
478 return tr("Global classes and typedefs");
479
480 case InactiveGlobalClass:
481 return tr("Inactive global classes and typedefs");
482
483 case RawString:
484 return tr("C++ raw string");
485
486 case InactiveRawString:
487 return tr("Inactive C++ raw string");
488
489 case TripleQuotedVerbatimString:
490 return tr("Vala triple-quoted verbatim string");
491
492 case InactiveTripleQuotedVerbatimString:
493 return tr("Inactive Vala triple-quoted verbatim string");
494
495 case HashQuotedString:
496 return tr("Pike hash-quoted string");
497
498 case InactiveHashQuotedString:
499 return tr("Inactive Pike hash-quoted string");
500
501 case PreProcessorComment:
502 return tr("Pre-processor C comment");
503
504 case InactivePreProcessorComment:
505 return tr("Inactive pre-processor C comment");
506
507 case PreProcessorCommentLineDoc:
508 return tr("JavaDoc style pre-processor comment");
509
510 case InactivePreProcessorCommentLineDoc:
511 return tr("Inactive JavaDoc style pre-processor comment");
512
513 case UserLiteral:
514 return tr("User-defined literal");
515
516 case InactiveUserLiteral:
517 return tr("Inactive user-defined literal");
518
519 case TaskMarker:
520 return tr("Task marker");
521
522 case InactiveTaskMarker:
523 return tr("Inactive task marker");
524
525 case EscapeSequence:
526 return tr("Escape sequence");
527
528 case InactiveEscapeSequence:
529 return tr("Inactive escape sequence");
530 }
531
532 return QString();
533 }
534
535
536 // Returns the background colour of the text for a style.
537 QColor QsciLexerCPP::defaultPaper(int style) const
538 {
539 switch (style)
540 {
541 case UnclosedString:
542 case InactiveUnclosedString:
543 return QColor(0xe0,0xc0,0xe0);
544
545 case VerbatimString:
546 case InactiveVerbatimString:
547 case TripleQuotedVerbatimString:
548 case InactiveTripleQuotedVerbatimString:
549 return QColor(0xe0,0xff,0xe0);
550
551 case Regex:
552 case InactiveRegex:
553 return QColor(0xe0,0xf0,0xe0);
554
555 case RawString:
556 case InactiveRawString:
557 return QColor(0xff,0xf3,0xff);
558
559 case HashQuotedString:
560 case InactiveHashQuotedString:
561 return QColor(0xe7,0xff,0xd7);
562 }
563
564 return QsciLexer::defaultPaper(style);
565 }
566
567
568 // Refresh all properties.
569 void QsciLexerCPP::refreshProperties()
570 {
571 setAtElseProp();
572 setCommentProp();
573 setCompactProp();
574 setPreprocProp();
575 setStylePreprocProp();
576 setDollarsProp();
577 setHighlightTripleProp();
578 setHighlightHashProp();
579 setHighlightBackProp();
580 setHighlightEscapeProp();
581 setVerbatimStringEscapeProp();
582 }
583
584
585 // Read properties from the settings.
586 bool QsciLexerCPP::readProperties(QSettings &qs,const QString &prefix)
587 {
588 fold_atelse = qs.value(prefix + "foldatelse", false).toBool();
589 fold_comments = qs.value(prefix + "foldcomments", false).toBool();
590 fold_compact = qs.value(prefix + "foldcompact", true).toBool();
591 fold_preproc = qs.value(prefix + "foldpreprocessor", true).toBool();
592 style_preproc = qs.value(prefix + "stylepreprocessor", false).toBool();
593 dollars = qs.value(prefix + "dollars", true).toBool();
594 highlight_triple = qs.value(prefix + "highlighttriple", false).toBool();
595 highlight_hash = qs.value(prefix + "highlighthash", false).toBool();
596 highlight_back = qs.value(prefix + "highlightback", false).toBool();
597 highlight_escape = qs.value(prefix + "highlightescape", false).toBool();
598 vs_escape = qs.value(prefix + "verbatimstringescape", false).toBool();
599
600 return true;
601 }
602
603
604 // Write properties to the settings.
605 bool QsciLexerCPP::writeProperties(QSettings &qs,const QString &prefix) const
606 {
607 qs.setValue(prefix + "foldatelse", fold_atelse);
608 qs.setValue(prefix + "foldcomments", fold_comments);
609 qs.setValue(prefix + "foldcompact", fold_compact);
610 qs.setValue(prefix + "foldpreprocessor", fold_preproc);
611 qs.setValue(prefix + "stylepreprocessor", style_preproc);
612 qs.setValue(prefix + "dollars", dollars);
613 qs.setValue(prefix + "highlighttriple", highlight_triple);
614 qs.setValue(prefix + "highlighthash", highlight_hash);
615 qs.setValue(prefix + "highlightback", highlight_back);
616 qs.setValue(prefix + "highlightescape", highlight_escape);
617 qs.setValue(prefix + "verbatimstringescape", vs_escape);
618
619 return true;
620 }
621
622
623 // Set if else can be folded.
624 void QsciLexerCPP::setFoldAtElse(bool fold)
625 {
626 fold_atelse = fold;
627
628 setAtElseProp();
629 }
630
631
632 // Set the "fold.at.else" property.
633 void QsciLexerCPP::setAtElseProp()
634 {
635 emit propertyChanged("fold.at.else",(fold_atelse ? "1" : "0"));
636 }
637
638
639 // Set if comments can be folded.
640 void QsciLexerCPP::setFoldComments(bool fold)
641 {
642 fold_comments = fold;
643
644 setCommentProp();
645 }
646
647
648 // Set the "fold.comment" property.
649 void QsciLexerCPP::setCommentProp()
650 {
651 emit propertyChanged("fold.comment",(fold_comments ? "1" : "0"));
652 }
653
654
655 // Set if folds are compact
656 void QsciLexerCPP::setFoldCompact(bool fold)
657 {
658 fold_compact = fold;
659
660 setCompactProp();
661 }
662
663
664 // Set the "fold.compact" property.
665 void QsciLexerCPP::setCompactProp()
666 {
667 emit propertyChanged("fold.compact",(fold_compact ? "1" : "0"));
668 }
669
670
671 // Set if preprocessor blocks can be folded.
672 void QsciLexerCPP::setFoldPreprocessor(bool fold)
673 {
674 fold_preproc = fold;
675
676 setPreprocProp();
677 }
678
679
680 // Set the "fold.preprocessor" property.
681 void QsciLexerCPP::setPreprocProp()
682 {
683 emit propertyChanged("fold.preprocessor",(fold_preproc ? "1" : "0"));
684 }
685
686
687 // Set if preprocessor lines are styled.
688 void QsciLexerCPP::setStylePreprocessor(bool style)
689 {
690 style_preproc = style;
691
692 setStylePreprocProp();
693 }
694
695
696 // Set the "styling.within.preprocessor" property.
697 void QsciLexerCPP::setStylePreprocProp()
698 {
699 emit propertyChanged("styling.within.preprocessor",(style_preproc ? "1" : "0"));
700 }
701
702
703 // Set if '$' characters are allowed.
704 void QsciLexerCPP::setDollarsAllowed(bool allowed)
705 {
706 dollars = allowed;
707
708 setDollarsProp();
709 }
710
711
712 // Set the "lexer.cpp.allow.dollars" property.
713 void QsciLexerCPP::setDollarsProp()
714 {
715 emit propertyChanged("lexer.cpp.allow.dollars",(dollars ? "1" : "0"));
716 }
717
718
719 // Set if triple quoted strings are highlighted.
720 void QsciLexerCPP::setHighlightTripleQuotedStrings(bool enabled)
721 {
722 highlight_triple = enabled;
723
724 setHighlightTripleProp();
725 }
726
727
728 // Set the "lexer.cpp.triplequoted.strings" property.
729 void QsciLexerCPP::setHighlightTripleProp()
730 {
731 emit propertyChanged("lexer.cpp.triplequoted.strings",
732 (highlight_triple ? "1" : "0"));
733 }
734
735
736 // Set if hash quoted strings are highlighted.
737 void QsciLexerCPP::setHighlightHashQuotedStrings(bool enabled)
738 {
739 highlight_hash = enabled;
740
741 setHighlightHashProp();
742 }
743
744
745 // Set the "lexer.cpp.hashquoted.strings" property.
746 void QsciLexerCPP::setHighlightHashProp()
747 {
748 emit propertyChanged("lexer.cpp.hashquoted.strings",
749 (highlight_hash ? "1" : "0"));
750 }
751
752
753 // Set if back-quoted strings are highlighted.
754 void QsciLexerCPP::setHighlightBackQuotedStrings(bool enabled)
755 {
756 highlight_back = enabled;
757
758 setHighlightBackProp();
759 }
760
761
762 // Set the "lexer.cpp.backquoted.strings" property.
763 void QsciLexerCPP::setHighlightBackProp()
764 {
765 emit propertyChanged("lexer.cpp.backquoted.strings",
766 (highlight_back ? "1" : "0"));
767 }
768
769
770 // Set if escape sequences in strings are highlighted.
771 void QsciLexerCPP::setHighlightEscapeSequences(bool enabled)
772 {
773 highlight_escape = enabled;
774
775 setHighlightEscapeProp();
776 }
777
778
779 // Set the "lexer.cpp.escape.sequence" property.
780 void QsciLexerCPP::setHighlightEscapeProp()
781 {
782 emit propertyChanged("lexer.cpp.escape.sequence",
783 (highlight_escape ? "1" : "0"));
784 }
785
786
787 // Set if escape sequences in verbatim strings are allowed.
788 void QsciLexerCPP::setVerbatimStringEscapeSequencesAllowed(bool allowed)
789 {
790 vs_escape = allowed;
791
792 setVerbatimStringEscapeProp();
793 }
794
795
796 // Set the "lexer.cpp.verbatim.strings.allow.escapes" property.
797 void QsciLexerCPP::setVerbatimStringEscapeProp()
798 {
799 emit propertyChanged("lexer.cpp.verbatim.strings.allow.escapes",
800 (vs_escape ? "1" : "0"));
801 }