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
This commit is contained in:
Chris Lattner 2009-03-13 21:03:27 +00:00
parent 55a07b20cd
commit ea9f4df616
2 changed files with 30 additions and 1 deletions

5
test/TableGen/String.td Normal file
View File

@ -0,0 +1,5 @@
// RUN: tblgen %s
class x {
string y = "missing terminating '\"' character";
}

View File

@ -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;
}