1 /*
2 	Actiona
3 	Copyright (C) 2005 Jonathan Mercier-Ganady
4 
5 	Actiona is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 3 of the License, or
8 	(at your option) any later version.
9 
10 	Actiona is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 	Contact : jmgr@jmgr.info
19 */
20 // This file uses some code lines from the Ofi Labs X2 project
21 // Copyright (C) 2010 Ariya Hidayat <ariya.hidayat@gmail.com>
22 // Licensed under GNU/GPLv3
23 
24 #pragma once
25 
26 #include <QSyntaxHighlighter>
27 #include <QTextCharFormat>
28 #include <QSet>
29 
30 #include "actiontools_global.h"
31 
32 class QTextDocument;
33 
34 namespace ActionTools
35 {
36 	class ACTIONTOOLSSHARED_EXPORT CodeHighlighter : public QSyntaxHighlighter
37 	{
38 		Q_OBJECT
39 
40 	public:
41 		enum Format
42 		{
43 			NormalFormat,
44 			CommentFormat,
45 			NumberFormat,
46 			StringFormat,
47 			OperatorFormat,
48 			IdentifierFormat,
49 			KeywordFormat,
50 			ReservedFormat,
51 			CodeObjectsFormat,
52 
53 			FormatCount
54 		};
55 
56 		CodeHighlighter(QTextDocument *parent = nullptr);
57 		void addCodeObject(const QString &name);
58 
59 	protected:
60 		void highlightBlock(const QString &text) override;
61 
62 	private:
63 		QSet<QString> mUsedKeywords;
64 		QSet<QString> mReservedKeywords;
65 		QSet<QString> mCodeObjects;
66 		QTextCharFormat mFormats[FormatCount];
67 
68 		Q_DISABLE_COPY(CodeHighlighter)
69 	};
70 }
71 
72