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

Kate

  • sources
  • kde-4.12
  • 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  public:
144  void doHighlight ( const Kate::TextLineData *prevLine,
145  Kate::TextLineData *textLine,
146  const Kate::TextLineData *nextLine,
147  bool &ctxChanged,
148  int tabWidth = 0);
149 
150  void setKateExtendedAttributeList(const QString &schema, QList<KateExtendedAttribute::Ptr> &,
151  KConfig* cfg=0 /*if 0 standard kate config*/, bool writeDefaultsToo=false);
152 
153  const QString &name() const {return iName;}
154  const QString &nameTranslated() const {return iNameTranslated;}
155  const QString &section() const {return iSection;}
156  bool hidden() const {return iHidden;}
157  const QString &version() const {return iVersion;}
158  const QString &style() const { return iStyle; }
159  const QString &author () const { return iAuthor; }
160  const QString &license () const { return iLicense; }
161  const QString &getIdentifier() const {return identifier;}
162  void use();
163  void release();
164 
169  bool isInWord( QChar c, int attrib=0 ) const;
170 
175  bool canBreakAt( QChar c, int attrib=0 ) const;
179  QLinkedList<QRegExp> emptyLines(int attribute=0) const;
180 
181  bool isEmptyLine(const Kate::TextLineData *textline) const;
182 
187  bool canComment( int startAttr, int endAttr ) const;
188 
193  signed char commentRegion(int attr) const;
194 
199  QString getCommentStart( int attrib=0 ) const;
200 
205  QString getCommentEnd( int attrib=0 ) const;
206 
211  QString getCommentSingleLineStart( int attrib=0 ) const;
212 
213 
214  const QHash<QString, QChar>& characterEncodings( int attrib = 0 ) const;
215 
219  enum CSLPos { CSLPosColumn0=0,CSLPosAfterWhitespace=1};
220 
225  CSLPos getCommentSingleLinePosition( int attrib=0 ) const;
226 
230  int attribute( int context ) const;
231 
232  bool attributeRequiresSpellchecking( int attr );
233 
238  QString hlKeyForAttrib( int attrib ) const;
239  QString hlKeyForContext( int attrib ) const;
240 
241  int defaultStyleForAttribute( int attrib ) const;
242 
243  void clearAttributeArrays ();
244 
245  QList<KTextEditor::Attribute::Ptr> attributes (const QString &schema);
246 
247  inline bool noHighlighting () const { return noHl; }
248 
249  // be carefull: all documents hl should be invalidated after calling this method!
250  void dropDynamicContexts();
251 
252  QString indentation () { return m_indentation; }
253 
254  void getKateExtendedAttributeList(const QString &schema, QList<KateExtendedAttribute::Ptr> &, KConfig* cfg=0);
255  void getKateExtendedAttributeListCopy(const QString &schema, QList<KateExtendedAttribute::Ptr> &,KConfig* cfg=0);
256 
257  const QHash<QString, QChar>& getCharacterEncodings( int attrib ) const;
258  const KatePrefixStore& getCharacterEncodingsPrefixStore( int attrib ) const;
259  const QHash<QChar, QString>& getReverseCharacterEncodings( int attrib ) const;
260  int getEncodedCharactersInsertionPolicy( int attrib ) const;
261 
265  QStringList getEmbeddedHighlightingModes() const;
266 
267  KateHlContext *contextNum (int n) { if (n >= 0 && n < m_contexts.size()) return m_contexts[n]; Q_ASSERT (0); return m_contexts[0]; }
268 
269  private:
273  void addCharacterEncoding( const QString& key, const QString& encoding, const QChar& c );
274 
275  private:
276  void init();
277  void done();
278  void makeContextList ();
279  int makeDynamicContext(KateHlContext *model, const QStringList *args);
280  void handleKateHlIncludeRules ();
281  void handleKateHlIncludeRulesRecursive(int index, KateHlIncludeRules *list);
282  int addToContextList(const QString &ident, int ctx0);
283  void addToKateExtendedAttributeList();
284  void createKateExtendedAttribute (QList<KateExtendedAttribute::Ptr> &list);
285  void readGlobalKeywordConfig();
286  void readWordWrapConfig();
287  void readCommentConfig();
288  void readEmptyLineConfig();
289  void readIndentationConfig ();
290  void readFoldingConfig ();
291  void readSpellCheckingConfig();
292 
300  KateHlContext *generateContextStack(Kate::TextLineData::ContextStack &contextStack, KateHlContextModification modification, int &indexLastContextPreviousLine);
301 
302  KateHlItem *createKateHlItem(KateSyntaxContextData *data, QList<KateExtendedAttribute::Ptr> &iDl, QStringList *RegionList, QStringList *ContextList);
303  int lookupAttrName(const QString& name, QList<KateExtendedAttribute::Ptr> &iDl);
304 
305  void createContextNameList(QStringList *ContextNameList, int ctx0);
306  KateHlContextModification getContextModificationFromString(QStringList *ContextNameList, QString tmpLineEndContext,/*NO CONST*/ QString &unres);
307 
308  QList<KateExtendedAttribute::Ptr> internalIDList;
309 
310  QVector<KateHlContext*> m_contexts;
311 
312  QMap< QPair<KateHlContext *, QString>, short> dynamicCtxs;
313 
314  // make them pointers perhaps
315  // NOTE: gets cleaned once makeContextList() finishes
316  KateEmbeddedHlInfos embeddedHls;
317  // valid once makeContextList() finishes
318  QStringList embeddedHighlightingModes;
319  KateHlUnresolvedCtxRefs unresolvedContextReferences;
320  QStringList RegionList;
321  QStringList ContextNameList;
322 
323  bool noHl;
324  bool folding;
325  bool casesensitive;
326  QString weakDeliminator;
327  QString deliminator;
328 
329  QString iName;
330  QString iNameTranslated;
331  QString iSection;
332  bool iHidden;
333  QString identifier;
334  QString iVersion;
335  QString iStyle;
336  QString iAuthor;
337  QString iLicense;
338  QString m_indentation;
339  int refCount;
340  int startctx, base_startctx;
341 
342  QString errorsAndWarnings;
343  QString buildIdentifier;
344  QString buildPrefix;
345  bool building;
346  uint itemData0;
347  uint buildContext0Offset;
348  KateHlIncludeRules includeRules;
349  bool m_foldingIndentationSensitive;
350 
351  // map schema name to attributes...
352  QHash< QString, QList<KTextEditor::Attribute::Ptr> > m_attributeArrays;
353 
354  // list of all created items to delete them later
355  QList<KateHlItem *> m_hlItemCleanupList;
356 
369  class HighlightPropertyBag {
370  public:
371  QString singleLineCommentMarker;
372  QString multiLineCommentStart;
373  QString multiLineCommentEnd;
374  QString multiLineRegion;
375  CSLPos singleLineCommentPosition;
376  QString deliminator;
377  QString wordWrapDeliminator;
378  QLinkedList<QRegExp> emptyLines;
379  QHash<QString, QChar> characterEncodings;
380  KatePrefixStore characterEncodingsPrefixStore;
381  QHash<QChar, QString> reverseCharacterEncodings;
382  int encodedCharactersInsertionPolicy;
383  };
384 
389  QHash<QString, HighlightPropertyBag*> m_additionalData;
390 
396  QMap<int, QString> m_hlIndex;
397  QMap<int, QString> m_ctxIndex;
398  public:
399  inline bool foldingIndentationSensitive () { return m_foldingIndentationSensitive; }
400  inline bool allowsFolding(){return folding;}
401 };
402 
403 #endif
404 
405 // 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:1111
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:161
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
Kate::TextLineData::ContextStack
QVector< short > ContextStack
Context stack.
Definition: katetextline.h:47
KateHlIncludeRules
QList< KateHlIncludeRule * > KateHlIncludeRules
Definition: katehighlight.h:115
KateHlItem
Definition: katehighlighthelpers.h:28
KateHighlighting::clearAttributeArrays
void clearAttributeArrays()
Definition: katehighlight.cpp:2102
KateHighlighting::KateHighlighting
KateHighlighting(const KateSyntaxModeListItem *def)
Definition: katehighlight.cpp:71
KateHighlighting::getCommentStart
QString getCommentStart(int attrib=0) const
Definition: katehighlight.cpp:1119
kconfig.h
KateHighlighting::use
void use()
Increase the usage count, and trigger initialization if needed.
Definition: katehighlight.cpp:719
kateextendedattribute.h
KateHighlighting::style
const QString & style() const
Definition: katehighlight.h:158
KateHighlighting::isEmptyLine
bool isEmptyLine(const Kate::TextLineData *textline) const
Definition: katehighlight.cpp:2171
QString
KateHlContextModification::doPopsAndPush
Definition: katehighlight.h:68
KateHighlighting::canBreakAt
bool canBreakAt(QChar c, int attrib=0) const
Definition: katehighlight.cpp:1091
KateHighlighting::CSLPosAfterWhitespace
Definition: katehighlight.h:219
QHash< QString, QChar >
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:1068
KateHighlighting::emptyLines
QLinkedList< QRegExp > emptyLines(int attribute=0) const
Definition: katehighlight.cpp:1097
KateHlContextModification::modType
modType
Definition: katehighlight.h:64
KateHighlighting::getCommentEnd
QString getCommentEnd(int attrib=0) const
Definition: katehighlight.cpp:1124
KateHighlighting::foldingIndentationSensitive
bool foldingIndentationSensitive()
Definition: katehighlight.h:399
KateHighlighting::nameTranslated
const QString & nameTranslated() const
Definition: katehighlight.h:154
KateHighlighting::getCharacterEncodingsPrefixStore
const KatePrefixStore & getCharacterEncodingsPrefixStore(int attrib) const
Definition: katehighlight.cpp:694
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:247
KateHighlighting::getCommentSingleLinePosition
CSLPos getCommentSingleLinePosition(int attrib=0) const
Definition: katehighlight.cpp:1134
KateEmbeddedHlInfo::loaded
bool loaded
Definition: katehighlight.h:110
KateHighlighting::attributeRequiresSpellchecking
bool attributeRequiresSpellchecking(int attr)
Definition: katehighlight.cpp:1045
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:1106
KateHighlighting::getEncodedCharactersInsertionPolicy
int getEncodedCharactersInsertionPolicy(int attrib) const
Definition: katehighlight.cpp:704
KateHighlighting::section
const QString & section() const
Definition: katehighlight.h:155
KateHighlighting::characterEncodings
const QHash< QString, QChar > & characterEncodings(int attrib=0) const
Definition: katehighlight.cpp:1139
KateHighlighting::attribute
int attribute(int context) const
Definition: katehighlight.cpp:1040
KateHighlighting::attributes
QList< KTextEditor::Attribute::Ptr > attributes(const QString &schema)
Definition: katehighlight.cpp:2134
KateEmbeddedHlInfo::KateEmbeddedHlInfo
KateEmbeddedHlInfo(bool l, int ctx0)
Definition: katehighlight.h:107
QStringList
KateHighlighting::license
const QString & license() const
Definition: katehighlight.h:160
KateHighlighting::defaultStyleForAttribute
int defaultStyleForAttribute(int attrib) const
KateHighlighting::getReverseCharacterEncodings
const QHash< QChar, QString > & getReverseCharacterEncodings(int attrib) const
Definition: katehighlight.cpp:699
KateHighlighting::hidden
bool hidden() const
Definition: katehighlight.h:156
kactionmenu.h
KateHighlighting::getEmbeddedHighlightingModes
QStringList getEmbeddedHighlightingModes() const
Returns a list of names of embedded modes.
Definition: katehighlight.cpp:2166
KateHighlighting::version
const QString & version() const
Definition: katehighlight.h:157
KateHighlighting::author
const QString & author() const
Definition: katehighlight.h:159
KateHighlighting::doHighlight
void doHighlight(const Kate::TextLineData *prevLine, Kate::TextLineData *textLine, const Kate::TextLineData *nextLine, bool &ctxChanged, int tabWidth=0)
Parse the text and fill in the context array and folding list array.
Definition: katehighlight.cpp:253
KateHighlighting::getKateExtendedAttributeList
void getKateExtendedAttributeList(const QString &schema, QList< KateExtendedAttribute::Ptr > &, KConfig *cfg=0)
Definition: katehighlight.cpp:584
KConfig
KateEmbeddedHlInfo::KateEmbeddedHlInfo
KateEmbeddedHlInfo()
Definition: katehighlight.h:106
KateHighlighting::getCommentSingleLineStart
QString getCommentSingleLineStart(int attrib=0) const
Definition: katehighlight.cpp:1129
KateSyntaxModeListItem
Information about each syntax hl Mode.
Definition: katesyntaxdocument.h:34
KateHighlighting::getCharacterEncodings
const QHash< QString, QChar > & getCharacterEncodings(int attrib) const
Definition: katehighlight.cpp:689
KateHighlighting
Definition: katehighlight.h:119
KateHighlighting::CSLPosColumn0
Definition: katehighlight.h:219
KateHighlighting::~KateHighlighting
~KateHighlighting()
Definition: katehighlight.cpp:108
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:657
KateHighlighting::getKateExtendedAttributeListCopy
void getKateExtendedAttributeListCopy(const QString &schema, QList< KateExtendedAttribute::Ptr > &, KConfig *cfg=0)
Definition: katehighlight.cpp:639
KateHighlighting::hlKeyForContext
QString hlKeyForContext(int attrib) const
Definition: katehighlight.cpp:1054
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:219
KateHighlighting::name
const QString & name() const
Definition: katehighlight.h:153
KateHighlighting::release
void release()
Decrease the usage count, and trigger cleanup if needed.
Definition: katehighlight.cpp:730
KateEmbeddedHlInfo::context0
int context0
Definition: katehighlight.h:111
KateHighlighting::dropDynamicContexts
void dropDynamicContexts()
Drop all dynamic contexts.
Definition: katehighlight.cpp:238
KateHighlighting::isInWord
bool isInWord(QChar c, int attrib=0) const
Definition: katehighlight.cpp:1084
KateHighlighting::allowsFolding
bool allowsFolding()
Definition: katehighlight.h:400
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
QMap< QString, KateEmbeddedHlInfo >
KateHighlighting::contextNum
KateHlContext * contextNum(int n)
Definition: katehighlight.h:267
QList< KateHlIncludeRule * >
KateHighlighting::indentation
QString indentation()
Definition: katehighlight.h:252
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:52 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
  • Applications
  •   Libraries
  •     libkonq
  • 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