Commit 7fb6109b authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[scanner] Add Skip to be used after successful Peek

Change-Id: Ic3df370e2859bf77572b34a314ad8ed17b75b942
Reviewed-on: https://chromium-review.googlesource.com/1183485
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55279}
parent ca688f26
......@@ -529,7 +529,8 @@ Token::Value Scanner::ScanHtmlComment() {
PushBack('!'); // undo Advance()
return Token::LT;
}
Advance();
source_->Skip('-');
DCHECK_EQ('-', c0_);
found_html_comment_ = true;
return SkipSingleHTMLComment();
......@@ -674,7 +675,7 @@ void Scanner::Scan() {
if (c0_ == '/') {
uc32 c = Peek();
if (c == '#' || c == '@') {
Advance();
source_->Skip(c);
Advance();
token = SkipSourceURLComment();
} else {
......@@ -727,7 +728,7 @@ void Scanner::Scan() {
token = Token::PERIOD;
if (c0_ == '.') {
if (Peek() == '.') {
Advance();
source_->Skip('.');
Advance();
token = Token::ELLIPSIS;
}
......@@ -1004,8 +1005,8 @@ Token::Value Scanner::ScanTemplateSpan() {
result = Token::TEMPLATE_TAIL;
break;
} else if (c == '$' && Peek() == '{') {
Advance(); // Consume '$'
Advance(); // Consume '{'
source_->Skip('{');
Advance();
break;
} else if (c == '\\') {
Advance(); // Consume '\\'
......
......@@ -50,6 +50,12 @@ class Utf16CharacterStream {
}
}
inline void Skip(uc32 c) {
DCHECK_LT(buffer_cursor_, buffer_end_);
DCHECK_EQ(c, static_cast<uc32>(*buffer_cursor_));
buffer_cursor_++;
}
// Returns and advances past the next UTF-16 code unit in the input
// stream. If there are no more code units it returns kEndOfInput.
inline uc32 Advance() {
......@@ -634,13 +640,13 @@ class Scanner {
bool CombineSurrogatePair() {
DCHECK(!unibrow::Utf16::IsLeadSurrogate(kEndOfInput));
if (unibrow::Utf16::IsLeadSurrogate(c0_)) {
uc32 c1 = source_->Advance();
uc32 c1 = source_->Peek();
DCHECK(!unibrow::Utf16::IsTrailSurrogate(kEndOfInput));
if (unibrow::Utf16::IsTrailSurrogate(c1)) {
c0_ = unibrow::Utf16::CombineSurrogatePair(c0_, c1);
source_->Skip(c1);
return true;
}
source_->Back();
}
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment