diff options
-rw-r--r-- | test/TableGen/String.td | 5 | ||||
-rw-r--r-- | utils/TableGen/TGLexer.cpp | 26 |
2 files changed, 30 insertions, 1 deletions
diff --git a/test/TableGen/String.td b/test/TableGen/String.td new file mode 100644 index 0000000..d2ae451 --- /dev/null +++ b/test/TableGen/String.td @@ -0,0 +1,5 @@ +// RUN: tblgen %s +class x { + string y = "missing terminating '\"' character"; +} + 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; } |