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

Side by Side Diff: runtime/vm/regexp_parser.cc

Issue 539153002: Port and integrate the irregexp engine from V8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Port remaining V8 regexp tests and fix exposed bugs. Created 6 years, 2 months 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 (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/longjump.h" 5 #include "vm/longjump.h"
6 #include "vm/object_store.h" 6 #include "vm/object_store.h"
7 #include "vm/regexp_parser.h" 7 #include "vm/regexp_parser.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 242 }
243 243
244 244
245 void RegExpParser::Reset(intptr_t pos) { 245 void RegExpParser::Reset(intptr_t pos) {
246 next_pos_ = pos; 246 next_pos_ = pos;
247 has_more_ = (pos < in().Length()); 247 has_more_ = (pos < in().Length());
248 Advance(); 248 Advance();
249 } 249 }
250 250
251 251
252 bool RegExpParser::ParseFunction(ParsedFunction *parsed_function) {
253 Isolate* isolate = parsed_function->isolate();
254 JSRegExp& regexp = JSRegExp::Handle(parsed_function->function().regexp());
255
256 const String& pattern = String::Handle(regexp.pattern());
257 const bool multiline = regexp.is_multi_line();
258
259 RegExpCompileData* compile_data = new(isolate) RegExpCompileData();
260 if (!RegExpParser::ParseRegExp(pattern, multiline, compile_data)) {
261 // Parsing failures are handled in the JSRegExp factory constructor.
262 UNREACHABLE();
263 }
264
265 regexp.set_num_bracket_expressions(compile_data->capture_count);
266 if (compile_data->simple) {
267 regexp.set_is_simple();
268 } else {
269 regexp.set_is_complex();
270 }
271
272 parsed_function->SetRegExpCompileData(compile_data);
273
274 return true;
275 }
276
277
252 bool RegExpParser::ParseRegExp(const String& input, 278 bool RegExpParser::ParseRegExp(const String& input,
253 bool multiline, 279 bool multiline,
254 RegExpCompileData* result) { 280 RegExpCompileData* result) {
255 ASSERT(result != NULL); 281 ASSERT(result != NULL);
256 LongJumpScope jump; 282 LongJumpScope jump;
257 RegExpParser parser(input, &result->error, multiline); 283 RegExpParser parser(input, &result->error, multiline);
258 if (setjmp(*jump.Set()) == 0) { 284 if (setjmp(*jump.Set()) == 0) {
259 RegExpTree* tree = parser.ParsePattern(); 285 RegExpTree* tree = parser.ParsePattern();
260 ASSERT(tree != NULL); 286 ASSERT(tree != NULL);
261 ASSERT(result->error.IsNull()); 287 ASSERT(result->error.IsNull());
262 result->tree = tree; 288 result->tree = tree;
263 intptr_t capture_count = parser.captures_started(); 289 intptr_t capture_count = parser.captures_started();
264 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0; 290 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0;
265 result->contains_anchor = parser.contains_anchor(); 291 result->contains_anchor = parser.contains_anchor();
266 result->capture_count = capture_count; 292 result->capture_count = capture_count;
267 } else { 293 } else {
268 ASSERT(!result->error.IsNull()); 294 ASSERT(!result->error.IsNull());
295 Isolate::Current()->object_store()->clear_sticky_error();
269 296
270 // TODO(jgruber): Throw a format exception once we are ready to replace 297 // Throw a FormatException on parsing failures.
271 // jscre. For now, we ignore the error set by LongJump. 298 const String& message = String::Handle(
272 Isolate::Current()->object_store()->clear_sticky_error(); 299 String::Concat(result->error, input));
300 const Array& args = Array::Handle(Array::New(1));
301 args.SetAt(0, message);
302
303 Exceptions::ThrowByType(Exceptions::kFormat, args);
273 } 304 }
274 return !parser.failed(); 305 return !parser.failed();
275 } 306 }
276 307
277 308
278 void RegExpParser::ReportError(const char* message) { 309 void RegExpParser::ReportError(const char* message) {
279 failed_ = true; 310 failed_ = true;
280 *error_ = String::New(message); 311 *error_ = String::New(message);
281 // Zip to the end to make sure the no more input is read. 312 // Zip to the end to make sure the no more input is read.
282 current_ = kEndMarker; 313 current_ = kEndMarker;
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 uint32_t c = ParseClassCharacterEscape(); 1061 uint32_t c = ParseClassCharacterEscape();
1031 return CharacterRange::Singleton(c); 1062 return CharacterRange::Singleton(c);
1032 } 1063 }
1033 } else { 1064 } else {
1034 Advance(); 1065 Advance();
1035 return CharacterRange::Singleton(first); 1066 return CharacterRange::Singleton(first);
1036 } 1067 }
1037 } 1068 }
1038 1069
1039 } // namespace dart 1070 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698