Add Peek
authorDavid Greene <greened@obbligato.org>
Wed, 19 Oct 2011 13:03:35 +0000 (13:03 +0000)
committerDavid Greene <greened@obbligato.org>
Wed, 19 Oct 2011 13:03:35 +0000 (13:03 +0000)
Add a peek function to let the Lexer look at a character arbitrarily
far ahead in the stream without consuming anything.  We need this to
disambiguate numbers and operands of a paste operation.  For example:

def foo#8i

Without lookahead the lexer will treat '8' as a number rather than as
part of a string to be pasted to form an identifier.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142512 91177308-0d34-0410-b5e6-96231b3b80d8

lib/TableGen/TGLexer.cpp
lib/TableGen/TGLexer.h

index 8c1b4290548de11577138afb7d30f658978a1f45..c1b00b66ef5a4c2cc4e735b886a567a7a63b4f55 100644 (file)
@@ -80,6 +80,10 @@ int TGLexer::getNextChar() {
   }  
 }
 
+int TGLexer::peekNextChar(int Index) {
+  return *(CurPtr + Index);
+}
+
 tgtok::TokKind TGLexer::LexToken() {
   TokStart = CurPtr;
   // This always consumes at least one character.
index 84d328b12d9764d894cc8b626e49d60e36db32c0..24f8ea4ce5a0202b964c7edfe389fb9f2282c379 100644 (file)
@@ -109,6 +109,7 @@ private:
   tgtok::TokKind ReturnError(const char *Loc, const Twine &Msg);
   
   int getNextChar();
+  int peekNextChar(int Index);
   void SkipBCPLComment();
   bool SkipCComment();
   tgtok::TokKind LexIdentifier();