@@ -4,7 +4,7 @@ Syntax::Syntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
44{
55 SyntaxRule rule;
66
7- keywordFormat.setForeground (Qt::darkBlue );
7+ keywordFormat.setForeground (Qt::blue );
88 keywordFormat.setFontWeight (QFont::Bold);
99 QStringList keywordPatterns;
1010 keywordPatterns << " \\ bchar\\ b" << " \\ bclass\\ b" << " \\ bconst\\ b"
@@ -16,7 +16,7 @@ Syntax::Syntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
1616 << " \\ bslots\\ b" << " \\ bstatic\\ b" << " \\ bstruct\\ b"
1717 << " \\ btemplate\\ b" << " \\ btypedef\\ b" << " \\ btypename\\ b"
1818 << " \\ bunion\\ b" << " \\ bunsigned\\ b" << " \\ bvirtual\\ b"
19- << " \\ bvoid\\ b" << " \\ bvolatile\\ b" ;
19+ << " \\ bvoid\\ b" << " \\ bvolatile\\ b" << " \\ bforeach \\ b " ;
2020 foreach (const QString &pattern, keywordPatterns)
2121 {
2222 rule.pattern = QRegularExpression (pattern);
@@ -25,10 +25,36 @@ Syntax::Syntax(QTextDocument *parent) : QSyntaxHighlighter(parent)
2525 }
2626
2727 // Single line comment format expression
28- singleLineCommentFormat.setForeground (Qt::red );
28+ singleLineCommentFormat.setForeground (Qt::darkGray );
2929 rule.pattern = QRegularExpression (QStringLiteral (" //[^\n ]*" ));
3030 rule.format = singleLineCommentFormat;
3131 syntaxRules.append (rule);
32+
33+ // Double quotation mark for string
34+ quotationMark.setForeground (Qt::darkGreen);
35+ rule.pattern = QRegularExpression (QStringLiteral (" \" .*\" " ));
36+ rule.format = quotationMark;
37+ syntaxRules.append (rule);
38+
39+ // Function format expression
40+ functionFormat.setFontItalic (true );
41+ functionFormat.setForeground (Qt::darkYellow);
42+ rule.pattern = QRegularExpression (QStringLiteral (" \\ b[a-zA-Z_][a-zA-Z0-9_]*(?=\\ s*\\ ()" ));
43+ rule.format = functionFormat;
44+ syntaxRules.append (rule);
45+
46+ // Color pattern for parenthesis
47+ QColor parenthesisColor (" #6495ED" );
48+ parenthesisFormat.setForeground (parenthesisColor);
49+ rule.pattern = QRegularExpression (QStringLiteral (" [()]" ));
50+ rule.format = parenthesisFormat;
51+ syntaxRules.append (rule);
52+
53+ // Regex for single character format 'a', '\n', etc
54+ charFormat.setForeground (Qt::darkCyan);
55+ rule.pattern = QRegularExpression (QStringLiteral (" '(\\\\ .|[^'])'" ));
56+ rule.format = charFormat;
57+ syntaxRules.append (rule);
3258}
3359
3460void Syntax::highlightBlock (const QString &text)
0 commit comments