Kate
katehighlighthelpers.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2001,2002 Joseph Wenninger <jowenn@kde.org> 00003 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 00004 Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2 as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef __KATE_HIGHLIGHTHELPERS_H__ 00022 #define __KATE_HIGHLIGHTHELPERS_H__ 00023 00024 #include "katehighlight.h" 00025 00026 #include <QRegExp> 00027 00028 class KateHlItem 00029 { 00030 public: 00031 KateHlItem(int attribute, KateHlContextModification context,signed char regionId, signed char regionId2); 00032 virtual ~KateHlItem(); 00033 00034 public: 00035 // caller must keep in mind: LEN > 0 is a must !!!!!!!!!!!!!!!!!!!!!1 00036 // Now, the function returns the offset detected, or 0 if no match is found. 00037 // bool linestart isn't needed, this is equivalent to offset == 0. 00038 virtual int checkHgl(const QString& text, int offset, int len) = 0; 00039 00040 virtual bool lineContinue(){return false;} 00041 00042 virtual void capturedTexts (QStringList &) { } 00043 virtual KateHlItem *clone(const QStringList *) {return this;} 00044 00045 static void dynamicSubstitute(QString& str, const QStringList *args); 00046 00047 QVector<KateHlItem*> subItems; 00048 int attr; 00049 KateHlContextModification ctx; 00050 signed char region; 00051 signed char region2; 00052 00053 bool lookAhead; 00054 00055 bool dynamic; 00056 bool dynamicChild; 00057 bool firstNonSpace; 00058 bool onlyConsume; 00059 int column; 00060 00061 // start enable flags, nicer than the virtual methodes 00062 // saves function calls 00063 bool alwaysStartEnable; 00064 bool customStartEnable; 00065 00066 // set to true when you cached something 00067 bool haveCache; 00068 // internal for doHighlight, don't set it in the items 00069 bool cachingHandled; 00070 }; 00071 00072 class KateHlContext 00073 { 00074 public: 00075 KateHlContext(const QString &_hlId, int attribute, KateHlContextModification _lineEndContext,KateHlContextModification _lineBeginContext, 00076 bool _fallthrough, KateHlContextModification _fallthroughContext, bool _dynamic,bool _noIndentationBasedFolding); 00077 virtual ~KateHlContext(); 00078 KateHlContext *clone(const QStringList *args); 00079 00080 QVector<KateHlItem*> items; 00081 QString hlId; 00082 int attr; 00083 KateHlContextModification lineEndContext; 00084 KateHlContextModification lineBeginContext; 00090 bool fallthrough; 00091 KateHlContextModification ftctx; // where to go after no rules matched 00092 00093 bool dynamic; 00094 bool dynamicChild; 00095 bool noIndentationBasedFolding; 00096 }; 00097 00098 class KateHlIncludeRule 00099 { 00100 public: 00101 explicit KateHlIncludeRule(int ctx_=0, uint pos_=0, const QString &incCtxN_="", bool incAttrib=false) 00102 : ctx(ctx_) 00103 , pos( pos_) 00104 , incCtxN( incCtxN_ ) 00105 , includeAttrib( incAttrib ) 00106 { 00107 incCtx=-1; 00108 } 00109 //KateHlIncludeRule(int ctx_, uint pos_, bool incAttrib) {ctx=ctx_;pos=pos_;incCtx=-1;incCtxN="";includeAttrib=incAttrib} 00110 00111 public: 00112 int ctx; 00113 uint pos; 00114 KateHlContextModification incCtx; 00115 QString incCtxN; 00116 bool includeAttrib; 00117 }; 00118 00119 class KateHlCharDetect : public KateHlItem 00120 { 00121 public: 00122 KateHlCharDetect(int attribute, KateHlContextModification context,signed char regionId,signed char regionId2, QChar); 00123 00124 virtual int checkHgl(const QString& text, int offset, int len); 00125 virtual KateHlItem *clone(const QStringList *args); 00126 00127 private: 00128 QChar sChar; 00129 }; 00130 00131 class KateHl2CharDetect : public KateHlItem 00132 { 00133 public: 00134 KateHl2CharDetect(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2, QChar ch1, QChar ch2); 00135 KateHl2CharDetect(int attribute, KateHlContextModification context,signed char regionId,signed char regionId2, const QChar *ch); 00136 00137 virtual int checkHgl(const QString& text, int offset, int len); 00138 virtual KateHlItem *clone(const QStringList *args); 00139 00140 private: 00141 QChar sChar1; 00142 QChar sChar2; 00143 }; 00144 00145 class KateHlStringDetect : public KateHlItem 00146 { 00147 public: 00148 KateHlStringDetect(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2, const QString &, bool inSensitive=false); 00149 00150 virtual int checkHgl(const QString& text, int offset, int len); 00151 virtual KateHlItem *clone(const QStringList *args); 00152 00153 protected: 00154 const QString str; 00155 const int strLen; 00156 const bool _inSensitive; 00157 }; 00158 00159 class KateHlWordDetect : public KateHlStringDetect 00160 { 00161 public: 00162 KateHlWordDetect(int attribute, KateHlContextModification context, signed char regionId, signed char regionId2, const QString &, bool inSensitive = false); 00163 00164 virtual int checkHgl(const QString& text, int offset, int len); 00165 virtual KateHlItem *clone(const QStringList *args); 00166 }; 00167 00168 class KateHlRangeDetect : public KateHlItem 00169 { 00170 public: 00171 KateHlRangeDetect(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2, QChar ch1, QChar ch2); 00172 00173 virtual int checkHgl(const QString& text, int offset, int len); 00174 00175 private: 00176 QChar sChar1; 00177 QChar sChar2; 00178 }; 00179 00180 class KateHlKeyword : public KateHlItem 00181 { 00182 public: 00183 KateHlKeyword(int attribute, KateHlContextModification context,signed char regionId,signed char regionId2, bool insensitive, const QString& delims); 00184 virtual ~KateHlKeyword (); 00185 00186 void addList(const QStringList &); 00187 virtual int checkHgl(const QString& text, int offset, int len); 00188 00189 private: 00190 QVector< QSet<QString>* > dict; 00191 bool _insensitive; 00192 QSet<QChar> deliminators; 00193 int minLen; 00194 int maxLen; 00195 }; 00196 00197 class KateHlInt : public KateHlItem 00198 { 00199 public: 00200 KateHlInt(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2); 00201 00202 virtual int checkHgl(const QString& text, int offset, int len); 00203 }; 00204 00205 class KateHlFloat : public KateHlItem 00206 { 00207 public: 00208 KateHlFloat(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2); 00209 virtual ~KateHlFloat () {} 00210 00211 virtual int checkHgl(const QString& text, int offset, int len); 00212 }; 00213 00214 class KateHlCFloat : public KateHlFloat 00215 { 00216 public: 00217 KateHlCFloat(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2); 00218 00219 virtual int checkHgl(const QString& text, int offset, int len); 00220 int checkIntHgl(const QString& text, int offset, int len); 00221 }; 00222 00223 class KateHlCOct : public KateHlItem 00224 { 00225 public: 00226 KateHlCOct(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2); 00227 00228 virtual int checkHgl(const QString& text, int offset, int len); 00229 }; 00230 00231 class KateHlCHex : public KateHlItem 00232 { 00233 public: 00234 KateHlCHex(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2); 00235 00236 virtual int checkHgl(const QString& text, int offset, int len); 00237 }; 00238 00239 class KateHlLineContinue : public KateHlItem 00240 { 00241 public: 00242 KateHlLineContinue(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2); 00243 00244 virtual bool endEnable(QChar c) {return c == '\0';} 00245 virtual int checkHgl(const QString& text, int offset, int len); 00246 virtual bool lineContinue(){return true;} 00247 }; 00248 00249 class KateHlCStringChar : public KateHlItem 00250 { 00251 public: 00252 KateHlCStringChar(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2); 00253 00254 virtual int checkHgl(const QString& text, int offset, int len); 00255 }; 00256 00257 class KateHlCChar : public KateHlItem 00258 { 00259 public: 00260 KateHlCChar(int attribute, KateHlContextModification context,signed char regionId,signed char regionId2); 00261 00262 virtual int checkHgl(const QString& text, int offset, int len); 00263 }; 00264 00265 class KateHlAnyChar : public KateHlItem 00266 { 00267 public: 00268 KateHlAnyChar(int attribute, KateHlContextModification context, signed char regionId,signed char regionId2, const QString& charList); 00269 00270 virtual int checkHgl(const QString& text, int offset, int len); 00271 00272 private: 00273 const QString _charList; 00274 }; 00275 00276 class KateHlRegExpr : public KateHlItem 00277 { 00278 public: 00279 KateHlRegExpr(int attribute, KateHlContextModification context,signed char regionId,signed char regionId2 ,const QString &expr, bool insensitive, bool minimal); 00280 00281 virtual int checkHgl(const QString& text, int offset, int len); 00282 00283 virtual void capturedTexts (QStringList &); 00284 00285 virtual KateHlItem *clone(const QStringList *args); 00286 00287 private: 00288 bool handlesLinestart; 00289 QString _regexp; 00290 bool _insensitive; 00291 bool _minimal; 00292 00293 // optimization stuff below 00295 int _lastOffset; 00297 int _lastOffsetLength; 00298 00299 QRegExp Expr; 00300 }; 00301 00302 class KateHlDetectSpaces : public KateHlItem 00303 { 00304 public: 00305 KateHlDetectSpaces (int attribute, KateHlContextModification context,signed char regionId,signed char regionId2) 00306 : KateHlItem(attribute,context,regionId,regionId2) {} 00307 00308 virtual int checkHgl(const QString& text, int offset, int len) 00309 { 00310 int len2 = offset + len; 00311 while ((offset < len2) && text[offset].isSpace()) offset++; 00312 return offset; 00313 } 00314 }; 00315 00316 class KateHlDetectIdentifier : public KateHlItem 00317 { 00318 public: 00319 KateHlDetectIdentifier (int attribute, KateHlContextModification context,signed char regionId,signed char regionId2) 00320 : KateHlItem(attribute,context,regionId,regionId2) { alwaysStartEnable = false; } 00321 00322 virtual int checkHgl(const QString& text, int offset, int len) 00323 { 00324 // first char should be a letter or underscore 00325 if ( text[offset].isLetter() || text[offset] == QChar ('_') ) 00326 { 00327 // memorize length 00328 int len2 = offset+len; 00329 00330 // one char seen 00331 offset++; 00332 00333 // now loop for all other thingies 00334 while ( 00335 (offset < len2) 00336 && (text[offset].isLetterOrNumber() || (text[offset] == QChar ('_'))) 00337 ) 00338 offset++; 00339 00340 return offset; 00341 } 00342 00343 return 0; 00344 } 00345 }; 00346 00347 //END 00348 00349 #endif 00350 00351 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference