- Added some expansion of assertions.

- Splitting of character classes into word and non-word parts.
- A bunch of refactorings.
- Made dispatch table construction lazy.


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@880 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5c39d9c7
......@@ -59,6 +59,25 @@ inline bool IsHexDigit(uc32 c) {
}
inline bool IsRegExpWord(uc16 c) {
return ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9')
|| (c == '_');
}
inline bool IsRegExpNewline(uc16 c) {
switch (c) {
// CR LF LS PS
case 0x000A: case 0x000D: case 0x2028: case 0x2029:
return false;
default:
return true;
}
}
} } // namespace v8::internal
#endif // V8_CHAR_PREDICATES_INL_H_
......@@ -37,6 +37,8 @@ inline bool IsCarriageReturn(uc32 c);
inline bool IsLineFeed(uc32 c);
inline bool IsDecimalDigit(uc32 c);
inline bool IsHexDigit(uc32 c);
inline bool IsRegExpWord(uc32 c);
inline bool IsRegExpNewline(uc32 c);
struct IdentifierStart {
static inline bool Is(uc32 c) {
......
This diff is collapsed.
This diff is collapsed.
......@@ -1028,7 +1028,7 @@ class LexicalScope BASE_EMBEDDED {
#define DUMMY ) // to make indentation work
#undef DUMMY
#define CHECK_FAILED ); \
#define CHECK_FAILED /**/); \
if (failed_) return NULL; \
((void)0
#define DUMMY ) // to make indentation work
......
......@@ -324,27 +324,8 @@ static bool NotWhiteSpace(uc16 c) {
}
static bool IsWord(uc16 c) {
return ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9')
|| (c == '_');
}
static bool NotWord(uc16 c) {
return !IsWord(c);
}
static bool Dot(uc16 c) {
switch (c) {
// CR LF LS PS
case 0x000A: case 0x000D: case 0x2028: case 0x2029:
return false;
default:
return true;
}
return !IsRegExpWord(c);
}
......@@ -364,12 +345,12 @@ static void TestCharacterClassEscapes(uc16 c, bool (pred)(uc16 c)) {
TEST(CharacterClassEscapes) {
TestCharacterClassEscapes('.', Dot);
TestCharacterClassEscapes('.', IsRegExpNewline);
TestCharacterClassEscapes('d', IsDigit);
TestCharacterClassEscapes('D', NotDigit);
TestCharacterClassEscapes('s', IsWhiteSpace);
TestCharacterClassEscapes('S', NotWhiteSpace);
TestCharacterClassEscapes('w', IsWord);
TestCharacterClassEscapes('w', IsRegExpWord);
TestCharacterClassEscapes('W', NotWord);
}
......@@ -395,7 +376,7 @@ static void Execute(const char* input,
USE(node);
#ifdef DEBUG
if (dot_output) {
RegExpEngine::DotPrint(input, node);
RegExpEngine::DotPrint(input, node, false);
exit(0);
}
#endif // DEBUG
......@@ -964,7 +945,7 @@ TEST(AddInverseToTable) {
ranges->Add(CharacterRange(from, to));
}
DispatchTable table;
DispatchTableConstructor cons(&table);
DispatchTableConstructor cons(&table, false);
cons.set_choice_index(0);
cons.AddInverse(ranges);
for (int i = 0; i < kLimit; i++) {
......@@ -980,7 +961,7 @@ TEST(AddInverseToTable) {
new ZoneList<CharacterRange>(1);
ranges->Add(CharacterRange(0xFFF0, 0xFFFE));
DispatchTable table;
DispatchTableConstructor cons(&table);
DispatchTableConstructor cons(&table, false);
cons.set_choice_index(0);
cons.AddInverse(ranges);
CHECK(!table.Get(0xFFFE)->Get(0));
......@@ -1162,7 +1143,45 @@ TEST(CharacterRangeCaseIndependence) {
}
static bool InClass(uc16 c, ZoneList<CharacterRange>* ranges) {
if (ranges == NULL)
return false;
for (int i = 0; i < ranges->length(); i++) {
CharacterRange range = ranges->at(i);
if (range.from() <= c && c <= range.to())
return true;
}
return false;
}
TEST(CharClassDifference) {
ZoneScope zone_scope(DELETE_ON_EXIT);
ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1);
base->Add(CharacterRange::Everything());
Vector<const uc16> overlay = CharacterRange::GetWordBounds();
ZoneList<CharacterRange>* included = NULL;
ZoneList<CharacterRange>* excluded = NULL;
CharacterRange::Split(base, overlay, &included, &excluded);
for (int i = 0; i < (1 << 16); i++) {
bool in_base = InClass(i, base);
if (in_base) {
bool in_overlay = false;
for (int j = 0; !in_overlay && j < overlay.length(); j += 2) {
if (overlay[j] <= i && i <= overlay[j+1])
in_overlay = true;
}
CHECK_EQ(in_overlay, InClass(i, included));
CHECK_EQ(!in_overlay, InClass(i, excluded));
} else {
CHECK(!InClass(i, included));
CHECK(!InClass(i, excluded));
}
}
}
TEST(Graph) {
V8::Initialize(NULL);
Execute("foo$(?!bar)", false, true);
Execute("\\b\\w", false, true);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment