Index: src/ast.h |
diff --git a/src/ast.h b/src/ast.h |
index 14f71a6cc28bfb03e95f2f767c97cce90727542d..3d02debcd3d127fc2948216dd2460c9f7d314f63 100644 |
--- a/src/ast.h |
+++ b/src/ast.h |
@@ -119,7 +119,7 @@ class RegExpCharacterClass; |
class RegExpCompiler; |
class RegExpDisjunction; |
class RegExpEmpty; |
-class RegExpLookahead; |
+class RegExpLookaround; |
class RegExpQuantifier; |
class RegExpText; |
@@ -3075,8 +3075,7 @@ class RegExpQuantifier final : public RegExpTree { |
class RegExpCapture final : public RegExpTree { |
public: |
- explicit RegExpCapture(RegExpTree* body, int index) |
- : body_(body), index_(index) { } |
+ explicit RegExpCapture(int index) : body_(NULL), index_(index) {} |
void* Accept(RegExpVisitor* visitor, void* data) override; |
RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; |
static RegExpNode* ToNode(RegExpTree* body, |
@@ -3091,6 +3090,7 @@ class RegExpCapture final : public RegExpTree { |
int min_match() override { return body_->min_match(); } |
int max_match() override { return body_->max_match(); } |
RegExpTree* body() { return body_; } |
+ void set_body(RegExpTree* body) { body_ = body; } |
int index() { return index_; } |
static int StartRegister(int index) { return index * 2; } |
static int EndRegister(int index) { return index * 2 + 1; } |
@@ -3101,22 +3101,23 @@ class RegExpCapture final : public RegExpTree { |
}; |
-class RegExpLookahead final : public RegExpTree { |
+class RegExpLookaround final : public RegExpTree { |
public: |
- RegExpLookahead(RegExpTree* body, |
- bool is_positive, |
- int capture_count, |
- int capture_from) |
+ enum Type { LOOKAHEAD, LOOKBEHIND }; |
+ |
+ RegExpLookaround(RegExpTree* body, bool is_positive, int capture_count, |
+ int capture_from, Type type) |
: body_(body), |
is_positive_(is_positive), |
capture_count_(capture_count), |
- capture_from_(capture_from) { } |
+ capture_from_(capture_from), |
+ type_(type) {} |
void* Accept(RegExpVisitor* visitor, void* data) override; |
RegExpNode* ToNode(RegExpCompiler* compiler, RegExpNode* on_success) override; |
- RegExpLookahead* AsLookahead() override; |
+ RegExpLookaround* AsLookaround() override; |
Interval CaptureRegisters() override; |
- bool IsLookahead() override; |
+ bool IsLookaround() override; |
bool IsAnchoredAtStart() override; |
int min_match() override { return 0; } |
int max_match() override { return 0; } |
@@ -3124,12 +3125,14 @@ class RegExpLookahead final : public RegExpTree { |
bool is_positive() { return is_positive_; } |
int capture_count() { return capture_count_; } |
int capture_from() { return capture_from_; } |
+ Type type() { return type_; } |
private: |
RegExpTree* body_; |
bool is_positive_; |
int capture_count_; |
int capture_from_; |
+ Type type_; |
}; |
@@ -3142,7 +3145,14 @@ class RegExpBackReference final : public RegExpTree { |
RegExpBackReference* AsBackReference() override; |
bool IsBackReference() override; |
int min_match() override { return 0; } |
- int max_match() override { return capture_->max_match(); } |
+ // The capture may not be completely parsed yet, if the reference occurs |
+ // before the capture. In the ordinary case, nothing has been captured yet, |
+ // so the back reference must have the length 0. If the back reference is |
+ // inside a lookbehind, effectively making it a forward reference, we return |
+ // 0 since lookbehinds have a length of 0. |
+ int max_match() override { |
+ return capture_->body() ? capture_->max_match() : 0; |
+ } |
int index() { return capture_->index(); } |
RegExpCapture* capture() { return capture_; } |
private: |