Pushes a repetition regexp onto the stack. A valid argument for the operator must already be on the stack.
| 566 | // Pushes a repetition regexp onto the stack. |
| 567 | // A valid argument for the operator must already be on the stack. |
| 568 | bool Regexp::ParseState::PushRepetition(int min, int max, |
| 569 | const StringPiece& s, |
| 570 | bool nongreedy) { |
| 571 | if ((max != -1 && max < min) || min > kMaxRepeat || max > kMaxRepeat) { |
| 572 | status_->set_code(kRegexpRepeatSize); |
| 573 | status_->set_error_arg(s); |
| 574 | return false; |
| 575 | } |
| 576 | if (stacktop_ == NULL || IsMarker(stacktop_->op())) { |
| 577 | status_->set_code(kRegexpRepeatArgument); |
| 578 | status_->set_error_arg(s); |
| 579 | return false; |
| 580 | } |
| 581 | Regexp::ParseFlags fl = flags_; |
| 582 | if (nongreedy) |
| 583 | fl = fl ^ NonGreedy; |
| 584 | Regexp* re = new Regexp(kRegexpRepeat, fl); |
| 585 | re->min_ = min; |
| 586 | re->max_ = max; |
| 587 | re->AllocSub(1); |
| 588 | re->down_ = stacktop_->down_; |
| 589 | re->sub()[0] = FinishRegexp(stacktop_); |
| 590 | re->simple_ = re->ComputeSimple(); |
| 591 | stacktop_ = re; |
| 592 | if (min >= 2 || max >= 2) { |
| 593 | RepetitionWalker w; |
| 594 | if (w.Walk(stacktop_, kMaxRepeat) == 0) { |
| 595 | status_->set_code(kRegexpRepeatSize); |
| 596 | status_->set_error_arg(s); |
| 597 | return false; |
| 598 | } |
| 599 | } |
| 600 | return true; |
| 601 | } |
| 602 | |
| 603 | // Checks whether a particular regexp op is a marker. |
| 604 | bool Regexp::ParseState::IsMarker(RegexpOp op) { |
no test coverage detected