Kate
katehighlight.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00052 #define KATE_HL_HOWMANY 1024
00053
00054
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)
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
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 ( KateTextLine *prevLine,
00136 KateTextLine *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
00227 int defaultStyleForAttribute( int attrib ) const;
00228
00229 void clearAttributeArrays ();
00230
00231 QList<KTextEditor::Attribute::Ptr> attributes (const QString &schema);
00232
00233 inline bool noHighlighting () const { return noHl; }
00234
00235
00236 void dropDynamicContexts();
00237
00238 QString indentation () { return m_indentation; }
00239
00240 void getKateExtendedAttributeList(const QString &schema, QList<KateExtendedAttribute::Ptr> &);
00241 void getKateExtendedAttributeListCopy(const QString &schema, QList<KateExtendedAttribute::Ptr> &);
00242
00243 const QHash<QString, QChar>& getCharacterEncodings( int attrib ) const;
00244 const KatePrefixStore& getCharacterEncodingsPrefixStore( int attrib ) const;
00245 const QHash<QChar, QString>& getReverseCharacterEncodings( int attrib ) const;
00246 int getEncodedCharactersInsertionPolicy( int attrib ) const;
00247
00251 QStringList getEmbeddedModes() const;
00252
00253 private:
00257 void addCharacterEncoding( const QString& key, const QString& encoding, const QChar& c );
00258
00259 private:
00260 void init();
00261 void done();
00262 void makeContextList ();
00263 int makeDynamicContext(KateHlContext *model, const QStringList *args);
00264 void handleKateHlIncludeRules ();
00265 void handleKateHlIncludeRulesRecursive(int index, KateHlIncludeRules *list);
00266 int addToContextList(const QString &ident, int ctx0);
00267 void addToKateExtendedAttributeList();
00268 void createKateExtendedAttribute (QList<KateExtendedAttribute::Ptr> &list);
00269 void readGlobalKeywordConfig();
00270 void readWordWrapConfig();
00271 void readCommentConfig();
00272 void readEmptyLineConfig();
00273 void readIndentationConfig ();
00274 void readFoldingConfig ();
00275 void readSpellCheckingConfig();
00276
00284 KateHlContext *generateContextStack(QVector<short> &contextStack, KateHlContextModification modification, int &indexLastContextPreviousLine);
00285
00286 KateHlItem *createKateHlItem(KateSyntaxContextData *data, QList<KateExtendedAttribute::Ptr> &iDl, QStringList *RegionList, QStringList *ContextList);
00287 int lookupAttrName(const QString& name, QList<KateExtendedAttribute::Ptr> &iDl);
00288
00289 void createContextNameList(QStringList *ContextNameList, int ctx0);
00290 KateHlContextModification getContextModificationFromString(QStringList *ContextNameList, QString tmpLineEndContext, QString &unres);
00291
00292 QList<KateExtendedAttribute::Ptr> internalIDList;
00293
00294 QVector<KateHlContext*> m_contexts;
00295 inline KateHlContext *contextNum (int n) { if (n >= 0 && n < m_contexts.size()) return m_contexts[n]; Q_ASSERT (0); return m_contexts[0]; }
00296
00297 QMap< QPair<KateHlContext *, QString>, short> dynamicCtxs;
00298
00299
00300
00301 KateEmbeddedHlInfos embeddedHls;
00302
00303 QStringList embeddedModes;
00304 KateHlUnresolvedCtxRefs unresolvedContextReferences;
00305 QStringList RegionList;
00306 QStringList ContextNameList;
00307
00308 bool noHl;
00309 bool folding;
00310 bool casesensitive;
00311 QString weakDeliminator;
00312 QString deliminator;
00313
00314 QString iName;
00315 QString iNameTranslated;
00316 QString iSection;
00317 bool iHidden;
00318 QString identifier;
00319 QString iVersion;
00320 QString iStyle;
00321 QString iAuthor;
00322 QString iLicense;
00323 QString m_indentation;
00324 int refCount;
00325 int startctx, base_startctx;
00326
00327 QString errorsAndWarnings;
00328 QString buildIdentifier;
00329 QString buildPrefix;
00330 bool building;
00331 uint itemData0;
00332 uint buildContext0Offset;
00333 KateHlIncludeRules includeRules;
00334 bool m_foldingIndentationSensitive;
00335
00336
00337 QHash< QString, QList<KTextEditor::Attribute::Ptr> > m_attributeArrays;
00338
00339
00352 class HighlightPropertyBag {
00353 public:
00354 QString singleLineCommentMarker;
00355 QString multiLineCommentStart;
00356 QString multiLineCommentEnd;
00357 QString multiLineRegion;
00358 CSLPos singleLineCommentPosition;
00359 QString deliminator;
00360 QString wordWrapDeliminator;
00361 QLinkedList<QRegExp> emptyLines;
00362 QHash<QString, QChar> characterEncodings;
00363 KatePrefixStore characterEncodingsPrefixStore;
00364 QHash<QChar, QString> reverseCharacterEncodings;
00365 int encodedCharactersInsertionPolicy;
00366 };
00367
00372 QHash<QString, HighlightPropertyBag*> m_additionalData;
00373
00379 QMap<int, QString> m_hlIndex;
00380
00381 public:
00382 inline bool foldingIndentationSensitive () { return m_foldingIndentationSensitive; }
00383 inline bool allowsFolding(){return folding;}
00384 };
00385
00386 #endif
00387
00388