#ifndef SCRIPTHIGHLIGHTER_H
#define SCRIPTHIGHLIGHTER_H

#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include <QRegularExpression>
#include <qcodeedit.h>


class ScriptHighlighter: public QSyntaxHighlighter {
	Q_OBJECT
public:
	ScriptHighlighter(QTextDocument * parent = 0);
	
	int addCustomRule(const QStringList & keywords, const QColor & color, const QTextCharFormat & format = QTextCharFormat());
	int addCustomRule(const QList<QCodeEdit::ACEntry> & entries, const QColor & color, const QTextCharFormat & format = QTextCharFormat());
	void removeCustomRule(int id);
	QTextCharFormat formatForFunction() {return functionFormat;}

private:
	void highlightBlock(const QString & text);
	void setCharFormat(const QString& text, const QString & char_br, bool ext = false);
	
	struct HighlightingRule {
		QRegularExpression pattern;
		QTextCharFormat format;
	};
	
	int nid;
	QVector<HighlightingRule> highlightingRules, rules_chars;
	QMap<int, QVector<HighlightingRule> > customHighlightingRules;
	QString commentStartExpression, commentEndExpression;
	QTextCharFormat quotationFormat, quotationFormatE, functionFormat, commentFormat, macroFormat, spaceFormat, functionDeclarationFormat, regexpFormat;
	
};

#endif // SCRIPTHIGHLIGHTER_H
