1 /* 2 SPDX-FileCopyrightText: 2003-2006 Cies Breijs <cies AT kde DOT nl> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef _HIGHLIGHTER_H_ 8 #define _HIGHLIGHTER_H_ 9 10 #include <QSyntaxHighlighter> 11 #include <QTextCharFormat> 12 13 #include "interpreter/tokenizer.h" 14 15 16 class Highlighter : public QSyntaxHighlighter 17 { 18 Q_OBJECT 19 20 public: 21 explicit Highlighter(QTextDocument *parent = nullptr); 22 ~Highlighter() override; 23 24 /// used by the Editor for highlighting formatType(const QString & text,int cursorIndex)25 Token* formatType(const QString &text, int cursorIndex) { return checkOrApplyHighlighting(text, cursorIndex); } 26 27 /// used by the Inspector to give the text format for a single statement (first in the text) 28 QTextCharFormat* formatForStatement(const QString &text); 29 30 /// used by internally and by the Inspector 31 QTextCharFormat* tokenToFormat(Token* token); 32 33 protected: highlightBlock(const QString & text)34 void highlightBlock(const QString &text) override { checkOrApplyHighlighting(text); } 35 36 private: 37 Token* checkOrApplyHighlighting(const QString &text, int cursorIndex = -1); 38 39 Tokenizer* tokenizer; 40 41 QTextCharFormat variableFormat; 42 QTextCharFormat trueFalseFormat; 43 QTextCharFormat commentFormat; 44 QTextCharFormat stringFormat; 45 QTextCharFormat numberFormat; 46 QTextCharFormat scopeFormat; 47 QTextCharFormat controllerCommandFormat; 48 QTextCharFormat otherCommandFormat; 49 QTextCharFormat learnCommandFormat; 50 QTextCharFormat booleanOperatorFormat; 51 QTextCharFormat expressionFormat; 52 QTextCharFormat assignmentFormat; 53 QTextCharFormat mathOperatorFormat; 54 }; 55 56 57 #endif // _HIGHLIGHTER_H_ 58