Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: src/scanner.cc

Issue 706263002: Implement ES6 unicode escapes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Features shared by parsing and pre-parsing scanners. 5 // Features shared by parsing and pre-parsing scanners.
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 10
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 switch (c) { 687 switch (c) {
688 case '\'': // fall through 688 case '\'': // fall through
689 case '"' : // fall through 689 case '"' : // fall through
690 case '\\': break; 690 case '\\': break;
691 case 'b' : c = '\b'; break; 691 case 'b' : c = '\b'; break;
692 case 'f' : c = '\f'; break; 692 case 'f' : c = '\f'; break;
693 case 'n' : c = '\n'; break; 693 case 'n' : c = '\n'; break;
694 case 'r' : c = '\r'; break; 694 case 'r' : c = '\r'; break;
695 case 't' : c = '\t'; break; 695 case 't' : c = '\t'; break;
696 case 'u' : { 696 case 'u' : {
697 c = ScanHexNumber(4); 697 c = ScanUnicodeEscape();
698 if (c < 0) return false; 698 if (c < 0) return false;
699 break; 699 break;
700 } 700 }
701 case 'v' : c = '\v'; break; 701 case 'v' : c = '\v'; break;
702 case 'x' : { 702 case 'x' : {
703 c = ScanHexNumber(2); 703 c = ScanHexNumber(2);
704 if (c < 0) return false; 704 if (c < 0) return false;
705 break; 705 break;
706 } 706 }
707 case '0' : // fall through 707 case '0' : // fall through
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 literal.Complete(); 880 literal.Complete();
881 881
882 return Token::NUMBER; 882 return Token::NUMBER;
883 } 883 }
884 884
885 885
886 uc32 Scanner::ScanIdentifierUnicodeEscape() { 886 uc32 Scanner::ScanIdentifierUnicodeEscape() {
887 Advance(); 887 Advance();
888 if (c0_ != 'u') return -1; 888 if (c0_ != 'u') return -1;
889 Advance(); 889 Advance();
890 return ScanHexNumber(4); 890 return ScanUnicodeEscape();
891 } 891 }
892 892
893 893
894 uc32 Scanner::ScanUnicodeEscape() {
895 // Accept both \uxxxx and \u{xxxx}. \ and u have already been read.
896 bool has_brace = false;
897 if (c0_ == '{') {
898 has_brace = true;
899 Advance();
900 }
901 uc32 c = ScanHexNumber(4);
arv (Not doing code reviews) 2014/11/07 16:23:20 In case of u{ then there is no upper limit for the
caitp (gmail) 2014/11/07 16:23:55 If `has_brace` is true, we want the HexDigits non-
marja 2014/11/13 11:53:20 Done.
902 if (c < 0) {
903 return c;
904 }
905 if (has_brace) {
906 if (c0_ != '}') {
907 return 1;
caitp (gmail) 2014/11/07 16:50:39 shouldn't this return -1 so that the scanner knows
marja 2014/11/13 11:53:20 Done.
908 }
909 Advance();
910 }
911 return c;
912 }
913
914
894 // ---------------------------------------------------------------------------- 915 // ----------------------------------------------------------------------------
895 // Keyword Matcher 916 // Keyword Matcher
896 917
897 #define KEYWORDS(KEYWORD_GROUP, KEYWORD) \ 918 #define KEYWORDS(KEYWORD_GROUP, KEYWORD) \
898 KEYWORD_GROUP('b') \ 919 KEYWORD_GROUP('b') \
899 KEYWORD("break", Token::BREAK) \ 920 KEYWORD("break", Token::BREAK) \
900 KEYWORD_GROUP('c') \ 921 KEYWORD_GROUP('c') \
901 KEYWORD("case", Token::CASE) \ 922 KEYWORD("case", Token::CASE) \
902 KEYWORD("catch", Token::CATCH) \ 923 KEYWORD("catch", Token::CATCH) \
903 KEYWORD("class", \ 924 KEYWORD("class", \
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 } 1347 }
1327 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); 1348 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1328 } 1349 }
1329 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); 1350 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1330 1351
1331 backing_store_.AddBlock(bytes); 1352 backing_store_.AddBlock(bytes);
1332 return backing_store_.EndSequence().start(); 1353 return backing_store_.EndSequence().start();
1333 } 1354 }
1334 1355
1335 } } // namespace v8::internal 1356 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scanner.h ('k') | test/cctest/test-parsing.cc » ('j') | test/cctest/test-parsing.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698