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

Side by Side Diff: src/parser.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
« no previous file with comments | « src/parser.h ('k') | src/scanner.h » ('j') | src/scanner.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 4393 matching lines...) Expand 10 before | Expand all | Expand 10 after
4404 if (ParseHexEscape(2, &value)) { 4404 if (ParseHexEscape(2, &value)) {
4405 builder->AddCharacter(value); 4405 builder->AddCharacter(value);
4406 } else { 4406 } else {
4407 builder->AddCharacter('x'); 4407 builder->AddCharacter('x');
4408 } 4408 }
4409 break; 4409 break;
4410 } 4410 }
4411 case 'u': { 4411 case 'u': {
4412 Advance(2); 4412 Advance(2);
4413 uc32 value; 4413 uc32 value;
4414 if (ParseHexEscape(4, &value)) { 4414 if (ParseHexEscape(4, &value, true)) {
4415 builder->AddCharacter(value); 4415 builder->AddCharacter(value);
4416 } else { 4416 } else {
4417 builder->AddCharacter('u'); 4417 builder->AddCharacter('u');
4418 } 4418 }
4419 break; 4419 break;
4420 } 4420 }
4421 default: 4421 default:
4422 // Identity escape. 4422 // Identity escape.
4423 builder->AddCharacter(Next()); 4423 builder->AddCharacter(Next());
4424 Advance(2); 4424 Advance(2);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
4657 Advance(); 4657 Advance();
4658 if (value < 32 && '0' <= current() && current() <= '7') { 4658 if (value < 32 && '0' <= current() && current() <= '7') {
4659 value = value * 8 + current() - '0'; 4659 value = value * 8 + current() - '0';
4660 Advance(); 4660 Advance();
4661 } 4661 }
4662 } 4662 }
4663 return value; 4663 return value;
4664 } 4664 }
4665 4665
4666 4666
4667 bool RegExpParser::ParseHexEscape(int length, uc32 *value) { 4667 bool RegExpParser::ParseHexEscape(int length, uc32* value, bool allow_brace) {
4668 int start = position(); 4668 int start = position();
4669 uc32 val = 0; 4669 uc32 val = 0;
4670 bool done = false; 4670 bool has_brace = false;
4671 for (int i = 0; !done; i++) { 4671 if (allow_brace && current() == '{') {
4672 has_brace = true;
4673 Advance();
4674 }
4675 for (int i = 0; i < length; ++i) {
4672 uc32 c = current(); 4676 uc32 c = current();
4673 int d = HexValue(c); 4677 int d = HexValue(c);
4674 if (d < 0) { 4678 if (d < 0) {
4675 Reset(start); 4679 Reset(start);
4676 return false; 4680 return false;
4677 } 4681 }
4678 val = val * 16 + d; 4682 val = val * 16 + d;
4679 Advance(); 4683 Advance();
4680 if (i == length - 1) { 4684 }
4681 done = true; 4685 if (has_brace) {
4686 if (current() != '}') {
4687 Reset(start);
4688 return false;
4682 } 4689 }
4690 Advance();
4683 } 4691 }
4684 *value = val; 4692 *value = val;
4685 return true; 4693 return true;
4686 } 4694 }
4687 4695
4688 4696
4689 uc32 RegExpParser::ParseClassCharacterEscape() { 4697 uc32 RegExpParser::ParseClassCharacterEscape() {
4690 DCHECK(current() == '\\'); 4698 DCHECK(current() == '\\');
4691 DCHECK(has_next() && !IsSpecialClassEscape(Next())); 4699 DCHECK(has_next() && !IsSpecialClassEscape(Next()));
4692 Advance(); 4700 Advance();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4740 if (ParseHexEscape(2, &value)) { 4748 if (ParseHexEscape(2, &value)) {
4741 return value; 4749 return value;
4742 } 4750 }
4743 // If \x is not followed by a two-digit hexadecimal, treat it 4751 // If \x is not followed by a two-digit hexadecimal, treat it
4744 // as an identity escape. 4752 // as an identity escape.
4745 return 'x'; 4753 return 'x';
4746 } 4754 }
4747 case 'u': { 4755 case 'u': {
4748 Advance(); 4756 Advance();
4749 uc32 value; 4757 uc32 value;
4750 if (ParseHexEscape(4, &value)) { 4758 if (ParseHexEscape(4, &value, true)) {
4751 return value; 4759 return value;
4752 } 4760 }
4753 // If \u is not followed by a four-digit hexadecimal, treat it 4761 // If \u is not followed by a four-digit hexadecimal, treat it
4754 // as an identity escape. 4762 // as an identity escape.
4755 return 'u'; 4763 return 'u';
4756 } 4764 }
4757 default: { 4765 default: {
4758 // Extended identity escape. We accept any character that hasn't 4766 // Extended identity escape. We accept any character that hasn't
4759 // been matched by a more specific case, not just the subset required 4767 // been matched by a more specific case, not just the subset required
4760 // by the ECMAScript specification. 4768 // by the ECMAScript specification.
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
4955 4963
4956 // We cannot internalize on a background thread; a foreground task will take 4964 // We cannot internalize on a background thread; a foreground task will take
4957 // care of calling Parser::Internalize just before compilation. 4965 // care of calling Parser::Internalize just before compilation.
4958 4966
4959 if (compile_options() == ScriptCompiler::kProduceParserCache) { 4967 if (compile_options() == ScriptCompiler::kProduceParserCache) {
4960 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); 4968 if (result != NULL) *info_->cached_data() = recorder.GetScriptData();
4961 log_ = NULL; 4969 log_ = NULL;
4962 } 4970 }
4963 } 4971 }
4964 } } // namespace v8::internal 4972 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/scanner.h » ('j') | src/scanner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698