@@ -19,8 +19,8 @@ Syntax::Syntax(QTextDocument *parent)
1919void Syntax::initKeywordRules ()
2020{
2121 // Keyword format
22- keywordFormat .setForeground (Qt::blue);
23- keywordFormat .setFontWeight (QFont::Bold);
22+ m_keywordFormat .setForeground (Qt::blue);
23+ m_keywordFormat .setFontWeight (QFont::Bold);
2424
2525 QStringList keywordPatterns = {
2626 " \\ bchar\\ b" , " \\ bclass\\ b" , " \\ bconst\\ b" ,
@@ -36,77 +36,76 @@ void Syntax::initKeywordRules()
3636
3737 for (const QString &pattern : keywordPatterns)
3838 {
39- addPattern (pattern, keywordFormat );
39+ addPattern (pattern, m_keywordFormat );
4040 }
4141
42- iterationFormat.setForeground (Qt::darkMagenta);
43- iterationFormat.setFontWeight (QFont::Bold);
44- QStringList iterationPatterns = {
45- " \\ bfor\\ b" , " \\ bwhile\\ b" , " \\ bdo\\ b" , " \\ bif\\ b" , " \\ belse\\ b" };
42+ m_iterationFormat.setForeground (Qt::darkMagenta);
43+ m_iterationFormat.setFontWeight (QFont::Bold);
44+ QStringList iterationPatterns = {" \\ bfor\\ b" , " \\ bwhile\\ b" , " \\ bdo\\ b" , " \\ bif\\ b" , " \\ belse\\ b" };
4645 for (const QString &pattern : iterationPatterns)
4746 {
48- addPattern (pattern, iterationFormat );
47+ addPattern (pattern, m_iterationFormat );
4948 }
5049}
5150
5251void Syntax::initCommentRules ()
5352{
5453 // Single line comment format expression
55- singleLineCommentFormat .setForeground (Qt::darkGray);
56- addPattern (" //[^\n ]*" , singleLineCommentFormat );
54+ m_singleLineCommentFormat .setForeground (Qt::darkGray);
55+ addPattern (" //[^\n ]*" , m_singleLineCommentFormat );
5756
5857 // TO-DO: Add multi-line comment support
5958}
6059
6160void Syntax::initQuotationRules ()
6261{
6362 // Double quotation mark for string
64- quotationMark .setForeground (Qt::darkGreen);
65- addPattern (" \" (\\\\ .|[^\"\\\\ ])*\" " , quotationMark );
63+ m_quotationMark .setForeground (Qt::darkGreen);
64+ addPattern (" \" (\\\\ .|[^\"\\\\ ])*\" " , m_quotationMark );
6665
6766 // TO-DO: Add single quotation mark for character
6867}
6968
7069void Syntax::initFunctionRules ()
7170{
7271 // Function format expression
73- functionFormat .setFontItalic (true );
74- functionFormat .setForeground (Qt::darkYellow);
75- addPattern (" \\ b(?!for\\ b|if\\ b|else\\ b|while\\ b|do\\ b)[a-zA-Z_][a-zA-Z0-9_]*(?=\\ s*\\ ()" , functionFormat );
72+ m_functionFormat .setFontItalic (true );
73+ m_functionFormat .setForeground (Qt::darkYellow);
74+ addPattern (" \\ b(?!for\\ b|if\\ b|else\\ b|while\\ b|do\\ b)[a-zA-Z_][a-zA-Z0-9_]*(?=\\ s*\\ ()" , m_functionFormat );
7675}
7776
7877void Syntax::initParenthesisRules ()
7978{
8079 // Color pattern for parenthesis
8180 QColor parenthesisColor (" #6495ED" );
82- parenthesisFormat .setForeground (parenthesisColor);
83- addPattern (" [()]" , parenthesisFormat );
81+ m_parenthesisFormat .setForeground (parenthesisColor);
82+ addPattern (" [()]" , m_parenthesisFormat );
8483}
8584
8685// Regex for single character format 'a', '\n', etc.
8786void Syntax::initCharRules ()
8887{
89- charFormat .setForeground (Qt::darkCyan);
90- addPattern (" '(\\\\ .|[^'])'" , charFormat );
88+ m_charFormat .setForeground (Qt::darkCyan);
89+ addPattern (" '(\\\\ .|[^'])'" , m_charFormat );
9190}
9291
9392void Syntax::addPattern (const QString &pattern, const QTextCharFormat &format)
9493{
9594 SyntaxRule rule;
96- rule.pattern = QRegularExpression (pattern);
97- rule.format = format;
98- syntaxRules .append (rule);
95+ rule.m_pattern = QRegularExpression (pattern);
96+ rule.m_format = format;
97+ m_syntaxRules .append (rule);
9998}
10099
101100void Syntax::highlightBlock (const QString &text)
102101{
103- for (const SyntaxRule &rule : syntaxRules )
102+ for (const SyntaxRule &rule : m_syntaxRules )
104103 {
105- QRegularExpressionMatchIterator matchIterator = rule.pattern .globalMatch (text);
104+ QRegularExpressionMatchIterator matchIterator = rule.m_pattern .globalMatch (text);
106105 while (matchIterator.hasNext ())
107106 {
108107 QRegularExpressionMatch match = matchIterator.next ();
109- setFormat (match.capturedStart (), match.capturedLength (), rule.format );
108+ setFormat (match.capturedStart (), match.capturedLength (), rule.m_format );
110109 }
111110 }
112111}
0 commit comments