1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include <QtCore/QString>
37 #include <QtCore/QList>
38 #include <QtCore/QSharedPointer>
40 namespace TextEditor {
44 class HighlightDefinition;
49 Rule(bool consumesNonSpace = true);
52 void setContext(const QString &context);
53 const QString &context() const;
55 void setItemData(const QString &itemData);
56 const QString &itemData() const;
58 void setBeginRegion(const QString &begin);
59 const QString &beginRegion() const;
61 void setEndRegion(const QString &end);
62 const QString &endRegion() const;
64 void setLookAhead(const QString &lookAhead);
65 bool isLookAhead() const;
67 void setFirstNonSpace(const QString &firstNonSpace);
68 bool isFirstNonSpace() const;
70 void setColumn(const QString &column);
73 void addChild(const QSharedPointer<Rule> &rule);
74 const QList<QSharedPointer<Rule> > &children() const;
75 bool hasChildren() const;
77 void setDefinition(const QSharedPointer<HighlightDefinition> &definition);
78 const QSharedPointer<HighlightDefinition> &definition() const;
80 bool matchSucceed(const QString &text, const int length, ProgressData *progress);
84 void progressFinished();
87 bool charPredicateMatchSucceed(const QString &text,
89 ProgressData *progress,
90 bool (QChar::* predicate)() const) const;
91 bool charPredicateMatchSucceed(const QString &text,
93 ProgressData *progress,
94 bool (*predicate)(const QChar &)) const;
96 bool matchCharacter(const QString &text,
98 ProgressData *progress,
100 bool saveRestoreOffset = true) const;
101 bool matchEscapeSequence(const QString &text,
103 ProgressData *progress,
104 bool saveRestoreOffset = true) const;
105 bool matchOctalSequence(const QString &text,
107 ProgressData *progress,
108 bool saveRestoreOffset = true) const;
109 bool matchHexSequence(const QString &text,
111 ProgressData *progress,
112 bool saveRestoreOffset = true) const;
114 static const QLatin1Char kBackSlash;
115 static const QLatin1Char kUnderscore;
116 static const QLatin1Char kDot;
117 static const QLatin1Char kPlus;
118 static const QLatin1Char kMinus;
119 static const QLatin1Char kZero;
120 static const QLatin1Char kQuote;
121 static const QLatin1Char kSingleQuote;
122 static const QLatin1Char kQuestion;
123 static const QLatin1Char kX;
124 static const QLatin1Char kA;
125 static const QLatin1Char kB;
126 static const QLatin1Char kE;
127 static const QLatin1Char kF;
128 static const QLatin1Char kN;
129 static const QLatin1Char kR;
130 static const QLatin1Char kT;
131 static const QLatin1Char kV;
132 static const QLatin1Char kOpeningBrace;
133 static const QLatin1Char kClosingBrace;
136 virtual bool doMatchSucceed(const QString &text, const int length, ProgressData *progress) = 0;
138 virtual Rule *doClone() const = 0;
140 virtual void doProgressFinished() {}
142 template <class predicate_t>
143 bool predicateMatchSucceed(const QString &text,
145 ProgressData *progress,
146 const predicate_t &p) const;
150 QString m_beginRegion;
153 bool m_firstNonSpace;
155 bool m_consumesNonSpace;
157 QList<QSharedPointer<Rule> > m_children;
159 // Rules are represented within contexts. However, they have their own definition because
160 // of externally included rules.
161 QSharedPointer<HighlightDefinition> m_definition;
164 } // namespace Internal
165 } // namespace TextEditor