forked from qt-creator/qt-creator
Introduced BackwardsScanner::LA(n). LA(n) returns the n-th lookhead token.
This commit is contained in:
@@ -45,6 +45,8 @@ BackwardsScanner::BackwardsScanner(const QTextCursor &cursor, const QString &suf
|
|||||||
_text += suffix;
|
_text += suffix;
|
||||||
|
|
||||||
_tokens.append(_tokenize(_text, previousBlockState(_block)));
|
_tokens.append(_tokenize(_text, previousBlockState(_block)));
|
||||||
|
|
||||||
|
_startToken = _tokens.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BackwardsScanner::state() const
|
int BackwardsScanner::state() const
|
||||||
@@ -53,8 +55,11 @@ int BackwardsScanner::state() const
|
|||||||
const QList<SimpleToken> &BackwardsScanner::tokens() const
|
const QList<SimpleToken> &BackwardsScanner::tokens() const
|
||||||
{ return _tokens; }
|
{ return _tokens; }
|
||||||
|
|
||||||
const SimpleToken &BackwardsScanner::operator[](int i) const
|
const SimpleToken &BackwardsScanner::LA(int index) const
|
||||||
{ return const_cast<BackwardsScanner *>(this)->fetchToken(i); }
|
{ return const_cast<BackwardsScanner *>(this)->fetchToken(_startToken - index); }
|
||||||
|
|
||||||
|
const SimpleToken &BackwardsScanner::operator[](int index) const
|
||||||
|
{ return const_cast<BackwardsScanner *>(this)->fetchToken(index); }
|
||||||
|
|
||||||
const SimpleToken &BackwardsScanner::fetchToken(int i)
|
const SimpleToken &BackwardsScanner::fetchToken(int i)
|
||||||
{
|
{
|
||||||
@@ -89,7 +94,7 @@ const SimpleToken &BackwardsScanner::fetchToken(int i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int BackwardsScanner::startToken() const
|
int BackwardsScanner::startToken() const
|
||||||
{ return _tokens.size(); }
|
{ return _startToken; }
|
||||||
|
|
||||||
int BackwardsScanner::startPosition() const
|
int BackwardsScanner::startPosition() const
|
||||||
{ return _block.position(); }
|
{ return _block.position(); }
|
||||||
|
|||||||
@@ -54,7 +54,11 @@ public:
|
|||||||
QString text(int begin, int end) const;
|
QString text(int begin, int end) const;
|
||||||
QStringRef textRef(int begin, int end) const;
|
QStringRef textRef(int begin, int end) const;
|
||||||
|
|
||||||
const SimpleToken &operator[](int i) const;
|
// 1-based
|
||||||
|
const SimpleToken &LA(int index) const;
|
||||||
|
|
||||||
|
// n-la token is [startToken - n]
|
||||||
|
const SimpleToken &operator[](int index) const; // ### deprecate
|
||||||
|
|
||||||
int startOfMatchingBrace(int index) const;
|
int startOfMatchingBrace(int index) const;
|
||||||
int previousBlockState(const QTextBlock &block) const;
|
int previousBlockState(const QTextBlock &block) const;
|
||||||
@@ -71,6 +75,7 @@ private:
|
|||||||
QString _text;
|
QString _text;
|
||||||
SimpleLexer _tokenize;
|
SimpleLexer _tokenize;
|
||||||
int _maxBlockCount;
|
int _maxBlockCount;
|
||||||
|
int _startToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace CPlusPlus
|
} // end of namespace CPlusPlus
|
||||||
|
|||||||
Reference in New Issue
Block a user