Skip over whitespace using loop. NFC.

Else we can stack overflow on a long sequence of whitespace.

PiperOrigin-RevId: 228893517
This commit is contained in:
Jacques Pienaar 2019-01-11 09:24:02 -08:00 committed by jpienaar
parent 311af4abf3
commit 4fd6db3e29
1 changed files with 16 additions and 7 deletions

View File

@ -64,6 +64,22 @@ Token Lexer::emitError(const char *loc, const Twine &message) {
Token Lexer::lexToken() {
const char *tokStart = curPtr;
// Ignore whitespace.
while (curPtr) {
switch (*curPtr) {
case ' ':
case '\t':
case '\n':
case '\r':
++curPtr;
continue;
default:
break;
}
tokStart = curPtr;
break;
}
switch (*curPtr++) {
default:
// Handle bare identifiers.
@ -84,13 +100,6 @@ Token Lexer::lexToken() {
return formToken(Token::eof, tokStart);
LLVM_FALLTHROUGH;
case ' ':
case '\t':
case '\n':
case '\r':
// Ignore whitespace.
return lexToken();
case ':': return formToken(Token::colon, tokStart);
case ',': return formToken(Token::comma, tokStart);
case '(': return formToken(Token::l_paren, tokStart);