forked from OSchip/llvm-project
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:
parent
311af4abf3
commit
4fd6db3e29
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue