From 81cac3cc49c5ea7817cc04479d706d426f528bc0 Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Fri, 18 Sep 2009 11:14:54 +0200 Subject: [PATCH] Introduced BackwardsScanner::LA(n). LA(n) returns the n-th lookhead token. --- src/libs/cplusplus/BackwardsScanner.cpp | 11 ++++++++--- src/libs/cplusplus/BackwardsScanner.h | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libs/cplusplus/BackwardsScanner.cpp b/src/libs/cplusplus/BackwardsScanner.cpp index 07c4688757a..b0b71ffecdf 100644 --- a/src/libs/cplusplus/BackwardsScanner.cpp +++ b/src/libs/cplusplus/BackwardsScanner.cpp @@ -45,6 +45,8 @@ BackwardsScanner::BackwardsScanner(const QTextCursor &cursor, const QString &suf _text += suffix; _tokens.append(_tokenize(_text, previousBlockState(_block))); + + _startToken = _tokens.size(); } int BackwardsScanner::state() const @@ -53,8 +55,11 @@ int BackwardsScanner::state() const const QList<SimpleToken> &BackwardsScanner::tokens() const { return _tokens; } -const SimpleToken &BackwardsScanner::operator[](int i) const -{ return const_cast<BackwardsScanner *>(this)->fetchToken(i); } +const SimpleToken &BackwardsScanner::LA(int index) const +{ 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) { @@ -89,7 +94,7 @@ const SimpleToken &BackwardsScanner::fetchToken(int i) } int BackwardsScanner::startToken() const -{ return _tokens.size(); } +{ return _startToken; } int BackwardsScanner::startPosition() const { return _block.position(); } diff --git a/src/libs/cplusplus/BackwardsScanner.h b/src/libs/cplusplus/BackwardsScanner.h index 7b8e3b6e717..68d1f047878 100644 --- a/src/libs/cplusplus/BackwardsScanner.h +++ b/src/libs/cplusplus/BackwardsScanner.h @@ -54,7 +54,11 @@ public: QString text(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 previousBlockState(const QTextBlock &block) const; @@ -71,6 +75,7 @@ private: QString _text; SimpleLexer _tokenize; int _maxBlockCount; + int _startToken; }; } // end of namespace CPlusPlus -- GitLab