Kate
katehighlight.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_HIGHLIGHT_H__ 00022 #define __KATE_HIGHLIGHT_H__ 00023 00024 #include "katetextline.h" 00025 #include "kateextendedattribute.h" 00026 #include "katesyntaxmanager.h" 00027 #include "spellcheck/prefixstore.h" 00028 00029 #include <kconfig.h> 00030 #include <kactionmenu.h> 00031 00032 #include <QtCore/QVector> 00033 #include <QtCore/QList> 00034 #include <QtCore/QHash> 00035 #include <QtCore/QMap> 00036 00037 #include <QtCore/QRegExp> 00038 #include <QtCore/QObject> 00039 #include <QtCore/QStringList> 00040 #include <QtCore/QPointer> 00041 #include <QtCore/QDate> 00042 #include <QtCore/QLinkedList> 00043 00044 class KateHlContext; 00045 class KateHlItem; 00046 class KateHlIncludeRule; 00047 class KateTextLine; 00048 class KateSyntaxModeListItem; 00049 class KateSyntaxContextData; 00050 00051 // same as in kmimemagic, no need to feed more data 00052 #define KATE_HL_HOWMANY 1024 00053 00054 // min. x seconds between two dynamic contexts reset 00055 #define KATE_DYNAMIC_CONTEXTS_RESET_DELAY (30 * 1000) 00056 00057 00061 class KateHlContextModification 00062 { 00063 public: 00064 enum modType { 00065 doNothing = 0, 00066 doPush = 1, 00067 doPops = 2, 00068 doPopsAndPush = 3 00069 }; 00070 00076 KateHlContextModification (int _newContext = -1, int _pops = 0) : type (doNothing), newContext (_newContext), pops (_pops) //krazy:exclude=explicit 00077 { 00078 if (newContext >= 0 && pops == 0) type = doPush; 00079 else if (newContext < 0 && pops > 0) type = doPops; 00080 else if (newContext >= 0 && pops > 0) type = doPopsAndPush; 00081 else type = doNothing; 00082 } 00083 00084 public: 00088 char type; 00089 00094 int newContext; 00095 00100 int pops; 00101 }; 00102 00103 class KateEmbeddedHlInfo 00104 { 00105 public: 00106 KateEmbeddedHlInfo() {loaded=false;context0=-1;} 00107 KateEmbeddedHlInfo(bool l, int ctx0) {loaded=l;context0=ctx0;} 00108 00109 public: 00110 bool loaded; 00111 int context0; 00112 }; 00113 00114 // some typedefs 00115 typedef QList<KateHlIncludeRule*> KateHlIncludeRules; 00116 typedef QMap<QString,KateEmbeddedHlInfo> KateEmbeddedHlInfos; 00117 typedef QMap<KateHlContextModification*,QString> KateHlUnresolvedCtxRefs; 00118 00119 class KateHighlighting 00120 { 00121 public: 00122 KateHighlighting(const KateSyntaxModeListItem *def); 00123 ~KateHighlighting(); 00124 00125 private: 00132 void cleanup (); 00133 00134 public: 00135 void doHighlight ( Kate::TextLineData *prevLine, 00136 Kate::TextLineData *textLine, 00137 QVector<int> &foldingList, 00138 bool &ctxChanged ); 00139 00140 void setKateExtendedAttributeList(uint schema, QList<KateExtendedAttribute::Ptr> &); 00141 00142 const QString &name() const {return iName;} 00143 const QString &nameTranslated() const {return iNameTranslated;} 00144 const QString §ion() const {return iSection;} 00145 bool hidden() const {return iHidden;} 00146 const QString &version() const {return iVersion;} 00147 const QString &style() const { return iStyle; } 00148 const QString &author () const { return iAuthor; } 00149 const QString &license () const { return iLicense; } 00150 const QString &getIdentifier() const {return identifier;} 00151 void use(); 00152 void release(); 00153 00158 bool isInWord( QChar c, int attrib=0 ) const; 00159 00164 bool canBreakAt( QChar c, int attrib=0 ) const; 00165 00169 QLinkedList<QRegExp> emptyLines(int attribute=0) const; 00174 bool canComment( int startAttr, int endAttr ) const; 00175 00180 signed char commentRegion(int attr) const; 00181 00186 QString getCommentStart( int attrib=0 ) const; 00187 00192 QString getCommentEnd( int attrib=0 ) const; 00193 00198 QString getCommentSingleLineStart( int attrib=0 ) const; 00199 00200 00201 const QHash<QString, QChar>& characterEncodings( int attrib = 0 ) const; 00202 00206 enum CSLPos { CSLPosColumn0=0,CSLPosAfterWhitespace=1}; 00207 00212 CSLPos getCommentSingleLinePosition( int attrib=0 ) const; 00213 00217 int attribute( int context ) const; 00218 00219 bool attributeRequiresSpellchecking( int attr ); 00220 00225 QString hlKeyForAttrib( int attrib ) const; 00226 QString hlKeyForContext( int attrib ) const; 00227 00228 int defaultStyleForAttribute( int attrib ) const; 00229 00230 void clearAttributeArrays (); 00231 00232 QList<KTextEditor::Attribute::Ptr> attributes (const QString &schema); 00233 00234 inline bool noHighlighting () const { return noHl; } 00235 00236 // be carefull: all documents hl should be invalidated after calling this method! 00237 void dropDynamicContexts(); 00238 00239 QString indentation () { return m_indentation; } 00240 00241 void getKateExtendedAttributeList(const QString &schema, QList<KateExtendedAttribute::Ptr> &); 00242 void getKateExtendedAttributeListCopy(const QString &schema, QList<KateExtendedAttribute::Ptr> &); 00243 00244 const QHash<QString, QChar>& getCharacterEncodings( int attrib ) const; 00245 const KatePrefixStore& getCharacterEncodingsPrefixStore( int attrib ) const; 00246 const QHash<QChar, QString>& getReverseCharacterEncodings( int attrib ) const; 00247 int getEncodedCharactersInsertionPolicy( int attrib ) const; 00248 00252 QStringList getEmbeddedHighlightingModes() const; 00253 00254 private: 00258 void addCharacterEncoding( const QString& key, const QString& encoding, const QChar& c ); 00259 00260 private: 00261 void init(); 00262 void done(); 00263 void makeContextList (); 00264 int makeDynamicContext(KateHlContext *model, const QStringList *args); 00265 void handleKateHlIncludeRules (); 00266 void handleKateHlIncludeRulesRecursive(int index, KateHlIncludeRules *list); 00267 int addToContextList(const QString &ident, int ctx0); 00268 void addToKateExtendedAttributeList(); 00269 void createKateExtendedAttribute (QList<KateExtendedAttribute::Ptr> &list); 00270 void readGlobalKeywordConfig(); 00271 void readWordWrapConfig(); 00272 void readCommentConfig(); 00273 void readEmptyLineConfig(); 00274 void readIndentationConfig (); 00275 void readFoldingConfig (); 00276 void readSpellCheckingConfig(); 00277 00285 KateHlContext *generateContextStack(QVector<short> &contextStack, KateHlContextModification modification, int &indexLastContextPreviousLine); 00286 00287 KateHlItem *createKateHlItem(KateSyntaxContextData *data, QList<KateExtendedAttribute::Ptr> &iDl, QStringList *RegionList, QStringList *ContextList); 00288 int lookupAttrName(const QString& name, QList<KateExtendedAttribute::Ptr> &iDl); 00289 00290 void createContextNameList(QStringList *ContextNameList, int ctx0); 00291 KateHlContextModification getContextModificationFromString(QStringList *ContextNameList, QString tmpLineEndContext,/*NO CONST*/ QString &unres); 00292 00293 QList<KateExtendedAttribute::Ptr> internalIDList; 00294 00295 QVector<KateHlContext*> m_contexts; 00296 inline KateHlContext *contextNum (int n) { if (n >= 0 && n < m_contexts.size()) return m_contexts[n]; Q_ASSERT (0); return m_contexts[0]; } 00297 00298 QMap< QPair<KateHlContext *, QString>, short> dynamicCtxs; 00299 00300 // make them pointers perhaps 00301 // NOTE: gets cleaned once makeContextList() finishes 00302 KateEmbeddedHlInfos embeddedHls; 00303 // valid once makeContextList() finishes 00304 QStringList embeddedHighlightingModes; 00305 KateHlUnresolvedCtxRefs unresolvedContextReferences; 00306 QStringList RegionList; 00307 QStringList ContextNameList; 00308 00309 bool noHl; 00310 bool folding; 00311 bool casesensitive; 00312 QString weakDeliminator; 00313 QString deliminator; 00314 00315 QString iName; 00316 QString iNameTranslated; 00317 QString iSection; 00318 bool iHidden; 00319 QString identifier; 00320 QString iVersion; 00321 QString iStyle; 00322 QString iAuthor; 00323 QString iLicense; 00324 QString m_indentation; 00325 int refCount; 00326 int startctx, base_startctx; 00327 00328 QString errorsAndWarnings; 00329 QString buildIdentifier; 00330 QString buildPrefix; 00331 bool building; 00332 uint itemData0; 00333 uint buildContext0Offset; 00334 KateHlIncludeRules includeRules; 00335 bool m_foldingIndentationSensitive; 00336 00337 // map schema name to attributes... 00338 QHash< QString, QList<KTextEditor::Attribute::Ptr> > m_attributeArrays; 00339 00340 // list of all created items to delete them later 00341 QList<KateHlItem *> m_hlItemCleanupList; 00342 00355 class HighlightPropertyBag { 00356 public: 00357 QString singleLineCommentMarker; 00358 QString multiLineCommentStart; 00359 QString multiLineCommentEnd; 00360 QString multiLineRegion; 00361 CSLPos singleLineCommentPosition; 00362 QString deliminator; 00363 QString wordWrapDeliminator; 00364 QLinkedList<QRegExp> emptyLines; 00365 QHash<QString, QChar> characterEncodings; 00366 KatePrefixStore characterEncodingsPrefixStore; 00367 QHash<QChar, QString> reverseCharacterEncodings; 00368 int encodedCharactersInsertionPolicy; 00369 }; 00370 00375 QHash<QString, HighlightPropertyBag*> m_additionalData; 00376 00382 QMap<int, QString> m_hlIndex; 00383 QMap<int, QString> m_ctxIndex; 00384 public: 00385 inline bool foldingIndentationSensitive () { return m_foldingIndentationSensitive; } 00386 inline bool allowsFolding(){return folding;} 00387 }; 00388 00389 #endif 00390 00391 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference