3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_SC_SYNTAX_HIGHLIGHTER_HPP_INCLUDED
22 #define SCIDE_SC_SYNTAX_HIGHLIGHTER_HPP_INCLUDED
26 #include <QSyntaxHighlighter>
31 namespace Settings
{ class Manager
; }
54 SyntaxRule(): type(Token::Unknown
) {}
55 SyntaxRule( Token::Type t
, const QString
&s
): type(t
), expr(s
) {}
61 class SyntaxHighlighterGlobals
: public QObject
66 SyntaxHighlighterGlobals( Main
*, Settings::Manager
* settings
);
68 inline const QTextCharFormat
* formats() const
73 inline const QTextCharFormat
& format( SyntaxFormat type
) const
75 return mFormats
[type
];
78 inline static const SyntaxHighlighterGlobals
* instance() { Q_ASSERT(mInstance
); return mInstance
; }
81 void applySettings( Settings::Manager
* );
84 void syntaxFormatsChanged();
87 friend class SyntaxHighlighter
;
89 void initSyntaxRules();
92 void applySettings( Settings::Manager
*, const QString
&key
, SyntaxFormat
);
94 QTextCharFormat mFormats
[FormatCount
];
95 QVector
<SyntaxRule
> mInCodeRules
;
96 QRegExp mInSymbolRegexp
, mInStringRegexp
;
98 static SyntaxHighlighterGlobals
*mInstance
;
101 class SyntaxHighlighter
:
102 public QSyntaxHighlighter
106 static const int inCode
= 0;
107 static const int inString
= 1;
108 static const int inSymbol
= 2;
109 static const int inComment
= 100;
110 // NOTE: Integers higher than inComment are reserved for multi line comments,
111 // and indicate the comment nesting level!
114 SyntaxHighlighter(QTextDocument
*parent
= 0);
117 void highlightBlock(const QString
&text
);
118 void highlightBlockInCode(const QString
& text
, int & currentIndex
, int & currentState
);
119 void highlightBlockInString(const QString
& text
, int & currentIndex
, int & currentState
);
120 void highlightBlockInSymbol(const QString
& text
, int & currentIndex
, int & currentState
);
121 void highlightBlockInComment(const QString
& text
, int & currentIndex
, int & currentState
);
123 Token::Type
findMatchingRule(QString
const & text
, int & currentIndex
, int & lengthOfMatch
);
125 const SyntaxHighlighterGlobals
*mGlobals
;