diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-13 21:03:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-13 21:03:27 +0000 |
commit | 2b30c030ce731867afd39f6d08cf2a1077a6d83e (patch) | |
tree | 8450b96eddbbda62584f2a86ae5e6c43b5e75eaa /utils | |
parent | 3fd1aa7393d1828e582986a75cbdd422ab07f621 (diff) | |
download | external_llvm-2b30c030ce731867afd39f6d08cf2a1077a6d83e.zip external_llvm-2b30c030ce731867afd39f6d08cf2a1077a6d83e.tar.gz external_llvm-2b30c030ce731867afd39f6d08cf2a1077a6d83e.tar.bz2 |
add support for a few simple escape characters in tblgen strings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66949 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r-- | utils/TableGen/TGLexer.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/utils/TableGen/TGLexer.cpp b/utils/TableGen/TGLexer.cpp index e315db2..8b81091 100644 --- a/utils/TableGen/TGLexer.cpp +++ b/utils/TableGen/TGLexer.cpp @@ -151,6 +151,8 @@ tgtok::TokKind TGLexer::LexToken() { tgtok::TokKind TGLexer::LexString() { const char *StrStart = CurPtr; + CurStrVal = ""; + while (*CurPtr != '"') { // If we hit the end of the buffer, report an error. if (*CurPtr == 0 && CurPtr == CurBuf->getBufferEnd()) @@ -159,10 +161,32 @@ tgtok::TokKind TGLexer::LexString() { if (*CurPtr == '\n' || *CurPtr == '\r') return ReturnError(StrStart, "End of line in string literal"); + if (*CurPtr != '\\') { + CurStrVal += *CurPtr++; + continue; + } + ++CurPtr; + + switch (*CurPtr) { + case '\\': case '\'': case '"': + // These turn into their literal character. + CurStrVal += *CurPtr++; + break; + case '\n': + case '\r': + return ReturnError(CurPtr, "escaped newlines not supported in tblgen"); + + // If we hit the end of the buffer, report an error. + case '\0': + if (CurPtr == CurBuf->getBufferEnd()) + return ReturnError(StrStart, "End of file in string literal"); + // FALL THROUGH + default: + return ReturnError(CurPtr, "invalid escape in string literal"); + } } - CurStrVal.assign(StrStart, CurPtr); ++CurPtr; return tgtok::StrVal; } |