1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
/* This is a comment
NOTE works
*/
//BEGIN INCLUDES
#include "katehighlight.h"
#include "katehighlight.moc"
#include <qstringlist.h>
#include <qtextstream.h>
//END
//BEGIN defines
// same as in kmimemagic, no need to feed more data
#define KATE_HL_HOWMANY 1024
// min. x seconds between two dynamic contexts reset
static const int KATE_DYNAMIC_CONTEXTS_RESET_DELAY = 30 * 1000;
// x is a QString. if x is "true" or "1" this expression returns "true"
#define IS_TRUE(x) x.lower() == QString("true") || x.toInt() == 1
//END defines
//BEGIN Prviate HL classes
inline bool kateInsideString (const QString &str, QChar ch)
{
for (uint i=0; i < str.length(); i++)
if (*(str.unicode()+i) == ch)
return true;
return false;
}
class KateHlItem
{
public:
KateHlItem(int attribute, int context,signed char regionId, signed char regionId2);
virtual ~KateHlItem();
public:
// Now, the function returns the offset detected, or 0 if no match is found.
// bool linestart isn't needed, this is equivalent to offset == 0.
virtual int checkHgl(const QString& text, int offset, int len) = 0;
virtual bool lineContinue(){return false;}
virtual QStringList *capturedTexts() {return 0;}
static void dynamicSubstitute(QString& str, const QStringList *args);
int attr;
int ctx;
signed char region;
signed char region2;
bool lookAhead;
bool dynamic;
int column;
// start enable flags, nicer than the virtual methodes
// saves function calls
};
//END
//BEGIN STATICS
KateHlManager *KateHlManager::s_self = 0;
static const bool trueBool = true;
static const QString stdDeliminator = QString (" \t.():!+,-<=>%&*/;?[]^{|}~\\");
//END
//BEGIN NON MEMBER FUNCTIONS
static KateHlItemData::ItemStyles getDefStyleNum(QString name)
{
if (name=="dsNormal") return KateHlItemData::dsNormal;
else if (name=="dsKeyword") return KateHlItemData::dsKeyword;
else if (name=="dsError") return KateHlItemData::dsError;
return KateHlItemData::dsNormal;
}
//END
//BEGIN KateHlItem
KateHlItem::KateHlItem(int attribute, int context,signed char regionId,signed char regionId2)
: attr(attribute),
ctx(context),
region(regionId),
alwaysStartEnable (true),
customStartEnable (false)
{
}
KateHlItem::~KateHlItem()
{
//kdDebug(13010)<<"In hlItem::~KateHlItem()"<<endl;
for (uint i=0; i < subItems.size(); i++)
delete subItems[i];
}
void KateHlItem::dynamicSubstitute(QString &str, const QStringList *args)
{
for (uint i = 0; i < str.length() - 1; ++i)
{
if (str[i] == '%')
{
char c = str[i + 1].latin1();
if (c == '%')
str.replace(i, 1, "");
else if (c >= '0' && c <= '9')
{
if ((uint)(c - '0') < args->size())
{
str.replace(i, 2, (*args)[c - '0']);
i += ((*args)[c - '0']).length() - 1;
}
else
{
str.replace(i, 2, "");
--i;
}
}
}
}
}
//END
//BEGIN KateHlStringDetect
KateHlStringDetect::KateHlStringDetect(int attribute, int context, signed char regionId,signed char regionId2,const QString &s, bool inSensitive)
: KateHlItem(attribute, context,regionId,regionId2)
, str(inSensitive ? s.upper() : s)
, strLen (str.length())
, _inSensitive(inSensitive)
{
}
//BEGIN KateHlCFloat
KateHlCFloat::KateHlCFloat(int attribute, int context, signed char regionId,signed char regionId2)
: KateHlFloat(attribute,context,regionId,regionId2)
{
alwaysStartEnable = false;
}
//END
/**
* Creates a new dynamic context or reuse an old one if it has already been created.
*/
int KateHighlighting::makeDynamicContext(KateHlContext *model, const QStringList *args)
{
QPair<KateHlContext *, QString> key(model, args->front());
short value;
if (dynamicCtxs.contains(key))
value = dynamicCtxs[key];
else
{
kdDebug(13010) << "new stuff: " << startctx << endl;
KateHlContext *newctx = model->clone(args);
m_contexts.push_back (newctx);
value = startctx++;
dynamicCtxs[key] = value;
KateHlManager::self()->incDynamicCtxs();
}
// kdDebug(13010) << "Dynamic context: using context #" << value << " (for model " << model << " with args " << *args << ")" << endl;
return value;
}
/**
* Drop all dynamic contexts. Shall be called with extreme care, and shall be immediatly
* followed by a full HL invalidation.
*/
void KateHighlighting::dropDynamicContexts()
{
for (uint i=base_startctx; i < m_contexts.size(); ++i)
delete m_contexts[i];
m_contexts.resize (base_startctx);
dynamicCtxs.clear();
startctx = base_startctx;
}
/**
* Parse the text and fill in the context array and folding list array
*
* @param prevLine The previous line, the context array is picked up from that if present.
* @param textLine The text line to parse
* @param foldinglist will be filled
* @param ctxChanged will be set to reflect if the context changed
*/
void KateHighlighting::doHighlight ( KateTextLine *prevLine,
KateTextLine *textLine,
QMemArray<uint>* foldingList,
bool *ctxChanged )
void KateHighlighting::loadWildcards()
{
KConfig *config = KateHlManager::self()->getKConfig();
config->setGroup("Highlighting " + iName);
QString extensionString = config->readEntry("Wildcards", iWildcards);
if (extensionSource != extensionString) {
regexpExtensions.clear();
plainExtensions.clear();
extensionSource = extensionString;
static QRegExp sep("\\s*;\\s*");
QStringList l = QStringList::split( sep, extensionSource );
static QRegExp boringExpression("\\*\\.[\\d\\w]+");
for( QStringList::Iterator it = l.begin(); it != l.end(); ++it )
if (boringExpression.exactMatch(*it))
plainExtensions.append((*it).mid(1));
else
regexpExtensions.append(QRegExp((*it), true, true));
}
}
QValueList<QRegExp>& KateHighlighting::getRegexpExtensions()
{
return regexpExtensions;
}
//END KateViewHighlightAction
// kate: space-indent on; indent-width 2; replace-tabs on;
|