Removed the TokenCache.

This commit is contained in:
Erik Verbruggen
2010-06-29 17:47:59 +02:00
parent bb8aed629f
commit e3e8b1a5c0
22 changed files with 107 additions and 250 deletions

View File

@@ -170,4 +170,36 @@ QList<SimpleToken> SimpleLexer::operator()(const QString &text, int state)
return tokens;
}
int SimpleLexer::tokenAt(const QList<SimpleToken> &tokens, int offset)
{
for (int index = tokens.size() - 1; index >= 0; --index) {
const SimpleToken &tk = tokens.at(index);
if (tk.position() <= offset && tk.end() >= offset)
return index;
}
return -1;
}
SimpleToken SimpleLexer::tokenAt(const QString &text,
int offset,
int state,
bool qtMocRunEnabled)
{
SimpleLexer tokenize;
tokenize.setQtMocRunEnabled(qtMocRunEnabled);
const QList<SimpleToken> tokens = tokenize(text, state);
const int tokenIdx = tokenAt(tokens, offset);
return (tokenIdx == -1) ? SimpleToken() : tokens.at(tokenIdx);
}
int SimpleLexer::tokenBefore(const QList<SimpleToken> &tokens, int offset)
{
for (int index = tokens.size() - 1; index >= 0; --index) {
const SimpleToken &tk = tokens.at(index);
if (tk.position() <= offset)
return index;
}
return -1;
}