File indexing completed on 2022-09-27 12:31:10

0001 /*
0002     SPDX-FileCopyrightText: 2003-2006 Cies Breijs <cies AT kde DOT nl>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef _HIGHLIGHTER_H_
0008 #define _HIGHLIGHTER_H_
0009 
0010 #include <QSyntaxHighlighter>
0011 #include <QTextCharFormat>
0012 
0013 #include "interpreter/tokenizer.h"
0014 
0015 
0016 class Highlighter : public QSyntaxHighlighter
0017 {
0018     Q_OBJECT
0019 
0020     public:
0021         explicit Highlighter(QTextDocument *parent = nullptr);
0022         ~Highlighter() override;
0023 
0024         /// used by the Editor for highlighting
0025         Token* formatType(const QString &text, int cursorIndex) { return checkOrApplyHighlighting(text, cursorIndex); }
0026 
0027         /// used by the Inspector to give the text format for a single statement (first in the text)
0028         QTextCharFormat* formatForStatement(const QString &text);
0029 
0030         /// used by internally and by the Inspector
0031         QTextCharFormat* tokenToFormat(Token* token);
0032 
0033     protected:
0034         void highlightBlock(const QString &text) override { checkOrApplyHighlighting(text); }
0035 
0036     private:
0037         Token* checkOrApplyHighlighting(const QString &text, int cursorIndex = -1);
0038 
0039         Tokenizer* tokenizer;
0040 
0041         QTextCharFormat variableFormat;
0042         QTextCharFormat trueFalseFormat;
0043         QTextCharFormat commentFormat;
0044         QTextCharFormat stringFormat;
0045         QTextCharFormat numberFormat;
0046         QTextCharFormat scopeFormat;
0047         QTextCharFormat controllerCommandFormat;
0048         QTextCharFormat otherCommandFormat;
0049         QTextCharFormat learnCommandFormat;
0050         QTextCharFormat booleanOperatorFormat;
0051         QTextCharFormat expressionFormat;
0052         QTextCharFormat assignmentFormat;
0053         QTextCharFormat mathOperatorFormat;
0054 };
0055 
0056 
0057 #endif  // _HIGHLIGHTER_H_