Chromium Code Reviews| Index: src/scanner.cc |
| diff --git a/src/scanner.cc b/src/scanner.cc |
| index ddcd937584d50fc45fa921a25e2a5d21fcf5697e..8e05006688c0084c98719c553cfc7634a2f3cec8 100644 |
| --- a/src/scanner.cc |
| +++ b/src/scanner.cc |
| @@ -404,6 +404,7 @@ Token::Value Scanner::ScanHtmlComment() { |
| void Scanner::Scan() { |
| next_.literal_chars = NULL; |
| Token::Value token; |
| + |
| do { |
| // Remember the position of the next token |
| next_.location.beg_pos = source_pos(); |
| @@ -626,6 +627,12 @@ void Scanner::Scan() { |
| token = Select(Token::BIT_NOT); |
| break; |
| + case '`': |
| + if (HarmonyTemplates()) { |
| + token = ScanTemplateSpan(); |
| + break; |
| + } |
| + |
| default: |
| if (c0_ < 0) { |
| token = Token::EOS; |
| @@ -673,6 +680,7 @@ void Scanner::SeekForward(int pos) { |
| bool Scanner::ScanEscape() { |
| uc32 c = c0_; |
| + bool singleCharEscape = true; |
|
arv (Not doing code reviews)
2014/11/11 17:15:15
This is no longer used
|
| Advance(); |
| // Skip escaped newlines. |
| @@ -694,12 +702,14 @@ bool Scanner::ScanEscape() { |
| case 'r' : c = '\r'; break; |
| case 't' : c = '\t'; break; |
| case 'u' : { |
| + singleCharEscape = false; |
| c = ScanHexNumber(4); |
| if (c < 0) return false; |
| break; |
| } |
| case 'v' : c = '\v'; break; |
| case 'x' : { |
| + singleCharEscape = false; |
| c = ScanHexNumber(2); |
| if (c < 0) return false; |
| break; |
| @@ -711,7 +721,10 @@ bool Scanner::ScanEscape() { |
| case '4' : // fall through |
| case '5' : // fall through |
| case '6' : // fall through |
| - case '7' : c = ScanOctalEscape(c, 2); break; |
| + case '7': |
| + singleCharEscape = false; |
| + c = ScanOctalEscape(c, 2); |
| + break; |
| } |
| // According to ECMA-262, section 7.8.4, characters not covered by the |
| @@ -770,6 +783,80 @@ Token::Value Scanner::ScanString() { |
| } |
| +Token::Value Scanner::ScanTemplateSpan() { |
| + // When scanning a TemplateSpan, we are looking for the following construct: |
| + // TEMPLATE_SPAN :: |
| + // ` LiteralChars* ${ |
| + // | } LiteralChars* ${ |
| + // |
| + // TEMPLATE_TAIL :: |
| + // ` LiteralChars* ` |
| + // | } LiteralChar* ` |
| + // |
| + // A TEMPLATE_SPAN should always be followed by an Expression, while a |
| + // TEMPLATE_TAIL terminates a TemplateLiteral and does not need to be |
| + // followed by an Expression. |
| + // |
| + |
| + if (next_.token == Token::RBRACE) { |
| + // After parsing an Expression, the source position is incorrect due to |
| + // having scanned the brace. Push the RBRACE back into the stream. |
| + PushBack('}'); |
| + } |
| + |
| + next_.location.beg_pos = source_pos(); |
| + Token::Value result = Token::ILLEGAL; |
| + DCHECK(c0_ == '`' || c0_ == '}'); |
| + Advance(); // Consume ` or } |
| + |
| + LiteralScope literal(this); |
| + while (true) { |
| + uc32 c = c0_; |
| + Advance(); |
| + if (c == '`') { |
| + result = Token::TEMPLATE_TAIL; |
| + break; |
| + } else if (c == '$' && c0_ == '{') { |
| + Advance(); // Consume '{' |
| + result = Token::TEMPLATE_SPAN; |
| + break; |
| + } else if (c == '\\') { |
| + if (unicode_cache_->IsLineTerminator(c0_)) { |
| + // The TV of LineContinuation :: \ LineTerminatorSequence is the empty |
| + // code unit sequence. |
| + do { |
| + uc32 lastChar = c0_; |
| + Advance(); |
| + if (lastChar == '\r' && c0_ == '\n') Advance(); |
| + } while (unicode_cache_->IsLineTerminator(c0_)); |
| + } else if (c0_ == '0') { |
| + Advance(); |
| + AddLiteralChar('0'); |
| + } else { |
| + ScanEscape(); |
| + } |
| + } else if (c < 0) { |
| + // Unterminated template literal |
| + PushBack(c); |
| + break; |
| + } else { |
| + // The TRV of LineTerminatorSequence :: <CR> is the CV 0x000A. |
| + // The TRV of LineTerminatorSequence :: <CR><LF> is the sequence |
| + // consisting of the CV 0x000A. |
| + if (c == '\r') { |
| + if (c0_ == '\n') Advance(); |
| + c = '\n'; |
| + } |
| + AddLiteralChar(c); |
| + } |
| + } |
| + literal.Complete(); |
| + next_.location.end_pos = source_pos(); |
| + next_.token = result; |
| + return result; |
| +} |
| + |
| + |
| void Scanner::ScanDecimalDigits() { |
| while (IsDecimalDigit(c0_)) |
| AddLiteralCharAdvance(); |