• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • syntax
katehighlight.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2001,2002 Joseph Wenninger <jowenn@kde.org>
3  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
4  Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef __KATE_HIGHLIGHT_H__
22 #define __KATE_HIGHLIGHT_H__
23 
24 #include "katetextline.h"
25 #include "kateextendedattribute.h"
26 #include "katesyntaxmanager.h"
27 #include "spellcheck/prefixstore.h"
28 
29 #include <kconfig.h>
30 #include <kactionmenu.h>
31 
32 #include <QtCore/QVector>
33 #include <QtCore/QList>
34 #include <QtCore/QHash>
35 #include <QtCore/QMap>
36 
37 #include <QtCore/QRegExp>
38 #include <QtCore/QObject>
39 #include <QtCore/QStringList>
40 #include <QtCore/QPointer>
41 #include <QtCore/QDate>
42 #include <QtCore/QLinkedList>
43 
44 class KateHlContext;
45 class KateHlItem;
46 class KateHlIncludeRule;
47 class KateTextLine;
48 class KateSyntaxModeListItem;
49 class KateSyntaxContextData;
50 
51 // same as in kmimemagic, no need to feed more data
52 #define KATE_HL_HOWMANY 1024
53 
54 // min. x seconds between two dynamic contexts reset
55 #define KATE_DYNAMIC_CONTEXTS_RESET_DELAY (30 * 1000)
56 
57 
61 class KateHlContextModification
62 {
63  public:
64  enum modType {
65  doNothing = 0,
66  doPush = 1,
67  doPops = 2,
68  doPopsAndPush = 3
69  };
70 
76  KateHlContextModification (int _newContext = -1, int _pops = 0) : type (doNothing), newContext (_newContext), pops (_pops) //krazy:exclude=explicit
77  {
78  if (newContext >= 0 && pops == 0) type = doPush;
79  else if (newContext < 0 && pops > 0) type = doPops;
80  else if (newContext >= 0 && pops > 0) type = doPopsAndPush;
81  else type = doNothing;
82  }
83 
84  public:
88  char type;
89 
94  int newContext;
95 
100  int pops;
101 };
102 
103 class KateEmbeddedHlInfo
104 {
105  public:
106  KateEmbeddedHlInfo() {loaded=false;context0=-1;}
107  KateEmbeddedHlInfo(bool l, int ctx0) {loaded=l;context0=ctx0;}
108 
109  public:
110  bool loaded;
111  int context0;
112 };
113 
114 // some typedefs
115 typedef QList<KateHlIncludeRule*> KateHlIncludeRules;
116 typedef QMap<QString,KateEmbeddedHlInfo> KateEmbeddedHlInfos;
117 typedef QMap<KateHlContextModification*,QString> KateHlUnresolvedCtxRefs;
118 
119 class KateHighlighting
120 {
121  public:
122  KateHighlighting(const KateSyntaxModeListItem *def);
123  ~KateHighlighting();
124 
125  private:
132  void cleanup ();
133 
134  void makeNoneContext();
135 
136  public:
137  struct ContextChange {
138  KateHlContext* toContext;
139  int pos;
140  };
141 
151  void doHighlight ( const Kate::TextLineData *prevLine,
152  Kate::TextLineData *textLine,
153  const Kate::TextLineData *nextLine,
154  bool &ctxChanged,
155  int tabWidth = 0,
156  QVector<ContextChange>* contextChanges = 0);
157 
158  void setKateExtendedAttributeList(const QString &schema, QList<KateExtendedAttribute::Ptr> &,
159  KConfig* cfg=0 /*if 0 standard kate config*/, bool writeDefaultsToo=false);
160 
161  const QString &name() const {return iName;}
162  const QString &nameTranslated() const {return iNameTranslated;}
163  const QString &section() const {return iSection;}
164  bool hidden() const {return iHidden;}
165  const QString &version() const {return iVersion;}
166  const QString &style() const { return iStyle; }
167  const QString &author () const { return iAuthor; }
168  const QString &license () const { return iLicense; }
169  const QString &getIdentifier() const {return identifier;}
170  void use();
171  void release();
172 
177  bool isInWord( QChar c, int attrib=0 ) const;
178 
183  bool canBreakAt( QChar c, int attrib=0 ) const;
187  QLinkedList<QRegExp> emptyLines(int attribute=0) const;
188 
189  bool isEmptyLine(const Kate::TextLineData *textline) const;
190 
195  bool canComment( int startAttr, int endAttr ) const;
196 
201  signed char commentRegion(int attr) const;
202 
207  QString getCommentStart( int attrib=0 ) const;
208 
213  QString getCommentEnd( int attrib=0 ) const;
214 
219  QString getCommentSingleLineStart( int attrib=0 ) const;
220 
221 
222  const QHash<QString, QChar>& characterEncodings( int attrib = 0 ) const;
223 
227  enum CSLPos { CSLPosColumn0=0,CSLPosAfterWhitespace=1};
228 
233  CSLPos getCommentSingleLinePosition( int attrib=0 ) const;
234 
238  int attribute( int context ) const;
239 
240  bool attributeRequiresSpellchecking( int attr );
241 
246  QString hlKeyForAttrib( int attrib ) const;
247  QString hlKeyForContext( int attrib ) const;
248 
249  int defaultStyleForAttribute( int attrib ) const;
250 
251  void clearAttributeArrays ();
252 
253  QList<KTextEditor::Attribute::Ptr> attributes (const QString &schema);
254 
255  inline bool noHighlighting () const { return noHl; }
256 
257  // be carefull: all documents hl should be invalidated after calling this method!
258  void dropDynamicContexts();
259 
260  QString indentation () { return m_indentation; }
261 
262  void getKateExtendedAttributeList(const QString &schema, QList<KateExtendedAttribute::Ptr> &, KConfig* cfg=0);
263  void getKateExtendedAttributeListCopy(const QString &schema, QList<KateExtendedAttribute::Ptr> &,KConfig* cfg=0);
264 
265  const QHash<QString, QChar>& getCharacterEncodings( int attrib ) const;
266  const KatePrefixStore& getCharacterEncodingsPrefixStore( int attrib ) const;
267  const QHash<QChar, QString>& getReverseCharacterEncodings( int attrib ) const;
268  int getEncodedCharactersInsertionPolicy( int attrib ) const;
269 
273  QStringList getEmbeddedHighlightingModes() const;
274 
275  KateHlContext *contextNum (int n) { if (n >= 0 && n < m_contexts.size()) return m_contexts[n]; Q_ASSERT (0); return m_contexts[0]; }
276 
277  private:
281  void addCharacterEncoding( const QString& key, const QString& encoding, const QChar& c );
282 
283  private:
284  void init();
285  void done();
286  void makeContextList ();
287  int makeDynamicContext(KateHlContext *model, const QStringList *args);
288  void handleKateHlIncludeRules ();
289  void handleKateHlIncludeRulesRecursive(int index, KateHlIncludeRules *list);
290  int addToContextList(const QString &ident, int ctx0);
291  void addToKateExtendedAttributeList();
292  void createKateExtendedAttribute (QList<KateExtendedAttribute::Ptr> &list);
293  void readGlobalKeywordConfig();
294  void readWordWrapConfig();
295  void readCommentConfig();
296  void readEmptyLineConfig();
297  void readIndentationConfig ();
298  void readFoldingConfig ();
299  void readSpellCheckingConfig();
300 
308  KateHlContext *generateContextStack(Kate::TextLineData::ContextStack &contextStack, KateHlContextModification modification, int &indexLastContextPreviousLine);
309 
310  KateHlItem *createKateHlItem(KateSyntaxContextData *data, QList<KateExtendedAttribute::Ptr> &iDl, QStringList *RegionList, QStringList *ContextList);
311  int lookupAttrName(const QString& name, QList<KateExtendedAttribute::Ptr> &iDl);
312 
313  void createContextNameList(QStringList *ContextNameList, int ctx0);
314  KateHlContextModification getContextModificationFromString(QStringList *ContextNameList, QString tmpLineEndContext,/*NO CONST*/ QString &unres);
315 
316  QList<KateExtendedAttribute::Ptr> internalIDList;
317 
318  QVector<KateHlContext*> m_contexts;
319 
320  QMap< QPair<KateHlContext *, QString>, short> dynamicCtxs;
321 
322  // make them pointers perhaps
323  // NOTE: gets cleaned once makeContextList() finishes
324  KateEmbeddedHlInfos embeddedHls;
325  // valid once makeContextList() finishes
326  QStringList embeddedHighlightingModes;
327  KateHlUnresolvedCtxRefs unresolvedContextReferences;
328  QStringList RegionList;
329  QStringList ContextNameList;
330 
331  bool noHl;
332  bool folding;
333  bool casesensitive;
334  QString weakDeliminator;
335  QString deliminator;
336 
337  QString iName;
338  QString iNameTranslated;
339  QString iSection;
340  bool iHidden;
341  QString identifier;
342  QString iVersion;
343  QString iStyle;
344  QString iAuthor;
345  QString iLicense;
346  QString m_indentation;
347  int refCount;
348  int startctx, base_startctx;
349 
350  QString errorsAndWarnings;
351  QString buildIdentifier;
352  QString buildPrefix;
353  bool building;
354  uint itemData0;
355  uint buildContext0Offset;
356  KateHlIncludeRules includeRules;
357  bool m_foldingIndentationSensitive;
358 
359  // map schema name to attributes...
360  QHash< QString, QList<KTextEditor::Attribute::Ptr> > m_attributeArrays;
361 
362  // list of all created items to delete them later
363  QList<KateHlItem *> m_hlItemCleanupList;
364 
377  class HighlightPropertyBag {
378  public:
379  QString singleLineCommentMarker;
380  QString multiLineCommentStart;
381  QString multiLineCommentEnd;
382  QString multiLineRegion;
383  CSLPos singleLineCommentPosition;
384  QString deliminator;
385  QString wordWrapDeliminator;
386  QLinkedList<QRegExp> emptyLines;
387  QHash<QString, QChar> characterEncodings;
388  KatePrefixStore characterEncodingsPrefixStore;
389  QHash<QChar, QString> reverseCharacterEncodings;
390  int encodedCharactersInsertionPolicy;
391  };
392 
397  QHash<QString, HighlightPropertyBag*> m_additionalData;
398 
404  QMap<int, QString> m_hlIndex;
405  QMap<int, QString> m_ctxIndex;
406  public:
407  inline bool foldingIndentationSensitive () { return m_foldingIndentationSensitive; }
408  inline bool allowsFolding(){return folding;}
409 };
410 
411 #endif
412 
413 // kate: space-indent on; indent-width 2; replace-tabs on;
KateEmbeddedHlInfo
Definition: katehighlight.h:103
KatePrefixStore
This class can be used to efficiently search for occurrences of strings in a given string...
Definition: prefixstore.h:41
katetextline.h
KateHighlighting::canComment
bool canComment(int startAttr, int endAttr) const
Definition: katehighlight.cpp:1149
KateHlContextModification::KateHlContextModification
KateHlContextModification(int _newContext=-1, int _pops=0)
Constructor.
Definition: katehighlight.h:76
KateHlContextModification::doPops
Definition: katehighlight.h:67
KateHlContextModification::doNothing
Definition: katehighlight.h:65
KateHighlighting::getIdentifier
const QString & getIdentifier() const
Definition: katehighlight.h:169
KateEmbeddedHlInfos
QMap< QString, KateEmbeddedHlInfo > KateEmbeddedHlInfos
Definition: katehighlight.h:116
KateHlContextModification::pops
int pops
number of contexts to pop from the stack before pushing a new context on it
Definition: katehighlight.h:100
QChar
KateHlIncludeRules
QList< KateHlIncludeRule * > KateHlIncludeRules
Definition: katehighlight.h:115
KateHlItem
Definition: katehighlighthelpers.h:28
KateHighlighting::clearAttributeArrays
void clearAttributeArrays()
Definition: katehighlight.cpp:2140
KateHighlighting::KateHighlighting
KateHighlighting(const KateSyntaxModeListItem *def)
Definition: katehighlight.cpp:83
KateHighlighting::getCommentStart
QString getCommentStart(int attrib=0) const
Definition: katehighlight.cpp:1157
QMap< QString, KateEmbeddedHlInfo >
KateHighlighting::use
void use()
Increase the usage count, and trigger initialization if needed.
Definition: katehighlight.cpp:748
kateextendedattribute.h
KateHighlighting::style
const QString & style() const
Definition: katehighlight.h:166
KateHighlighting::isEmptyLine
bool isEmptyLine(const Kate::TextLineData *textline) const
Definition: katehighlight.cpp:2209
KateHlContextModification::doPopsAndPush
Definition: katehighlight.h:68
KateHighlighting::canBreakAt
bool canBreakAt(QChar c, int attrib=0) const
Definition: katehighlight.cpp:1129
KateHighlighting::CSLPosAfterWhitespace
Definition: katehighlight.h:227
KateHighlighting::ContextChange
Definition: katehighlight.h:137
Kate::TextLineData
Class representing a single text line.
Definition: katetextline.h:37
KateHighlighting::hlKeyForAttrib
QString hlKeyForAttrib(int attrib) const
map attribute to its highlighting file.
Definition: katehighlight.cpp:1106
KateHighlighting::emptyLines
QLinkedList< QRegExp > emptyLines(int attribute=0) const
Definition: katehighlight.cpp:1135
KateHlContextModification::modType
modType
Definition: katehighlight.h:64
KateHighlighting::getCommentEnd
QString getCommentEnd(int attrib=0) const
Definition: katehighlight.cpp:1162
KateHighlighting::foldingIndentationSensitive
bool foldingIndentationSensitive()
Definition: katehighlight.h:407
KateHighlighting::nameTranslated
const QString & nameTranslated() const
Definition: katehighlight.h:162
KateHighlighting::getCharacterEncodingsPrefixStore
const KatePrefixStore & getCharacterEncodingsPrefixStore(int attrib) const
Definition: katehighlight.cpp:723
KateHlContextModification
describe a modification of the context stack
Definition: katehighlight.h:61
KateHlContext
Definition: katehighlighthelpers.h:72
KateHighlighting::noHighlighting
bool noHighlighting() const
Definition: katehighlight.h:255
KateHighlighting::getCommentSingleLinePosition
CSLPos getCommentSingleLinePosition(int attrib=0) const
Definition: katehighlight.cpp:1172
KateEmbeddedHlInfo::loaded
bool loaded
Definition: katehighlight.h:110
QLinkedList< QRegExp >
KateHighlighting::attributeRequiresSpellchecking
bool attributeRequiresSpellchecking(int attr)
Definition: katehighlight.cpp:1083
KateHlContextModification::newContext
int newContext
new context to push on the stack if this is < 0, push nothing on the stack
Definition: katehighlight.h:94
katesyntaxmanager.h
KateHighlighting::commentRegion
signed char commentRegion(int attr) const
Definition: katehighlight.cpp:1144
KateHighlighting::getEncodedCharactersInsertionPolicy
int getEncodedCharactersInsertionPolicy(int attrib) const
Definition: katehighlight.cpp:733
KateHighlighting::section
const QString & section() const
Definition: katehighlight.h:163
KateHighlighting::characterEncodings
const QHash< QString, QChar > & characterEncodings(int attrib=0) const
Definition: katehighlight.cpp:1177
QHash< QString, QChar >
KateHighlighting::attribute
int attribute(int context) const
Definition: katehighlight.cpp:1078
KateHighlighting::attributes
QList< KTextEditor::Attribute::Ptr > attributes(const QString &schema)
Definition: katehighlight.cpp:2172
KateEmbeddedHlInfo::KateEmbeddedHlInfo
KateEmbeddedHlInfo(bool l, int ctx0)
Definition: katehighlight.h:107
KateHighlighting::ContextChange::pos
int pos
Definition: katehighlight.h:139
KateHighlighting::license
const QString & license() const
Definition: katehighlight.h:168
KateHighlighting::defaultStyleForAttribute
int defaultStyleForAttribute(int attrib) const
KateHighlighting::getReverseCharacterEncodings
const QHash< QChar, QString > & getReverseCharacterEncodings(int attrib) const
Definition: katehighlight.cpp:728
KateHighlighting::hidden
bool hidden() const
Definition: katehighlight.h:164
QString
QList< KateHlIncludeRule * >
QStringList
KateHighlighting::getEmbeddedHighlightingModes
QStringList getEmbeddedHighlightingModes() const
Returns a list of names of embedded modes.
Definition: katehighlight.cpp:2204
KateHighlighting::version
const QString & version() const
Definition: katehighlight.h:165
KateHighlighting::author
const QString & author() const
Definition: katehighlight.h:167
KateHighlighting::getKateExtendedAttributeList
void getKateExtendedAttributeList(const QString &schema, QList< KateExtendedAttribute::Ptr > &, KConfig *cfg=0)
Definition: katehighlight.cpp:619
QVector
KateEmbeddedHlInfo::KateEmbeddedHlInfo
KateEmbeddedHlInfo()
Definition: katehighlight.h:106
KateHighlighting::getCommentSingleLineStart
QString getCommentSingleLineStart(int attrib=0) const
Definition: katehighlight.cpp:1167
KateSyntaxModeListItem
Information about each syntax hl Mode.
Definition: katesyntaxdocument.h:34
KateHighlighting::ContextChange::toContext
KateHlContext * toContext
Definition: katehighlight.h:138
KateHighlighting::getCharacterEncodings
const QHash< QString, QChar > & getCharacterEncodings(int attrib) const
Definition: katehighlight.cpp:718
KateHighlighting
Definition: katehighlight.h:119
KateHighlighting::CSLPosColumn0
Definition: katehighlight.h:227
KateHighlighting::~KateHighlighting
~KateHighlighting()
Definition: katehighlight.cpp:115
KateHlContextModification::type
char type
indicates what this modification does, for speed
Definition: katehighlight.h:88
KateHighlighting::setKateExtendedAttributeList
void setKateExtendedAttributeList(const QString &schema, QList< KateExtendedAttribute::Ptr > &, KConfig *cfg=0, bool writeDefaultsToo=false)
Saves the attribute definitions to the config file.
Definition: katehighlight.cpp:686
KateHighlighting::getKateExtendedAttributeListCopy
void getKateExtendedAttributeListCopy(const QString &schema, QList< KateExtendedAttribute::Ptr > &, KConfig *cfg=0)
Definition: katehighlight.cpp:668
KateHighlighting::hlKeyForContext
QString hlKeyForContext(int attrib) const
Definition: katehighlight.cpp:1092
KateHlIncludeRule
Definition: katehighlighthelpers.h:102
KateHighlighting::CSLPos
CSLPos
This enum is used for storing the information where a single line comment marker should be inserted...
Definition: katehighlight.h:227
KateHighlighting::name
const QString & name() const
Definition: katehighlight.h:161
KateHighlighting::release
void release()
Decrease the usage count, and trigger cleanup if needed.
Definition: katehighlight.cpp:759
KateEmbeddedHlInfo::context0
int context0
Definition: katehighlight.h:111
KateHighlighting::dropDynamicContexts
void dropDynamicContexts()
Drop all dynamic contexts.
Definition: katehighlight.cpp:264
QVector::size
int size() const
KateHighlighting::isInWord
bool isInWord(QChar c, int attrib=0) const
Definition: katehighlight.cpp:1122
KateHighlighting::allowsFolding
bool allowsFolding()
Definition: katehighlight.h:408
KateHighlighting::doHighlight
void doHighlight(const Kate::TextLineData *prevLine, Kate::TextLineData *textLine, const Kate::TextLineData *nextLine, bool &ctxChanged, int tabWidth=0, QVector< ContextChange > *contextChanges=0)
Parse the text and fill in the context array and folding list array.
Definition: katehighlight.cpp:279
KateHlContextModification::doPush
Definition: katehighlight.h:66
KateSyntaxContextData
Class holding the data around the current QDomElement.
Definition: katesyntaxdocument.h:62
KateHlUnresolvedCtxRefs
QMap< KateHlContextModification *, QString > KateHlUnresolvedCtxRefs
Definition: katehighlight.h:117
prefixstore.h
KateHighlighting::contextNum
KateHlContext * contextNum(int n)
Definition: katehighlight.h:275
KateHighlighting::indentation
QString indentation()
Definition: katehighlight.h:260
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal