Skip to content
Permalink
Browse files
JavaScriptCore:
2008-12-09  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Oliver Hunt.

        Added WREC support for an assertion followed by a quantifier. Fixed
        PCRE to match.

        * wrec/WRECParser.cpp:
        (JSC::WREC::Parser::parseParentheses): Throw away the quantifier, since
        it's meaningless. (Firefox does the same.)

        * pcre/pcre_compile.cpp:
        (compileBranch): ditto.

LayoutTests:

2008-12-09  Geoffrey Garen  <ggaren@apple.com>

        Reviewed by Oliver Hunt.

        Added a test for an assertion followed by a quantifier.

        * fast/regex/quantified-assertions-expected.txt: Added.
        * fast/regex/quantified-assertions.html: Added.
        * fast/regex/resources/quantified-assertions.js: Copied from fast/regex/resources/alternative-length-miscalculation.js.



Canonical link: https://commits.webkit.org/31368@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@39164 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
geoffreygaren committed Dec 10, 2008
1 parent dda3d83 commit 5b1dff1cb3c09901e781d26eedc5dfb49164ac69
@@ -1,3 +1,17 @@
2008-12-09 Geoffrey Garen <ggaren@apple.com>

Reviewed by Oliver Hunt.

Added WREC support for an assertion followed by a quantifier. Fixed
PCRE to match.

* wrec/WRECParser.cpp:
(JSC::WREC::Parser::parseParentheses): Throw away the quantifier, since
it's meaningless. (Firefox does the same.)

* pcre/pcre_compile.cpp:
(compileBranch): ditto.

2008-12-09 Geoffrey Garen <ggaren@apple.com>

Reviewed by Cameron Zwarich.
@@ -1058,6 +1058,11 @@ compileBranch(int options, int* brackets, unsigned char** codePtr,

reqvary = (repeatMin == repeat_max) ? 0 : REQ_VARY;

// A quantifier after an assertion is meaningless, since assertions
// don't move index forward. So, we discard it.
if (*previous == OP_ASSERT || *previous == OP_ASSERT_NOT)
goto END_REPEAT;

opType = 0; /* Default single-char op codes */

/* Save start of previous item, in case we have to move it up to make space
@@ -1477,12 +1482,12 @@ compileBranch(int options, int* brackets, unsigned char** codePtr,
bravalue = OP_BRA + *brackets;
}

/* Process nested bracketed re. Assertions may not be repeated, but other
kinds can be. We copy code into a non-variable in order to be able
to pass its address because some compilers complain otherwise. Pass in a
new setting for the ims options if they have changed. */
/* Process nested bracketed re. We copy code into a non-variable
in order to be able to pass its address because some compilers
complain otherwise. Pass in a new setting for the ims options
if they have changed. */

previous = (bravalue >= OP_BRAZERO) ? code : 0;
previous = code;
*code = bravalue;
tempcode = code;
tempreqvary = cd.reqVaryOpt; /* Save value before bracket */
@@ -235,42 +235,36 @@ bool Parser::parseParentheses(JumpList& failures)
switch (type) {
case Generator::Assertion:
m_generator.generateParenthesesAssertion(failures);

if (consume() != ')') {
setError(ParenthesesUnmatched);
return false;
}

// A quantifier after an assertion is meaningless, since assertions
// don't move index forward. So, we discard it.
consumeQuantifier();
break;

case Generator::InvertedAssertion:
m_generator.generateParenthesesInvertedAssertion(failures);

if (consume() != ')') {
setError(ParenthesesUnmatched);
return false;
}

// A quantifier after an assertion is meaningless, since assertions
// don't move index forward. So, we discard it.
consumeQuantifier();
break;

default:
setError(ParenthesesNotSupported);
return false;
}

if (consume() != ')') {
setError(ParenthesesUnmatched);
return false;
}

Quantifier q = consumeQuantifier();

switch (q.type) {
case Quantifier::None:
return true;

case Quantifier::Greedy:
setError(ParenthesesNotSupported);
return false;

case Quantifier::NonGreedy:
setError(ParenthesesNotSupported);
return false;

case Quantifier::Error:
return false;
}

ASSERT_NOT_REACHED();
return false;
return true;
}

bool Parser::parseCharacterClass(JumpList& failures)
@@ -1,3 +1,13 @@
2008-12-09 Geoffrey Garen <ggaren@apple.com>

Reviewed by Oliver Hunt.

Added a test for an assertion followed by a quantifier.

* fast/regex/quantified-assertions-expected.txt: Added.
* fast/regex/quantified-assertions.html: Added.
* fast/regex/resources/quantified-assertions.js: Copied from fast/regex/resources/alternative-length-miscalculation.js.

2008-12-09 Geoffrey Garen <ggaren@apple.com>

Reviewed by Cameron Zwarich.
@@ -0,0 +1,25 @@
This page tests assertions followed by quantifiers.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".



Testing regexp: /(?=a){0}/gm
PASS regexp.test('a') is true
PASS regexp.lastIndex is 0

Testing regexp: /(?=a){1}/gm
PASS regexp.test('a') is true
PASS regexp.lastIndex is 0

Testing regexp: /(?!a){0}/gm
PASS regexp.test('b') is true
PASS regexp.lastIndex is 0

Testing regexp: /(?!a){1}/gm
PASS regexp.test('b') is true
PASS regexp.lastIndex is 0
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,13 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="resources/quantified-assertions.js"></script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
@@ -0,0 +1,27 @@
description(
"This page tests assertions followed by quantifiers."
);

var regexp;

regexp = /(?=a){0}/gm;
debug("\nTesting regexp: " + regexp);
shouldBeTrue("regexp.test('a')");
shouldBe("regexp.lastIndex", "0");

regexp = /(?=a){1}/gm;
debug("\nTesting regexp: " + regexp);
shouldBeTrue("regexp.test('a')");
shouldBe("regexp.lastIndex", "0");

regexp = /(?!a){0}/gm;
debug("\nTesting regexp: " + regexp);
shouldBeTrue("regexp.test('b')");
shouldBe("regexp.lastIndex", "0");

regexp = /(?!a){1}/gm;
debug("\nTesting regexp: " + regexp);
shouldBeTrue("regexp.test('b')");
shouldBe("regexp.lastIndex", "0");

var successfullyParsed = true;

0 comments on commit 5b1dff1

Please sign in to comment.