diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-11-11 23:37:35 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-11-11 23:37:35 +0100 |
commit | fa473930f424bf17a9e545b601c84dd2e61364e3 (patch) | |
tree | 41a29cb3ad0ebaf93f6b6248e92073fe4d8788ff /js/src/irregexp/RegExpParser.h | |
parent | b00601953bade944cd6df9cde6fcdd1f10d76feb (diff) | |
download | UXP-fa473930f424bf17a9e545b601c84dd2e61364e3.tar UXP-fa473930f424bf17a9e545b601c84dd2e61364e3.tar.gz UXP-fa473930f424bf17a9e545b601c84dd2e61364e3.tar.lz UXP-fa473930f424bf17a9e545b601c84dd2e61364e3.tar.xz UXP-fa473930f424bf17a9e545b601c84dd2e61364e3.zip |
Issue #1279 - Implement regular expression lookbehind
Based on Tom Schuster's work, with extra minters for unicode.
Diffstat (limited to 'js/src/irregexp/RegExpParser.h')
-rw-r--r-- | js/src/irregexp/RegExpParser.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/js/src/irregexp/RegExpParser.h b/js/src/irregexp/RegExpParser.h index 0a7e61858..2f02625b5 100644 --- a/js/src/irregexp/RegExpParser.h +++ b/js/src/irregexp/RegExpParser.h @@ -229,7 +229,7 @@ class RegExpParser bool simple() { return simple_; } bool contains_anchor() { return contains_anchor_; } void set_contains_anchor() { contains_anchor_ = true; } - int captures_started() { return captures_ == nullptr ? 0 : captures_->length(); } + int captures_started() { return captures_started_; } const CharT* position() { return next_pos_ - 1; } static const int kMaxCaptures = 1 << 16; @@ -239,8 +239,8 @@ class RegExpParser enum SubexpressionType { INITIAL, CAPTURE, // All positive values represent captures. - POSITIVE_LOOKAHEAD, - NEGATIVE_LOOKAHEAD, + POSITIVE_LOOKAROUND, + NEGATIVE_LOOKAROUND, GROUPING }; @@ -249,10 +249,12 @@ class RegExpParser RegExpParserState(LifoAlloc* alloc, RegExpParserState* previous_state, SubexpressionType group_type, + RegExpLookaround::Type lookaround_type, int disjunction_capture_index) : previous_state_(previous_state), builder_(alloc->newInfallible<RegExpBuilder>(alloc)), group_type_(group_type), + lookaround_type_(lookaround_type), disjunction_capture_index_(disjunction_capture_index) {} // Parser state of containing expression, if any. @@ -262,11 +264,16 @@ class RegExpParser RegExpBuilder* builder() { return builder_; } // Type of regexp being parsed (parenthesized group or entire regexp). SubexpressionType group_type() { return group_type_; } + // Lookahead or Lookbehind. + RegExpLookaround::Type lookaround_type() { return lookaround_type_; } // Index in captures array of first capture in this sub-expression, if any. // Also the capture index of this sub-expression itself, if group_type // is CAPTURE. int capture_index() { return disjunction_capture_index_; } + // Check whether the parser is inside a capture group with the given index. + bool IsInsideCaptureGroup(int index); + private: // Linked list implementation of stack of states. RegExpParserState* previous_state_; @@ -274,10 +281,15 @@ class RegExpParser RegExpBuilder* builder_; // Stored disjunction type (capture, look-ahead or grouping), if any. SubexpressionType group_type_; + // Stored read direction. + RegExpLookaround::Type lookaround_type_; // Stored disjunction's capture index (if any). int disjunction_capture_index_; }; + // Return the 1-indexed RegExpCapture object, allocate if necessary. + RegExpCapture* GetCapture(int index); + widechar current() { return current_; } bool has_more() { return has_more_; } bool has_next() { return next_pos_ < end_; } @@ -294,6 +306,7 @@ class RegExpParser const CharT* next_pos_; const CharT* end_; widechar current_; + int captures_started_; // The capture count is only valid after we have scanned for captures. int capture_count_; bool has_more_; |