| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 V8::Initialize(NULL); | 82 V8::Initialize(NULL); |
| 83 v8::HandleScope scope(CcTest::isolate()); | 83 v8::HandleScope scope(CcTest::isolate()); |
| 84 Zone zone(CcTest::i_isolate()); | 84 Zone zone(CcTest::i_isolate()); |
| 85 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 85 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
| 86 RegExpCompileData result; | 86 RegExpCompileData result; |
| 87 return v8::internal::RegExpParser::ParseRegExp( | 87 return v8::internal::RegExpParser::ParseRegExp( |
| 88 &reader, false, &result, &zone); | 88 &reader, false, &result, &zone); |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 static SmartArrayPointer<const char> Parse(const char* input) { | 92 static void CheckParseEq(const char* input, const char* expected) { |
| 93 V8::Initialize(NULL); | 93 V8::Initialize(NULL); |
| 94 v8::HandleScope scope(CcTest::isolate()); | 94 v8::HandleScope scope(CcTest::isolate()); |
| 95 Zone zone(CcTest::i_isolate()); | 95 Zone zone(CcTest::i_isolate()); |
| 96 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 96 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
| 97 RegExpCompileData result; | 97 RegExpCompileData result; |
| 98 CHECK(v8::internal::RegExpParser::ParseRegExp( | 98 CHECK(v8::internal::RegExpParser::ParseRegExp( |
| 99 &reader, false, &result, &zone)); | 99 &reader, false, &result, &zone)); |
| 100 CHECK(result.tree != NULL); | 100 CHECK(result.tree != NULL); |
| 101 CHECK(result.error.is_null()); | 101 CHECK(result.error.is_null()); |
| 102 SmartArrayPointer<const char> output = result.tree->ToString(&zone); | 102 OStringStream os; |
| 103 return output; | 103 result.tree->Print(os, &zone); |
| 104 CHECK_EQ(expected, os.c_str()); |
| 104 } | 105 } |
| 105 | 106 |
| 106 | 107 |
| 107 static bool CheckSimple(const char* input) { | 108 static bool CheckSimple(const char* input) { |
| 108 V8::Initialize(NULL); | 109 V8::Initialize(NULL); |
| 109 v8::HandleScope scope(CcTest::isolate()); | 110 v8::HandleScope scope(CcTest::isolate()); |
| 110 Zone zone(CcTest::i_isolate()); | 111 Zone zone(CcTest::i_isolate()); |
| 111 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 112 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
| 112 RegExpCompileData result; | 113 RegExpCompileData result; |
| 113 CHECK(v8::internal::RegExpParser::ParseRegExp( | 114 CHECK(v8::internal::RegExpParser::ParseRegExp( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 134 CHECK(result.tree != NULL); | 135 CHECK(result.tree != NULL); |
| 135 CHECK(result.error.is_null()); | 136 CHECK(result.error.is_null()); |
| 136 int min_match = result.tree->min_match(); | 137 int min_match = result.tree->min_match(); |
| 137 int max_match = result.tree->max_match(); | 138 int max_match = result.tree->max_match(); |
| 138 MinMaxPair pair = { min_match, max_match }; | 139 MinMaxPair pair = { min_match, max_match }; |
| 139 return pair; | 140 return pair; |
| 140 } | 141 } |
| 141 | 142 |
| 142 | 143 |
| 143 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) | 144 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) |
| 144 #define CHECK_PARSE_EQ(input, expected) CHECK_EQ(expected, Parse(input).get()) | |
| 145 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); | 145 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); |
| 146 #define CHECK_MIN_MAX(input, min, max) \ | 146 #define CHECK_MIN_MAX(input, min, max) \ |
| 147 { MinMaxPair min_max = CheckMinMaxMatch(input); \ | 147 { MinMaxPair min_max = CheckMinMaxMatch(input); \ |
| 148 CHECK_EQ(min, min_max.min_match); \ | 148 CHECK_EQ(min, min_max.min_match); \ |
| 149 CHECK_EQ(max, min_max.max_match); \ | 149 CHECK_EQ(max, min_max.max_match); \ |
| 150 } | 150 } |
| 151 | 151 |
| 152 TEST(Parser) { | 152 TEST(Parser) { |
| 153 V8::Initialize(NULL); | 153 V8::Initialize(NULL); |
| 154 | 154 |
| 155 CHECK_PARSE_ERROR("?"); | 155 CHECK_PARSE_ERROR("?"); |
| 156 | 156 |
| 157 CHECK_PARSE_EQ("abc", "'abc'"); | 157 CheckParseEq("abc", "'abc'"); |
| 158 CHECK_PARSE_EQ("", "%"); | 158 CheckParseEq("", "%"); |
| 159 CHECK_PARSE_EQ("abc|def", "(| 'abc' 'def')"); | 159 CheckParseEq("abc|def", "(| 'abc' 'def')"); |
| 160 CHECK_PARSE_EQ("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); | 160 CheckParseEq("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); |
| 161 CHECK_PARSE_EQ("^xxx$", "(: @^i 'xxx' @$i)"); | 161 CheckParseEq("^xxx$", "(: @^i 'xxx' @$i)"); |
| 162 CHECK_PARSE_EQ("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); | 162 CheckParseEq("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); |
| 163 CHECK_PARSE_EQ("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); | 163 CheckParseEq("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); |
| 164 CHECK_PARSE_EQ("a*", "(# 0 - g 'a')"); | 164 CheckParseEq("a*", "(# 0 - g 'a')"); |
| 165 CHECK_PARSE_EQ("a*?", "(# 0 - n 'a')"); | 165 CheckParseEq("a*?", "(# 0 - n 'a')"); |
| 166 CHECK_PARSE_EQ("abc+", "(: 'ab' (# 1 - g 'c'))"); | 166 CheckParseEq("abc+", "(: 'ab' (# 1 - g 'c'))"); |
| 167 CHECK_PARSE_EQ("abc+?", "(: 'ab' (# 1 - n 'c'))"); | 167 CheckParseEq("abc+?", "(: 'ab' (# 1 - n 'c'))"); |
| 168 CHECK_PARSE_EQ("xyz?", "(: 'xy' (# 0 1 g 'z'))"); | 168 CheckParseEq("xyz?", "(: 'xy' (# 0 1 g 'z'))"); |
| 169 CHECK_PARSE_EQ("xyz??", "(: 'xy' (# 0 1 n 'z'))"); | 169 CheckParseEq("xyz??", "(: 'xy' (# 0 1 n 'z'))"); |
| 170 CHECK_PARSE_EQ("xyz{0,1}", "(: 'xy' (# 0 1 g 'z'))"); | 170 CheckParseEq("xyz{0,1}", "(: 'xy' (# 0 1 g 'z'))"); |
| 171 CHECK_PARSE_EQ("xyz{0,1}?", "(: 'xy' (# 0 1 n 'z'))"); | 171 CheckParseEq("xyz{0,1}?", "(: 'xy' (# 0 1 n 'z'))"); |
| 172 CHECK_PARSE_EQ("xyz{93}", "(: 'xy' (# 93 93 g 'z'))"); | 172 CheckParseEq("xyz{93}", "(: 'xy' (# 93 93 g 'z'))"); |
| 173 CHECK_PARSE_EQ("xyz{93}?", "(: 'xy' (# 93 93 n 'z'))"); | 173 CheckParseEq("xyz{93}?", "(: 'xy' (# 93 93 n 'z'))"); |
| 174 CHECK_PARSE_EQ("xyz{1,32}", "(: 'xy' (# 1 32 g 'z'))"); | 174 CheckParseEq("xyz{1,32}", "(: 'xy' (# 1 32 g 'z'))"); |
| 175 CHECK_PARSE_EQ("xyz{1,32}?", "(: 'xy' (# 1 32 n 'z'))"); | 175 CheckParseEq("xyz{1,32}?", "(: 'xy' (# 1 32 n 'z'))"); |
| 176 CHECK_PARSE_EQ("xyz{1,}", "(: 'xy' (# 1 - g 'z'))"); | 176 CheckParseEq("xyz{1,}", "(: 'xy' (# 1 - g 'z'))"); |
| 177 CHECK_PARSE_EQ("xyz{1,}?", "(: 'xy' (# 1 - n 'z'))"); | 177 CheckParseEq("xyz{1,}?", "(: 'xy' (# 1 - n 'z'))"); |
| 178 CHECK_PARSE_EQ("a\\fb\\nc\\rd\\te\\vf", "'a\\x0cb\\x0ac\\x0dd\\x09e\\x0bf'"); | 178 CheckParseEq("a\\fb\\nc\\rd\\te\\vf", "'a\\x0cb\\x0ac\\x0dd\\x09e\\x0bf'"); |
| 179 CHECK_PARSE_EQ("a\\nb\\bc", "(: 'a\\x0ab' @b 'c')"); | 179 CheckParseEq("a\\nb\\bc", "(: 'a\\x0ab' @b 'c')"); |
| 180 CHECK_PARSE_EQ("(?:foo)", "'foo'"); | 180 CheckParseEq("(?:foo)", "'foo'"); |
| 181 CHECK_PARSE_EQ("(?: foo )", "' foo '"); | 181 CheckParseEq("(?: foo )", "' foo '"); |
| 182 CHECK_PARSE_EQ("(foo|bar|baz)", "(^ (| 'foo' 'bar' 'baz'))"); | 182 CheckParseEq("(foo|bar|baz)", "(^ (| 'foo' 'bar' 'baz'))"); |
| 183 CHECK_PARSE_EQ("foo|(bar|baz)|quux", "(| 'foo' (^ (| 'bar' 'baz')) 'quux')"); | 183 CheckParseEq("foo|(bar|baz)|quux", "(| 'foo' (^ (| 'bar' 'baz')) 'quux')"); |
| 184 CHECK_PARSE_EQ("foo(?=bar)baz", "(: 'foo' (-> + 'bar') 'baz')"); | 184 CheckParseEq("foo(?=bar)baz", "(: 'foo' (-> + 'bar') 'baz')"); |
| 185 CHECK_PARSE_EQ("foo(?!bar)baz", "(: 'foo' (-> - 'bar') 'baz')"); | 185 CheckParseEq("foo(?!bar)baz", "(: 'foo' (-> - 'bar') 'baz')"); |
| 186 CHECK_PARSE_EQ("()", "(^ %)"); | 186 CheckParseEq("()", "(^ %)"); |
| 187 CHECK_PARSE_EQ("(?=)", "(-> + %)"); | 187 CheckParseEq("(?=)", "(-> + %)"); |
| 188 CHECK_PARSE_EQ("[]", "^[\\x00-\\uffff]"); // Doesn't compile on windows | 188 CheckParseEq("[]", "^[\\x00-\\uffff]"); // Doesn't compile on windows |
| 189 CHECK_PARSE_EQ("[^]", "[\\x00-\\uffff]"); // \uffff isn't in codepage 1252 | 189 CheckParseEq("[^]", "[\\x00-\\uffff]"); // \uffff isn't in codepage 1252 |
| 190 CHECK_PARSE_EQ("[x]", "[x]"); | 190 CheckParseEq("[x]", "[x]"); |
| 191 CHECK_PARSE_EQ("[xyz]", "[x y z]"); | 191 CheckParseEq("[xyz]", "[x y z]"); |
| 192 CHECK_PARSE_EQ("[a-zA-Z0-9]", "[a-z A-Z 0-9]"); | 192 CheckParseEq("[a-zA-Z0-9]", "[a-z A-Z 0-9]"); |
| 193 CHECK_PARSE_EQ("[-123]", "[- 1 2 3]"); | 193 CheckParseEq("[-123]", "[- 1 2 3]"); |
| 194 CHECK_PARSE_EQ("[^123]", "^[1 2 3]"); | 194 CheckParseEq("[^123]", "^[1 2 3]"); |
| 195 CHECK_PARSE_EQ("]", "']'"); | 195 CheckParseEq("]", "']'"); |
| 196 CHECK_PARSE_EQ("}", "'}'"); | 196 CheckParseEq("}", "'}'"); |
| 197 CHECK_PARSE_EQ("[a-b-c]", "[a-b - c]"); | 197 CheckParseEq("[a-b-c]", "[a-b - c]"); |
| 198 CHECK_PARSE_EQ("[\\d]", "[0-9]"); | 198 CheckParseEq("[\\d]", "[0-9]"); |
| 199 CHECK_PARSE_EQ("[x\\dz]", "[x 0-9 z]"); | 199 CheckParseEq("[x\\dz]", "[x 0-9 z]"); |
| 200 CHECK_PARSE_EQ("[\\d-z]", "[0-9 - z]"); | 200 CheckParseEq("[\\d-z]", "[0-9 - z]"); |
| 201 CHECK_PARSE_EQ("[\\d-\\d]", "[0-9 - 0-9]"); | 201 CheckParseEq("[\\d-\\d]", "[0-9 - 0-9]"); |
| 202 CHECK_PARSE_EQ("[z-\\d]", "[z - 0-9]"); | 202 CheckParseEq("[z-\\d]", "[z - 0-9]"); |
| 203 // Control character outside character class. | 203 // Control character outside character class. |
| 204 CHECK_PARSE_EQ("\\cj\\cJ\\ci\\cI\\ck\\cK", | 204 CheckParseEq("\\cj\\cJ\\ci\\cI\\ck\\cK", "'\\x0a\\x0a\\x09\\x09\\x0b\\x0b'"); |
| 205 "'\\x0a\\x0a\\x09\\x09\\x0b\\x0b'"); | 205 CheckParseEq("\\c!", "'\\c!'"); |
| 206 CHECK_PARSE_EQ("\\c!", "'\\c!'"); | 206 CheckParseEq("\\c_", "'\\c_'"); |
| 207 CHECK_PARSE_EQ("\\c_", "'\\c_'"); | 207 CheckParseEq("\\c~", "'\\c~'"); |
| 208 CHECK_PARSE_EQ("\\c~", "'\\c~'"); | 208 CheckParseEq("\\c1", "'\\c1'"); |
| 209 CHECK_PARSE_EQ("\\c1", "'\\c1'"); | |
| 210 // Control character inside character class. | 209 // Control character inside character class. |
| 211 CHECK_PARSE_EQ("[\\c!]", "[\\ c !]"); | 210 CheckParseEq("[\\c!]", "[\\ c !]"); |
| 212 CHECK_PARSE_EQ("[\\c_]", "[\\x1f]"); | 211 CheckParseEq("[\\c_]", "[\\x1f]"); |
| 213 CHECK_PARSE_EQ("[\\c~]", "[\\ c ~]"); | 212 CheckParseEq("[\\c~]", "[\\ c ~]"); |
| 214 CHECK_PARSE_EQ("[\\ca]", "[\\x01]"); | 213 CheckParseEq("[\\ca]", "[\\x01]"); |
| 215 CHECK_PARSE_EQ("[\\cz]", "[\\x1a]"); | 214 CheckParseEq("[\\cz]", "[\\x1a]"); |
| 216 CHECK_PARSE_EQ("[\\cA]", "[\\x01]"); | 215 CheckParseEq("[\\cA]", "[\\x01]"); |
| 217 CHECK_PARSE_EQ("[\\cZ]", "[\\x1a]"); | 216 CheckParseEq("[\\cZ]", "[\\x1a]"); |
| 218 CHECK_PARSE_EQ("[\\c1]", "[\\x11]"); | 217 CheckParseEq("[\\c1]", "[\\x11]"); |
| 219 | 218 |
| 220 CHECK_PARSE_EQ("[a\\]c]", "[a ] c]"); | 219 CheckParseEq("[a\\]c]", "[a ] c]"); |
| 221 CHECK_PARSE_EQ("\\[\\]\\{\\}\\(\\)\\%\\^\\#\\ ", "'[]{}()%^# '"); | 220 CheckParseEq("\\[\\]\\{\\}\\(\\)\\%\\^\\#\\ ", "'[]{}()%^# '"); |
| 222 CHECK_PARSE_EQ("[\\[\\]\\{\\}\\(\\)\\%\\^\\#\\ ]", "[[ ] { } ( ) % ^ # ]"); | 221 CheckParseEq("[\\[\\]\\{\\}\\(\\)\\%\\^\\#\\ ]", "[[ ] { } ( ) % ^ # ]"); |
| 223 CHECK_PARSE_EQ("\\0", "'\\x00'"); | 222 CheckParseEq("\\0", "'\\x00'"); |
| 224 CHECK_PARSE_EQ("\\8", "'8'"); | 223 CheckParseEq("\\8", "'8'"); |
| 225 CHECK_PARSE_EQ("\\9", "'9'"); | 224 CheckParseEq("\\9", "'9'"); |
| 226 CHECK_PARSE_EQ("\\11", "'\\x09'"); | 225 CheckParseEq("\\11", "'\\x09'"); |
| 227 CHECK_PARSE_EQ("\\11a", "'\\x09a'"); | 226 CheckParseEq("\\11a", "'\\x09a'"); |
| 228 CHECK_PARSE_EQ("\\011", "'\\x09'"); | 227 CheckParseEq("\\011", "'\\x09'"); |
| 229 CHECK_PARSE_EQ("\\00011", "'\\x0011'"); | 228 CheckParseEq("\\00011", "'\\x0011'"); |
| 230 CHECK_PARSE_EQ("\\118", "'\\x098'"); | 229 CheckParseEq("\\118", "'\\x098'"); |
| 231 CHECK_PARSE_EQ("\\111", "'I'"); | 230 CheckParseEq("\\111", "'I'"); |
| 232 CHECK_PARSE_EQ("\\1111", "'I1'"); | 231 CheckParseEq("\\1111", "'I1'"); |
| 233 CHECK_PARSE_EQ("(x)(x)(x)\\1", "(: (^ 'x') (^ 'x') (^ 'x') (<- 1))"); | 232 CheckParseEq("(x)(x)(x)\\1", "(: (^ 'x') (^ 'x') (^ 'x') (<- 1))"); |
| 234 CHECK_PARSE_EQ("(x)(x)(x)\\2", "(: (^ 'x') (^ 'x') (^ 'x') (<- 2))"); | 233 CheckParseEq("(x)(x)(x)\\2", "(: (^ 'x') (^ 'x') (^ 'x') (<- 2))"); |
| 235 CHECK_PARSE_EQ("(x)(x)(x)\\3", "(: (^ 'x') (^ 'x') (^ 'x') (<- 3))"); | 234 CheckParseEq("(x)(x)(x)\\3", "(: (^ 'x') (^ 'x') (^ 'x') (<- 3))"); |
| 236 CHECK_PARSE_EQ("(x)(x)(x)\\4", "(: (^ 'x') (^ 'x') (^ 'x') '\\x04')"); | 235 CheckParseEq("(x)(x)(x)\\4", "(: (^ 'x') (^ 'x') (^ 'x') '\\x04')"); |
| 237 CHECK_PARSE_EQ("(x)(x)(x)\\1*", "(: (^ 'x') (^ 'x') (^ 'x')" | 236 CheckParseEq("(x)(x)(x)\\1*", |
| 238 " (# 0 - g (<- 1)))"); | 237 "(: (^ 'x') (^ 'x') (^ 'x')" |
| 239 CHECK_PARSE_EQ("(x)(x)(x)\\2*", "(: (^ 'x') (^ 'x') (^ 'x')" | 238 " (# 0 - g (<- 1)))"); |
| 240 " (# 0 - g (<- 2)))"); | 239 CheckParseEq("(x)(x)(x)\\2*", |
| 241 CHECK_PARSE_EQ("(x)(x)(x)\\3*", "(: (^ 'x') (^ 'x') (^ 'x')" | 240 "(: (^ 'x') (^ 'x') (^ 'x')" |
| 242 " (# 0 - g (<- 3)))"); | 241 " (# 0 - g (<- 2)))"); |
| 243 CHECK_PARSE_EQ("(x)(x)(x)\\4*", "(: (^ 'x') (^ 'x') (^ 'x')" | 242 CheckParseEq("(x)(x)(x)\\3*", |
| 244 " (# 0 - g '\\x04'))"); | 243 "(: (^ 'x') (^ 'x') (^ 'x')" |
| 245 CHECK_PARSE_EQ("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\10", | 244 " (# 0 - g (<- 3)))"); |
| 246 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" | 245 CheckParseEq("(x)(x)(x)\\4*", |
| 247 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') (<- 10))"); | 246 "(: (^ 'x') (^ 'x') (^ 'x')" |
| 248 CHECK_PARSE_EQ("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\11", | 247 " (# 0 - g '\\x04'))"); |
| 249 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" | 248 CheckParseEq("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\10", |
| 250 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') '\\x09')"); | 249 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" |
| 251 CHECK_PARSE_EQ("(a)\\1", "(: (^ 'a') (<- 1))"); | 250 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') (<- 10))"); |
| 252 CHECK_PARSE_EQ("(a\\1)", "(^ 'a')"); | 251 CheckParseEq("(x)(x)(x)(x)(x)(x)(x)(x)(x)(x)\\11", |
| 253 CHECK_PARSE_EQ("(\\1a)", "(^ 'a')"); | 252 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" |
| 254 CHECK_PARSE_EQ("(?=a)?a", "'a'"); | 253 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') '\\x09')"); |
| 255 CHECK_PARSE_EQ("(?=a){0,10}a", "'a'"); | 254 CheckParseEq("(a)\\1", "(: (^ 'a') (<- 1))"); |
| 256 CHECK_PARSE_EQ("(?=a){1,10}a", "(: (-> + 'a') 'a')"); | 255 CheckParseEq("(a\\1)", "(^ 'a')"); |
| 257 CHECK_PARSE_EQ("(?=a){9,10}a", "(: (-> + 'a') 'a')"); | 256 CheckParseEq("(\\1a)", "(^ 'a')"); |
| 258 CHECK_PARSE_EQ("(?!a)?a", "'a'"); | 257 CheckParseEq("(?=a)?a", "'a'"); |
| 259 CHECK_PARSE_EQ("\\1(a)", "(^ 'a')"); | 258 CheckParseEq("(?=a){0,10}a", "'a'"); |
| 260 CHECK_PARSE_EQ("(?!(a))\\1", "(: (-> - (^ 'a')) (<- 1))"); | 259 CheckParseEq("(?=a){1,10}a", "(: (-> + 'a') 'a')"); |
| 261 CHECK_PARSE_EQ("(?!\\1(a\\1)\\1)\\1", "(: (-> - (: (^ 'a') (<- 1))) (<- 1))"); | 260 CheckParseEq("(?=a){9,10}a", "(: (-> + 'a') 'a')"); |
| 262 CHECK_PARSE_EQ("[\\0]", "[\\x00]"); | 261 CheckParseEq("(?!a)?a", "'a'"); |
| 263 CHECK_PARSE_EQ("[\\11]", "[\\x09]"); | 262 CheckParseEq("\\1(a)", "(^ 'a')"); |
| 264 CHECK_PARSE_EQ("[\\11a]", "[\\x09 a]"); | 263 CheckParseEq("(?!(a))\\1", "(: (-> - (^ 'a')) (<- 1))"); |
| 265 CHECK_PARSE_EQ("[\\011]", "[\\x09]"); | 264 CheckParseEq("(?!\\1(a\\1)\\1)\\1", "(: (-> - (: (^ 'a') (<- 1))) (<- 1))"); |
| 266 CHECK_PARSE_EQ("[\\00011]", "[\\x00 1 1]"); | 265 CheckParseEq("[\\0]", "[\\x00]"); |
| 267 CHECK_PARSE_EQ("[\\118]", "[\\x09 8]"); | 266 CheckParseEq("[\\11]", "[\\x09]"); |
| 268 CHECK_PARSE_EQ("[\\111]", "[I]"); | 267 CheckParseEq("[\\11a]", "[\\x09 a]"); |
| 269 CHECK_PARSE_EQ("[\\1111]", "[I 1]"); | 268 CheckParseEq("[\\011]", "[\\x09]"); |
| 270 CHECK_PARSE_EQ("\\x34", "'\x34'"); | 269 CheckParseEq("[\\00011]", "[\\x00 1 1]"); |
| 271 CHECK_PARSE_EQ("\\x60", "'\x60'"); | 270 CheckParseEq("[\\118]", "[\\x09 8]"); |
| 272 CHECK_PARSE_EQ("\\x3z", "'x3z'"); | 271 CheckParseEq("[\\111]", "[I]"); |
| 273 CHECK_PARSE_EQ("\\c", "'\\c'"); | 272 CheckParseEq("[\\1111]", "[I 1]"); |
| 274 CHECK_PARSE_EQ("\\u0034", "'\x34'"); | 273 CheckParseEq("\\x34", "'\x34'"); |
| 275 CHECK_PARSE_EQ("\\u003z", "'u003z'"); | 274 CheckParseEq("\\x60", "'\x60'"); |
| 276 CHECK_PARSE_EQ("foo[z]*", "(: 'foo' (# 0 - g [z]))"); | 275 CheckParseEq("\\x3z", "'x3z'"); |
| 276 CheckParseEq("\\c", "'\\c'"); |
| 277 CheckParseEq("\\u0034", "'\x34'"); |
| 278 CheckParseEq("\\u003z", "'u003z'"); |
| 279 CheckParseEq("foo[z]*", "(: 'foo' (# 0 - g [z]))"); |
| 277 | 280 |
| 278 CHECK_SIMPLE("", false); | 281 CHECK_SIMPLE("", false); |
| 279 CHECK_SIMPLE("a", true); | 282 CHECK_SIMPLE("a", true); |
| 280 CHECK_SIMPLE("a|b", false); | 283 CHECK_SIMPLE("a|b", false); |
| 281 CHECK_SIMPLE("a\\n", false); | 284 CHECK_SIMPLE("a\\n", false); |
| 282 CHECK_SIMPLE("^a", false); | 285 CHECK_SIMPLE("^a", false); |
| 283 CHECK_SIMPLE("a$", false); | 286 CHECK_SIMPLE("a$", false); |
| 284 CHECK_SIMPLE("a\\b!", false); | 287 CHECK_SIMPLE("a\\b!", false); |
| 285 CHECK_SIMPLE("a\\Bb", false); | 288 CHECK_SIMPLE("a\\Bb", false); |
| 286 CHECK_SIMPLE("a*", false); | 289 CHECK_SIMPLE("a*", false); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 314 CHECK_SIMPLE("\\u0060", false); | 317 CHECK_SIMPLE("\\u0060", false); |
| 315 CHECK_SIMPLE("\\cA", false); | 318 CHECK_SIMPLE("\\cA", false); |
| 316 CHECK_SIMPLE("\\q", false); | 319 CHECK_SIMPLE("\\q", false); |
| 317 CHECK_SIMPLE("\\1112", false); | 320 CHECK_SIMPLE("\\1112", false); |
| 318 CHECK_SIMPLE("\\0", false); | 321 CHECK_SIMPLE("\\0", false); |
| 319 CHECK_SIMPLE("(a)\\1", false); | 322 CHECK_SIMPLE("(a)\\1", false); |
| 320 CHECK_SIMPLE("(?=a)?a", false); | 323 CHECK_SIMPLE("(?=a)?a", false); |
| 321 CHECK_SIMPLE("(?!a)?a\\1", false); | 324 CHECK_SIMPLE("(?!a)?a\\1", false); |
| 322 CHECK_SIMPLE("(?:(?=a))a\\1", false); | 325 CHECK_SIMPLE("(?:(?=a))a\\1", false); |
| 323 | 326 |
| 324 CHECK_PARSE_EQ("a{}", "'a{}'"); | 327 CheckParseEq("a{}", "'a{}'"); |
| 325 CHECK_PARSE_EQ("a{,}", "'a{,}'"); | 328 CheckParseEq("a{,}", "'a{,}'"); |
| 326 CHECK_PARSE_EQ("a{", "'a{'"); | 329 CheckParseEq("a{", "'a{'"); |
| 327 CHECK_PARSE_EQ("a{z}", "'a{z}'"); | 330 CheckParseEq("a{z}", "'a{z}'"); |
| 328 CHECK_PARSE_EQ("a{1z}", "'a{1z}'"); | 331 CheckParseEq("a{1z}", "'a{1z}'"); |
| 329 CHECK_PARSE_EQ("a{12z}", "'a{12z}'"); | 332 CheckParseEq("a{12z}", "'a{12z}'"); |
| 330 CHECK_PARSE_EQ("a{12,", "'a{12,'"); | 333 CheckParseEq("a{12,", "'a{12,'"); |
| 331 CHECK_PARSE_EQ("a{12,3b", "'a{12,3b'"); | 334 CheckParseEq("a{12,3b", "'a{12,3b'"); |
| 332 CHECK_PARSE_EQ("{}", "'{}'"); | 335 CheckParseEq("{}", "'{}'"); |
| 333 CHECK_PARSE_EQ("{,}", "'{,}'"); | 336 CheckParseEq("{,}", "'{,}'"); |
| 334 CHECK_PARSE_EQ("{", "'{'"); | 337 CheckParseEq("{", "'{'"); |
| 335 CHECK_PARSE_EQ("{z}", "'{z}'"); | 338 CheckParseEq("{z}", "'{z}'"); |
| 336 CHECK_PARSE_EQ("{1z}", "'{1z}'"); | 339 CheckParseEq("{1z}", "'{1z}'"); |
| 337 CHECK_PARSE_EQ("{12z}", "'{12z}'"); | 340 CheckParseEq("{12z}", "'{12z}'"); |
| 338 CHECK_PARSE_EQ("{12,", "'{12,'"); | 341 CheckParseEq("{12,", "'{12,'"); |
| 339 CHECK_PARSE_EQ("{12,3b", "'{12,3b'"); | 342 CheckParseEq("{12,3b", "'{12,3b'"); |
| 340 | 343 |
| 341 CHECK_MIN_MAX("a", 1, 1); | 344 CHECK_MIN_MAX("a", 1, 1); |
| 342 CHECK_MIN_MAX("abc", 3, 3); | 345 CHECK_MIN_MAX("abc", 3, 3); |
| 343 CHECK_MIN_MAX("a[bc]d", 3, 3); | 346 CHECK_MIN_MAX("a[bc]d", 3, 3); |
| 344 CHECK_MIN_MAX("a|bc", 1, 2); | 347 CHECK_MIN_MAX("a|bc", 1, 2); |
| 345 CHECK_MIN_MAX("ab|c", 1, 2); | 348 CHECK_MIN_MAX("ab|c", 1, 2); |
| 346 CHECK_MIN_MAX("a||bc", 0, 2); | 349 CHECK_MIN_MAX("a||bc", 0, 2); |
| 347 CHECK_MIN_MAX("|", 0, 0); | 350 CHECK_MIN_MAX("|", 0, 0); |
| 348 CHECK_MIN_MAX("(?:ab)", 2, 2); | 351 CHECK_MIN_MAX("(?:ab)", 2, 2); |
| 349 CHECK_MIN_MAX("(?:ab|cde)", 2, 3); | 352 CHECK_MIN_MAX("(?:ab|cde)", 2, 3); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 CHECK_MIN_MAX("a\\Bc", 2, 2); | 386 CHECK_MIN_MAX("a\\Bc", 2, 2); |
| 384 CHECK_MIN_MAX("a\\sc", 3, 3); | 387 CHECK_MIN_MAX("a\\sc", 3, 3); |
| 385 CHECK_MIN_MAX("a\\Sc", 3, 3); | 388 CHECK_MIN_MAX("a\\Sc", 3, 3); |
| 386 CHECK_MIN_MAX("a(?=b)c", 2, 2); | 389 CHECK_MIN_MAX("a(?=b)c", 2, 2); |
| 387 CHECK_MIN_MAX("a(?=bbb|bb)c", 2, 2); | 390 CHECK_MIN_MAX("a(?=bbb|bb)c", 2, 2); |
| 388 CHECK_MIN_MAX("a(?!bbb|bb)c", 2, 2); | 391 CHECK_MIN_MAX("a(?!bbb|bb)c", 2, 2); |
| 389 } | 392 } |
| 390 | 393 |
| 391 | 394 |
| 392 TEST(ParserRegression) { | 395 TEST(ParserRegression) { |
| 393 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); | 396 CheckParseEq("[A-Z$-][x]", "(! [A-Z $ -] [x])"); |
| 394 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); | 397 CheckParseEq("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); |
| 395 CHECK_PARSE_EQ("{", "'{'"); | 398 CheckParseEq("{", "'{'"); |
| 396 CHECK_PARSE_EQ("a|", "(| 'a' %)"); | 399 CheckParseEq("a|", "(| 'a' %)"); |
| 397 } | 400 } |
| 398 | 401 |
| 399 static void ExpectError(const char* input, | 402 static void ExpectError(const char* input, |
| 400 const char* expected) { | 403 const char* expected) { |
| 401 V8::Initialize(NULL); | 404 V8::Initialize(NULL); |
| 402 v8::HandleScope scope(CcTest::isolate()); | 405 v8::HandleScope scope(CcTest::isolate()); |
| 403 Zone zone(CcTest::i_isolate()); | 406 Zone zone(CcTest::i_isolate()); |
| 404 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); | 407 FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); |
| 405 RegExpCompileData result; | 408 RegExpCompileData result; |
| 406 CHECK(!v8::internal::RegExpParser::ParseRegExp( | 409 CHECK(!v8::internal::RegExpParser::ParseRegExp( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 426 ExpectError("*", kNothingToRepeat); | 429 ExpectError("*", kNothingToRepeat); |
| 427 ExpectError("?", kNothingToRepeat); | 430 ExpectError("?", kNothingToRepeat); |
| 428 ExpectError("+", kNothingToRepeat); | 431 ExpectError("+", kNothingToRepeat); |
| 429 ExpectError("{1}", kNothingToRepeat); | 432 ExpectError("{1}", kNothingToRepeat); |
| 430 ExpectError("{1,2}", kNothingToRepeat); | 433 ExpectError("{1,2}", kNothingToRepeat); |
| 431 ExpectError("{1,}", kNothingToRepeat); | 434 ExpectError("{1,}", kNothingToRepeat); |
| 432 | 435 |
| 433 // Check that we don't allow more than kMaxCapture captures | 436 // Check that we don't allow more than kMaxCapture captures |
| 434 const int kMaxCaptures = 1 << 16; // Must match RegExpParser::kMaxCaptures. | 437 const int kMaxCaptures = 1 << 16; // Must match RegExpParser::kMaxCaptures. |
| 435 const char* kTooManyCaptures = "Too many captures"; | 438 const char* kTooManyCaptures = "Too many captures"; |
| 436 HeapStringAllocator allocator; | 439 OStringStream os; |
| 437 StringStream accumulator(&allocator); | |
| 438 for (int i = 0; i <= kMaxCaptures; i++) { | 440 for (int i = 0; i <= kMaxCaptures; i++) { |
| 439 accumulator.Add("()"); | 441 os << "()"; |
| 440 } | 442 } |
| 441 SmartArrayPointer<const char> many_captures(accumulator.ToCString()); | 443 ExpectError(os.c_str(), kTooManyCaptures); |
| 442 ExpectError(many_captures.get(), kTooManyCaptures); | |
| 443 } | 444 } |
| 444 | 445 |
| 445 | 446 |
| 446 static bool IsDigit(uc16 c) { | 447 static bool IsDigit(uc16 c) { |
| 447 return ('0' <= c && c <= '9'); | 448 return ('0' <= c && c <= '9'); |
| 448 } | 449 } |
| 449 | 450 |
| 450 | 451 |
| 451 static bool NotDigit(uc16 c) { | 452 static bool NotDigit(uc16 c) { |
| 452 return !IsDigit(c); | 453 return !IsDigit(c); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 | 661 |
| 661 // Test of debug-only syntax. | 662 // Test of debug-only syntax. |
| 662 #ifdef DEBUG | 663 #ifdef DEBUG |
| 663 | 664 |
| 664 TEST(ParsePossessiveRepetition) { | 665 TEST(ParsePossessiveRepetition) { |
| 665 bool old_flag_value = FLAG_regexp_possessive_quantifier; | 666 bool old_flag_value = FLAG_regexp_possessive_quantifier; |
| 666 | 667 |
| 667 // Enable possessive quantifier syntax. | 668 // Enable possessive quantifier syntax. |
| 668 FLAG_regexp_possessive_quantifier = true; | 669 FLAG_regexp_possessive_quantifier = true; |
| 669 | 670 |
| 670 CHECK_PARSE_EQ("a*+", "(# 0 - p 'a')"); | 671 CheckParseEq("a*+", "(# 0 - p 'a')"); |
| 671 CHECK_PARSE_EQ("a++", "(# 1 - p 'a')"); | 672 CheckParseEq("a++", "(# 1 - p 'a')"); |
| 672 CHECK_PARSE_EQ("a?+", "(# 0 1 p 'a')"); | 673 CheckParseEq("a?+", "(# 0 1 p 'a')"); |
| 673 CHECK_PARSE_EQ("a{10,20}+", "(# 10 20 p 'a')"); | 674 CheckParseEq("a{10,20}+", "(# 10 20 p 'a')"); |
| 674 CHECK_PARSE_EQ("za{10,20}+b", "(: 'z' (# 10 20 p 'a') 'b')"); | 675 CheckParseEq("za{10,20}+b", "(: 'z' (# 10 20 p 'a') 'b')"); |
| 675 | 676 |
| 676 // Disable possessive quantifier syntax. | 677 // Disable possessive quantifier syntax. |
| 677 FLAG_regexp_possessive_quantifier = false; | 678 FLAG_regexp_possessive_quantifier = false; |
| 678 | 679 |
| 679 CHECK_PARSE_ERROR("a*+"); | 680 CHECK_PARSE_ERROR("a*+"); |
| 680 CHECK_PARSE_ERROR("a++"); | 681 CHECK_PARSE_ERROR("a++"); |
| 681 CHECK_PARSE_ERROR("a?+"); | 682 CHECK_PARSE_ERROR("a?+"); |
| 682 CHECK_PARSE_ERROR("a{10,20}+"); | 683 CHECK_PARSE_ERROR("a{10,20}+"); |
| 683 CHECK_PARSE_ERROR("a{10,20}+b"); | 684 CHECK_PARSE_ERROR("a{10,20}+b"); |
| 684 | 685 |
| (...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 ZoneList<CharacterRange> first_only(4, &zone); | 1811 ZoneList<CharacterRange> first_only(4, &zone); |
| 1811 ZoneList<CharacterRange> second_only(4, &zone); | 1812 ZoneList<CharacterRange> second_only(4, &zone); |
| 1812 ZoneList<CharacterRange> both(4, &zone); | 1813 ZoneList<CharacterRange> both(4, &zone); |
| 1813 } | 1814 } |
| 1814 | 1815 |
| 1815 | 1816 |
| 1816 TEST(Graph) { | 1817 TEST(Graph) { |
| 1817 V8::Initialize(NULL); | 1818 V8::Initialize(NULL); |
| 1818 Execute("\\b\\w+\\b", false, true, true); | 1819 Execute("\\b\\w+\\b", false, true, true); |
| 1819 } | 1820 } |
| OLD | NEW |