00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _HIGHLIGHT_H_
00024 #define _HIGHLIGHT_H_
00025
00026 #include <qlist.h>
00027 #include <qdialog.h>
00028
00029 #include <kcolorbtn.h>
00030 #include <qstrvec.h>
00031 #include <qdict.h>
00032 #include <qregexp.h>
00033 #include "../qt3back/qregexp3.h"
00034 #include <kdebug.h>
00035
00036 class SyntaxDocument;
00037 struct syntaxModeListItem;
00038 struct syntaxContextData;
00039
00040 class QCheckBox;
00041 class QComboBox;
00042 class QLineEdit;
00043
00044 class TextLine;
00045 class Attribute;
00046
00047 class HlItem {
00048 public:
00049 HlItem(int attribute, int context);
00050 virtual ~HlItem();
00051 virtual bool startEnable(QChar);
00052 virtual const QChar *checkHgl(const QChar *, int len, bool) = 0;
00053 QList<HlItem> *subItems;
00054 int attr;
00055 int ctx;
00056 };
00057
00058 class HlCharDetect : public HlItem {
00059 public:
00060 HlCharDetect(int attribute, int context, QChar);
00061 virtual const QChar *checkHgl(const QChar *, int len, bool);
00062 protected:
00063 QChar sChar;
00064 };
00065
00066 class Hl2CharDetect : public HlItem {
00067 public:
00068 Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2);
00069 Hl2CharDetect(int attribute, int context, const QChar *ch);
00070
00071 virtual const QChar *checkHgl(const QChar *, int len, bool);
00072 protected:
00073 QChar sChar1;
00074 QChar sChar2;
00075 };
00076
00077 class HlStringDetect : public HlItem {
00078 public:
00079 HlStringDetect(int attribute, int context, const QString &, bool inSensitive=false);
00080 virtual ~HlStringDetect();
00081 virtual const QChar *checkHgl(const QChar *, int len, bool);
00082 protected:
00083 const QString str;
00084 bool _inSensitive;
00085 };
00086
00087 class HlRangeDetect : public HlItem {
00088 public:
00089 HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2);
00090 virtual const QChar *checkHgl(const QChar *, int len, bool);
00091 protected:
00092 QChar sChar1;
00093 QChar sChar2;
00094 };
00095
00096 class HlKeyword : public HlItem
00097 {
00098 public:
00099 HlKeyword(int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen);
00100 virtual ~HlKeyword();
00101
00102 virtual void addWord(const QString &);
00103 virtual void addList(const QStringList &);
00104 virtual const QChar *checkHgl(const QChar *, int len, bool);
00105 QStringList getList() { return words;};
00106 virtual bool startEnable(QChar c);
00107
00108 protected:
00109 QStringList words;
00110 QDict<bool> dict;
00111 bool _caseSensitive;
00112 const QChar *deliminatorChars;
00113 uint deliminatorLen;
00114 };
00115
00116 class HlPHex : public HlItem {
00117 public:
00118 HlPHex(int attribute,int context);
00119 virtual const QChar *checkHgl(const QChar *, int len, bool);
00120 };
00121 class HlInt : public HlItem {
00122 public:
00123 HlInt(int attribute, int context);
00124 virtual const QChar *checkHgl(const QChar *, int len, bool);
00125 };
00126
00127 class HlFloat : public HlItem {
00128 public:
00129 HlFloat(int attribute, int context);
00130 virtual const QChar *checkHgl(const QChar *, int len, bool);
00131 };
00132
00133 class HlCInt : public HlInt {
00134 public:
00135 HlCInt(int attribute, int context);
00136 virtual const QChar *checkHgl(const QChar *, int len, bool);
00137 };
00138
00139 class HlCOct : public HlItem {
00140 public:
00141 HlCOct(int attribute, int context);
00142 virtual const QChar *checkHgl(const QChar *, int len, bool);
00143 };
00144
00145 class HlCHex : public HlItem {
00146 public:
00147 HlCHex(int attribute, int context);
00148 virtual const QChar *checkHgl(const QChar *, int len, bool);
00149 };
00150
00151 class HlCFloat : public HlFloat {
00152 public:
00153 HlCFloat(int attribute, int context);
00154 virtual const QChar *checkHgl(const QChar *, int len, bool);
00155 };
00156
00157 class HlLineContinue : public HlItem {
00158 public:
00159 HlLineContinue(int attribute, int context);
00160 virtual bool endEnable(QChar c) {return c == '\0';}
00161 virtual const QChar *checkHgl(const QChar *, int len, bool);
00162 };
00163
00164 class HlCStringChar : public HlItem {
00165 public:
00166 HlCStringChar(int attribute, int context);
00167 virtual const QChar *checkHgl(const QChar *, int len, bool);
00168 };
00169
00170 class HlCChar : public HlItem {
00171 public:
00172 HlCChar(int attribute, int context);
00173 virtual const QChar *checkHgl(const QChar *, int len, bool);
00174 };
00175
00176 class HlAnyChar : public HlItem {
00177 public:
00178 HlAnyChar(int attribute, int context, const QChar* charList, uint len);
00179 virtual const QChar *checkHgl(const QChar *, int len, bool);
00180 const QChar* _charList;
00181 uint _charListLen;
00182 };
00183
00184 class HlRegExpr : public HlItem {
00185 public:
00186 HlRegExpr(int attribute, int context,QString expr);
00187 ~HlRegExpr(){delete Expr;};
00188 virtual const QChar *checkHgl(const QChar *, int len, bool);
00189 QRegExp3 *Expr;
00190 bool handlesLinestart;
00191 };
00192
00193
00194
00195
00196
00197 class ItemStyle {
00198 public:
00199 ItemStyle();
00200
00201 ItemStyle(const QColor &, const QColor &, bool bold, bool italic);
00202 ItemStyle(ItemStyle *its){col=its->col;selCol=its->selCol; bold=its->bold; italic=its->italic;}
00203
00204 QColor col;
00205 QColor selCol;
00206 int bold;
00207 int italic;
00208 };
00209
00210 typedef QList<ItemStyle> ItemStyleList;
00211
00212
00213 class ItemData : public ItemStyle {
00214 public:
00215 ItemData(const QString name, int defStyleNum);
00216 ItemData(const QString name, int defStyleNum,
00217 const QColor&, const QColor&, bool bold, bool italic);
00218 ItemData(ItemData
00219 *itd):ItemStyle((ItemStyle*)itd),name(itd->name),defStyleNum(itd->defStyleNum),defStyle(itd->defStyle){;}
00220 const QString name;
00221 int defStyleNum;
00222 int defStyle;
00223 };
00224
00225 typedef QList<ItemData> ItemDataList;
00226
00227 class HlData {
00228 public:
00229 HlData(const QString &wildcards, const QString &mimetypes,const QString &identifier);
00230 ItemDataList itemDataList;
00231 QString wildcards;
00232 QString mimetypes;
00233 QString identifier;
00234 };
00235
00236 typedef QList<HlData> HlDataList;
00237
00238 class HlManager;
00239 class KateConfig;
00240
00241
00242 class HlContext {
00243 public:
00244 HlContext(int attribute, int lineEndContext,int _lineBeginContext);
00245 QList<HlItem> items;
00246 int attr;
00247 int ctx;
00248 int lineBeginContext;
00249 };
00250
00251 class Highlight
00252 {
00253 friend class HlManager;
00254
00255 public:
00256 Highlight(syntaxModeListItem *def);
00257 ~Highlight();
00258
00259 int doHighlight(int ctxNum, TextLine *);
00260
00261 KateConfig *getKateConfig();
00262 QString getWildcards();
00263 QString getMimetypes();
00264 HlData *getData();
00265 void setData(HlData *);
00266 void getItemDataList(ItemDataList &);
00267 void getItemDataList(ItemDataList &, KateConfig *);
00268 void setItemDataList(ItemDataList &, KateConfig *);
00269 QString name() {return iName;}
00270 QString section() {return iSection;}
00271 void use();
00272 void release();
00273 bool isInWord(QChar c);
00274
00275 QString getCommentStart() {return cmlStart;};
00276 QString getCommentEnd() {return cmlEnd;};
00277 QString getCommentSingleLineStart() { return cslStart;};
00278
00279 protected:
00280 void init();
00281 void done();
00282 void makeContextList ();
00283 void createItemData (ItemDataList &list);
00284 void readGlobalKeywordConfig();
00285 void readCommentConfig();
00286 HlItem *createHlItem(struct syntaxContextData *data, ItemDataList &iDl);
00287 int lookupAttrName(const QString& name, ItemDataList &iDl);
00288 ItemDataList internalIDList;
00289 static const int nContexts = 32;
00290 HlContext *contextList[nContexts];
00291
00292 bool noHl;
00293 bool casesensitive;
00294 QString weakDeliminator;
00295 QString deliminator;
00296 const QChar *deliminatorChars;
00297 uint deliminatorLen;
00298 QString cmlStart;
00299 QString cmlEnd;
00300 QString cslStart;
00301 QString iName;
00302 QString iSection;
00303 QString iWildcards;
00304 QString iMimetypes;
00305 QString identifier;
00306 int refCount;
00307 };
00308
00309 class HlManager : public QObject {
00310 Q_OBJECT
00311 public:
00312 HlManager();
00313 ~HlManager();
00314
00315 static HlManager *self();
00316
00317 Highlight *getHl(int n);
00318 int defaultHl();
00319 int nameFind(const QString &name);
00320
00321 int wildcardFind(const QString &fileName);
00322 int findHl(Highlight *h) {return hlList.find(h);}
00323
00324 int makeAttribs(Highlight *, Attribute *, int maxAttribs);
00325
00326 int defaultStyles();
00327 QString defaultStyleName(int n);
00328 void getDefaults(ItemStyleList &);
00329 void setDefaults(ItemStyleList &);
00330
00331 int highlights();
00332 QString hlName(int n);
00333 QString hlSection(int n);
00334 void getHlDataList(HlDataList &);
00335 void setHlDataList(HlDataList &);
00336
00337 SyntaxDocument *syntax;
00338
00339 signals:
00340 void changed();
00341 protected:
00342 QList<Highlight> hlList;
00343 static HlManager *s_pSelf;
00344 };
00345
00346
00347
00348
00349 #endif //_HIGHLIGHT_H_