OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 using namespace v8::internal; | 58 using namespace v8::internal; |
59 | 59 |
60 | 60 |
61 static bool CheckParse(const char* input) { | 61 static bool CheckParse(const char* input) { |
62 V8::Initialize(NULL); | 62 V8::Initialize(NULL); |
63 v8::HandleScope scope; | 63 v8::HandleScope scope; |
64 ZoneScope zone_scope(DELETE_ON_EXIT); | 64 ZoneScope zone_scope(DELETE_ON_EXIT); |
65 FlatStringReader reader(CStrVector(input)); | 65 FlatStringReader reader(CStrVector(input)); |
66 RegExpCompileData result; | 66 RegExpCompileData result; |
67 return v8::internal::Parser::ParseRegExp(&reader, false, &result); | 67 return v8::internal::RegExpParser::ParseRegExp(&reader, false, &result); |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 static SmartPointer<const char> Parse(const char* input) { | 71 static SmartPointer<const char> Parse(const char* input) { |
72 V8::Initialize(NULL); | 72 V8::Initialize(NULL); |
73 v8::HandleScope scope; | 73 v8::HandleScope scope; |
74 ZoneScope zone_scope(DELETE_ON_EXIT); | 74 ZoneScope zone_scope(DELETE_ON_EXIT); |
75 FlatStringReader reader(CStrVector(input)); | 75 FlatStringReader reader(CStrVector(input)); |
76 RegExpCompileData result; | 76 RegExpCompileData result; |
77 CHECK(v8::internal::Parser::ParseRegExp(&reader, false, &result)); | 77 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
78 CHECK(result.tree != NULL); | 78 CHECK(result.tree != NULL); |
79 CHECK(result.error.is_null()); | 79 CHECK(result.error.is_null()); |
80 SmartPointer<const char> output = result.tree->ToString(); | 80 SmartPointer<const char> output = result.tree->ToString(); |
81 return output; | 81 return output; |
82 } | 82 } |
83 | 83 |
84 static bool CheckSimple(const char* input) { | 84 static bool CheckSimple(const char* input) { |
85 V8::Initialize(NULL); | 85 V8::Initialize(NULL); |
86 v8::HandleScope scope; | 86 v8::HandleScope scope; |
87 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); | 87 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); |
88 ZoneScope zone_scope(DELETE_ON_EXIT); | 88 ZoneScope zone_scope(DELETE_ON_EXIT); |
89 FlatStringReader reader(CStrVector(input)); | 89 FlatStringReader reader(CStrVector(input)); |
90 RegExpCompileData result; | 90 RegExpCompileData result; |
91 CHECK(v8::internal::Parser::ParseRegExp(&reader, false, &result)); | 91 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
92 CHECK(result.tree != NULL); | 92 CHECK(result.tree != NULL); |
93 CHECK(result.error.is_null()); | 93 CHECK(result.error.is_null()); |
94 return result.simple; | 94 return result.simple; |
95 } | 95 } |
96 | 96 |
97 struct MinMaxPair { | 97 struct MinMaxPair { |
98 int min_match; | 98 int min_match; |
99 int max_match; | 99 int max_match; |
100 }; | 100 }; |
101 | 101 |
102 static MinMaxPair CheckMinMaxMatch(const char* input) { | 102 static MinMaxPair CheckMinMaxMatch(const char* input) { |
103 V8::Initialize(NULL); | 103 V8::Initialize(NULL); |
104 v8::HandleScope scope; | 104 v8::HandleScope scope; |
105 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); | 105 unibrow::Utf8InputBuffer<> buffer(input, StrLength(input)); |
106 ZoneScope zone_scope(DELETE_ON_EXIT); | 106 ZoneScope zone_scope(DELETE_ON_EXIT); |
107 FlatStringReader reader(CStrVector(input)); | 107 FlatStringReader reader(CStrVector(input)); |
108 RegExpCompileData result; | 108 RegExpCompileData result; |
109 CHECK(v8::internal::Parser::ParseRegExp(&reader, false, &result)); | 109 CHECK(v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
110 CHECK(result.tree != NULL); | 110 CHECK(result.tree != NULL); |
111 CHECK(result.error.is_null()); | 111 CHECK(result.error.is_null()); |
112 int min_match = result.tree->min_match(); | 112 int min_match = result.tree->min_match(); |
113 int max_match = result.tree->max_match(); | 113 int max_match = result.tree->max_match(); |
114 MinMaxPair pair = { min_match, max_match }; | 114 MinMaxPair pair = { min_match, max_match }; |
115 return pair; | 115 return pair; |
116 } | 116 } |
117 | 117 |
118 | 118 |
119 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) | 119 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 CHECK_PARSE_EQ("a|", "(| 'a' %)"); | 358 CHECK_PARSE_EQ("a|", "(| 'a' %)"); |
359 } | 359 } |
360 | 360 |
361 static void ExpectError(const char* input, | 361 static void ExpectError(const char* input, |
362 const char* expected) { | 362 const char* expected) { |
363 V8::Initialize(NULL); | 363 V8::Initialize(NULL); |
364 v8::HandleScope scope; | 364 v8::HandleScope scope; |
365 ZoneScope zone_scope(DELETE_ON_EXIT); | 365 ZoneScope zone_scope(DELETE_ON_EXIT); |
366 FlatStringReader reader(CStrVector(input)); | 366 FlatStringReader reader(CStrVector(input)); |
367 RegExpCompileData result; | 367 RegExpCompileData result; |
368 CHECK_EQ(false, v8::internal::Parser::ParseRegExp(&reader, false, &result)); | 368 CHECK(!v8::internal::RegExpParser::ParseRegExp(&reader, false, &result)); |
369 CHECK(result.tree == NULL); | 369 CHECK(result.tree == NULL); |
370 CHECK(!result.error.is_null()); | 370 CHECK(!result.error.is_null()); |
371 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); | 371 SmartPointer<char> str = result.error->ToCString(ALLOW_NULLS); |
372 CHECK_EQ(expected, *str); | 372 CHECK_EQ(expected, *str); |
373 } | 373 } |
374 | 374 |
375 | 375 |
376 TEST(Errors) { | 376 TEST(Errors) { |
377 V8::Initialize(NULL); | 377 V8::Initialize(NULL); |
378 const char* kEndBackslash = "\\ at end of pattern"; | 378 const char* kEndBackslash = "\\ at end of pattern"; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 TestCharacterClassEscapes('S', NotWhiteSpace); | 466 TestCharacterClassEscapes('S', NotWhiteSpace); |
467 TestCharacterClassEscapes('w', IsRegExpWord); | 467 TestCharacterClassEscapes('w', IsRegExpWord); |
468 TestCharacterClassEscapes('W', NotWord); | 468 TestCharacterClassEscapes('W', NotWord); |
469 } | 469 } |
470 | 470 |
471 | 471 |
472 static RegExpNode* Compile(const char* input, bool multiline, bool is_ascii) { | 472 static RegExpNode* Compile(const char* input, bool multiline, bool is_ascii) { |
473 V8::Initialize(NULL); | 473 V8::Initialize(NULL); |
474 FlatStringReader reader(CStrVector(input)); | 474 FlatStringReader reader(CStrVector(input)); |
475 RegExpCompileData compile_data; | 475 RegExpCompileData compile_data; |
476 if (!v8::internal::Parser::ParseRegExp(&reader, multiline, &compile_data)) | 476 if (!v8::internal::RegExpParser::ParseRegExp(&reader, multiline, |
| 477 &compile_data)) |
477 return NULL; | 478 return NULL; |
478 Handle<String> pattern = Factory::NewStringFromUtf8(CStrVector(input)); | 479 Handle<String> pattern = Factory::NewStringFromUtf8(CStrVector(input)); |
479 RegExpEngine::Compile(&compile_data, false, multiline, pattern, is_ascii); | 480 RegExpEngine::Compile(&compile_data, false, multiline, pattern, is_ascii); |
480 return compile_data.node; | 481 return compile_data.node; |
481 } | 482 } |
482 | 483 |
483 | 484 |
484 static void Execute(const char* input, | 485 static void Execute(const char* input, |
485 bool multiline, | 486 bool multiline, |
486 bool is_ascii, | 487 bool is_ascii, |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 bool in_second = CharacterInSet(&l2, i); | 1776 bool in_second = CharacterInSet(&l2, i); |
1776 CHECK((in_first || in_second) == CharacterInSet(&all, i)); | 1777 CHECK((in_first || in_second) == CharacterInSet(&all, i)); |
1777 } | 1778 } |
1778 } | 1779 } |
1779 | 1780 |
1780 | 1781 |
1781 TEST(Graph) { | 1782 TEST(Graph) { |
1782 V8::Initialize(NULL); | 1783 V8::Initialize(NULL); |
1783 Execute("\\b\\w+\\b", false, true, true); | 1784 Execute("\\b\\w+\\b", false, true, true); |
1784 } | 1785 } |
OLD | NEW |