Salome HOME
updated copyright message
[modules/gui.git] / tools / PyEditor / src / PyEditor_PyHighlighter.h
1 // Copyright (C) 2015-2023  OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File   : PyEditor_PyHighlighter.h
20 // Author : Maxim GLIBIN, Open CASCADE S.A.S. (maxim.glibin@opencascade.com)
21 //
22
23 #ifndef PYEDITOR_PYHIGHLIGHTER_H
24 #define PYEDITOR_PYHIGHLIGHTER_H
25
26 #include <QSyntaxHighlighter>
27
28 class QTextDocument;
29 class PyEditor_Keywords;
30
31 class PyEditor_PyHighlighter : public QSyntaxHighlighter
32 {
33   Q_OBJECT
34
35 public:
36
37   struct ParenthesisInfo
38   {
39     char character;
40     int position;
41   };
42
43   class TextBlockData : public QTextBlockUserData
44   {
45   public:
46     TextBlockData();
47
48     QVector<ParenthesisInfo*> parentheses();
49     void insert( ParenthesisInfo* );
50
51   private:
52     QVector<ParenthesisInfo*> myParentheses;
53   };
54
55 public:
56   PyEditor_PyHighlighter( QTextDocument*,
57                           PyEditor_Keywords*, PyEditor_Keywords* );
58
59 private Q_SLOTS:
60   void        onKeywordsChanged();
61
62 protected:
63   void        updateHighlight();
64
65 protected:
66   struct HighlightingRule
67   {
68     QRegExp pattern;
69     QTextCharFormat format;
70     int capture;
71   };
72   QVector<HighlightingRule> highlightingRules;
73
74   enum Brackets { RoundBrackets, CurlyBrackets, SquareBrackets };
75
76   QRegExp tripleQuotesExpression;
77   QRegExp tripleSingleExpression;
78   QRegExp tripleDoubleExpression;
79
80   QTextCharFormat classFormat;
81   QTextCharFormat referenceClassFormat;
82   QTextCharFormat functionFormat;
83   QTextCharFormat numberFormat;
84   QTextCharFormat singleLineCommentFormat;
85   QTextCharFormat multiLineCommentFormat;
86   QTextCharFormat quotationFormat;
87
88   void highlightBlock( const QString& );
89   void insertBracketsData( char, char, TextBlockData*, const QString& );
90   void insertBracketsData( Brackets, TextBlockData*, const QString& );
91
92 private:
93   PyEditor_Keywords* myStdKeywords;
94   PyEditor_Keywords* myUserKeywords;
95 };
96
97 #endif // PYEDITOR_PYHIGHLIGHTER_H