Skip to content
Snippets Groups Projects
Commit 81cac3cc authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Introduced BackwardsScanner::LA(n). LA(n) returns the n-th lookhead token.

parent 8ce39a8a
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,8 @@ BackwardsScanner::BackwardsScanner(const QTextCursor &cursor, const QString &suf ...@@ -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 ...@@ -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) ...@@ -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: ...@@ -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: ...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment