Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb_re2::Regexp::ParseState Class Reference
Collaboration diagram for duckdb_re2::Regexp::ParseState:

Public Member Functions

 ParseState (ParseFlags flags, const StringPiece &whole_regexp, RegexpStatus *status)
ParseFlags flags ()
int rune_max ()
bool PushRegexp (Regexp *re)
bool PushLiteral (Rune r)
bool PushSimpleOp (RegexpOp op)
bool PushCaret ()
bool PushWordBoundary (bool word)
bool PushDollar ()
bool PushDot ()
bool PushRepeatOp (RegexpOp op, const StringPiece &s, bool nongreedy)
bool PushRepetition (int min, int max, const StringPiece &s, bool nongreedy)
bool IsMarker (RegexpOp op)
bool DoLeftParen (const StringPiece &name)
bool DoLeftParenNoCapture ()
bool DoVerticalBar ()
bool DoRightParen ()
Regexp * DoFinish ()
Regexp * FinishRegexp (Regexp *)
bool ParseCharClass (StringPiece *s, Regexp **out_re, RegexpStatus *status)
bool ParseCCCharacter (StringPiece *s, Rune *rp, const StringPiece &whole_class, RegexpStatus *status)
bool ParseCCRange (StringPiece *s, RuneRange *rr, const StringPiece &whole_class, RegexpStatus *status)
bool ParsePerlFlags (StringPiece *s)
void DoConcatenation ()
void DoAlternation ()
void DoCollapse (RegexpOp op)
bool MaybeConcatString (int r, ParseFlags flags)

Private Member Functions

 ParseState (const ParseState &)=delete
ParseState & operator= (const ParseState &)=delete

Private Attributes

ParseFlags flags_
StringPiece whole_regexp_
RegexpStatus * status_
Regexp * stacktop_
int ncap_
int rune_max_

Constructor & Destructor Documentation

◆ ParseState()

duckdb_re2::Regexp::ParseState::ParseState ( ParseFlags flags,
const StringPiece & whole_regexp,
RegexpStatus * status )
466864 : flags_(flags), whole_regexp_(whole_regexp),
466865 status_(status), stacktop_(NULL), ncap_(0) {
466866 if (flags_ & Latin1)
466867 rune_max_ = 0xFF;
466868 else
466869 rune_max_ = Runemax;
466870}

◆ ~ParseState()

duckdb_re2::Regexp::ParseState::~ParseState ( )
466873 {
466874 Regexp* next;
466875 for (Regexp* re = stacktop_; re != NULL; re = next) {
466876 next = re->down_;
466877 re->down_ = NULL;
466878 if (re->op() == kLeftParen)
466879 delete re->arguments.capture.name_;
466880 re->Decref();
466881 }
466882}

Member Function Documentation

◆ flags()

ParseFlags duckdb_re2::Regexp::ParseState::flags ( )
inline
466744{ return flags_; }

◆ rune_max()

int duckdb_re2::Regexp::ParseState::rune_max ( )
inline
466745{ return rune_max_; }

◆ PushRegexp()

bool duckdb_re2::Regexp::ParseState::PushRegexp ( Regexp * re)
466904 {
466905 MaybeConcatString(-1, NoParseFlags);
466906
466907 // Special case: a character class of one character is just
466908 // a literal. This is a common idiom for escaping
466909 // single characters (e.g., [.] instead of \.), and some
466910 // analysis does better with fewer character classes.
466911 // Similarly, [Aa] can be rewritten as a literal A with ASCII case folding.
466912 if (re->op_ == kRegexpCharClass && re->arguments.char_class.ccb_ != NULL) {
466913 re->arguments.char_class.ccb_->RemoveAbove(rune_max_);
466914 if (re->arguments.char_class.ccb_->size() == 1) {
466915 Rune r = re->arguments.char_class.ccb_->begin()->lo;
466916 re->Decref();
466917 re = new Regexp(kRegexpLiteral, flags_);
466918 re->arguments.rune_ = r;
466919 } else if (re->arguments.char_class.ccb_->size() == 2) {
466920 Rune r = re->arguments.char_class.ccb_->begin()->lo;
466921 if ('A' <= r && r <= 'Z' && re->arguments.char_class.ccb_->Contains(r + 'a' - 'A')) {
466922 re->Decref();
466923 re = new Regexp(kRegexpLiteral, flags_ | FoldCase);
466924 re->arguments.rune_ = r + 'a' - 'A';
466925 }
466926 }
466927 }
466928
466929 if (!IsMarker(re->op()))
466930 re->simple_ = re->ComputeSimple();
466931 re->down_ = stacktop_;
466932 stacktop_ = re;
466933 return true;
466934}

◆ PushLiteral()

bool duckdb_re2::Regexp::ParseState::PushLiteral ( Rune r)
467064 {
467065 // Do case folding if needed.
467066 if ((flags_ & FoldCase) && CycleFoldRune(r) != r) {
467067 Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase);
467068 re->arguments.char_class.ccb_ = new CharClassBuilder;
467069 Rune r1 = r;
467070 do {
467071 if (!(flags_ & NeverNL) || r != '\n') {
467072 re->arguments.char_class.ccb_->AddRange(r, r);
467073 }
467074 r = CycleFoldRune(r);
467075 } while (r != r1);
467076 return PushRegexp(re);
467077 }
467078
467079 // Exclude newline if applicable.
467080 if ((flags_ & NeverNL) && r == '\n')
467081 return PushRegexp(new Regexp(kRegexpNoMatch, flags_));
467082
467083 // No fancy stuff worked. Ordinary literal.
467084 if (MaybeConcatString(r, flags_))
467085 return true;
467086
467087 Regexp* re = new Regexp(kRegexpLiteral, flags_);
467088 re->arguments.rune_ = r;
467089 return PushRegexp(re);
467090}

◆ PushSimpleOp()

bool duckdb_re2::Regexp::ParseState::PushSimpleOp ( RegexpOp op)
467134 {
467135 Regexp* re = new Regexp(op, flags_);
467136 return PushRegexp(re);
467137}

◆ PushCaret()

bool duckdb_re2::Regexp::ParseState::PushCaret ( )
467093 {
467094 if (flags_ & OneLine) {
467095 return PushSimpleOp(kRegexpBeginText);
467096 }
467097 return PushSimpleOp(kRegexpBeginLine);
467098}

◆ PushWordBoundary()

bool duckdb_re2::Regexp::ParseState::PushWordBoundary ( bool word)
467101 {
467102 if (word)
467103 return PushSimpleOp(kRegexpWordBoundary);
467104 return PushSimpleOp(kRegexpNoWordBoundary);
467105}

◆ PushDollar()

bool duckdb_re2::Regexp::ParseState::PushDollar ( )
467108 {
467109 if (flags_ & OneLine) {
467110 // Clumsy marker so that MimicsPCRE() can tell whether
467111 // this kRegexpEndText was a $ and not a \z.
467112 Regexp::ParseFlags oflags = flags_;
467113 flags_ = flags_ | WasDollar;
467114 bool ret = PushSimpleOp(kRegexpEndText);
467115 flags_ = oflags;
467116 return ret;
467117 }
467118 return PushSimpleOp(kRegexpEndLine);
467119}

◆ PushDot()

bool duckdb_re2::Regexp::ParseState::PushDot ( )
467122 {
467123 if ((flags_ & DotNL) && !(flags_ & NeverNL))
467124 return PushSimpleOp(kRegexpAnyChar);
467125 // Rewrite . into [^\n]
467126 Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase);
467127 re->arguments.char_class.ccb_ = new CharClassBuilder;
467128 re->arguments.char_class.ccb_->AddRange(0, '\n' - 1);
467129 re->arguments.char_class.ccb_->AddRange('\n' + 1, rune_max_);
467130 return PushRegexp(re);
467131}

◆ PushRepeatOp()

bool duckdb_re2::Regexp::ParseState::PushRepeatOp ( RegexpOp op,
const StringPiece & s,
bool nongreedy )
467143 {
467144 if (stacktop_ == NULL || IsMarker(stacktop_->op())) {
467145 status_->set_code(kRegexpRepeatArgument);
467146 status_->set_error_arg(s);
467147 return false;
467148 }
467149 Regexp::ParseFlags fl = flags_;
467150 if (nongreedy)
467151 fl = fl ^ NonGreedy;
467152
467153 // Squash **, ++ and ??. Regexp::Star() et al. handle this too, but
467154 // they're mostly for use during simplification, not during parsing.
467155 if (op == stacktop_->op() && fl == stacktop_->parse_flags())
467156 return true;
467157
467158 // Squash *+, *?, +*, +?, ?* and ?+. They all squash to *, so because
467159 // op is a repeat, we just have to check that stacktop_->op() is too,
467160 // then adjust stacktop_.
467161 if ((stacktop_->op() == kRegexpStar ||
467162 stacktop_->op() == kRegexpPlus ||
467163 stacktop_->op() == kRegexpQuest) &&
467164 fl == stacktop_->parse_flags()) {
467165 stacktop_->op_ = kRegexpStar;
467166 return true;
467167 }
467168
467169 Regexp* re = new Regexp(op, fl);
467170 re->AllocSub(1);
467171 re->down_ = stacktop_->down_;
467172 re->sub()[0] = FinishRegexp(stacktop_);
467173 re->simple_ = re->ComputeSimple();
467174 stacktop_ = re;
467175 return true;
467176}

◆ PushRepetition()

bool duckdb_re2::Regexp::ParseState::PushRepetition ( int min,
int max,
const StringPiece & s,
bool nongreedy )
467237 {
467238 if ((max != -1 && max < min) ||
467239 min > maximum_repeat_count ||
467240 max > maximum_repeat_count) {
467241 status_->set_code(kRegexpRepeatSize);
467242 status_->set_error_arg(s);
467243 return false;
467244 }
467245 if (stacktop_ == NULL || IsMarker(stacktop_->op())) {
467246 status_->set_code(kRegexpRepeatArgument);
467247 status_->set_error_arg(s);
467248 return false;
467249 }
467250 Regexp::ParseFlags fl = flags_;
467251 if (nongreedy)
467252 fl = fl ^ NonGreedy;
467253 Regexp* re = new Regexp(kRegexpRepeat, fl);
467254 re->arguments.repeat.min_ = min;
467255 re->arguments.repeat.max_ = max;
467256 re->AllocSub(1);
467257 re->down_ = stacktop_->down_;
467258 re->sub()[0] = FinishRegexp(stacktop_);
467259 re->simple_ = re->ComputeSimple();
467260 stacktop_ = re;
467261 if (min >= 2 || max >= 2) {
467262 RepetitionWalker w;
467263 if (w.Walk(stacktop_, maximum_repeat_count) == 0) {
467264 status_->set_code(kRegexpRepeatSize);
467265 status_->set_error_arg(s);
467266 return false;
467267 }
467268 }
467269 return true;
467270}
static softfloat min()
static softfloat max()

◆ IsMarker()

bool duckdb_re2::Regexp::ParseState::IsMarker ( RegexpOp op)
467273 {
467274 return op >= kLeftParen;
467275}

◆ DoLeftParen()

bool duckdb_re2::Regexp::ParseState::DoLeftParen ( const StringPiece & name)
467279 {
467280 Regexp* re = new Regexp(kLeftParen, flags_);
467281 re->arguments.capture.cap_ = ++ncap_;
467282 if (name.data() != NULL)
467283 re->arguments.capture.name_ = new std::string(name);
467284 return PushRegexp(re);
467285}

◆ DoLeftParenNoCapture()

bool duckdb_re2::Regexp::ParseState::DoLeftParenNoCapture ( )
467288 {
467289 Regexp* re = new Regexp(kLeftParen, flags_);
467290 re->arguments.capture.cap_ = -1;
467291 return PushRegexp(re);
467292}

◆ DoVerticalBar()

bool duckdb_re2::Regexp::ParseState::DoVerticalBar ( )
467295 {
467296 MaybeConcatString(-1, NoParseFlags);
467297 DoConcatenation();
467298
467299 // Below the vertical bar is a list to alternate.
467300 // Above the vertical bar is a list to concatenate.
467301 // We just did the concatenation, so either swap
467302 // the result below the vertical bar or push a new
467303 // vertical bar on the stack.
467304 Regexp* r1;
467305 Regexp* r2;
467306 if ((r1 = stacktop_) != NULL &&
467307 (r2 = r1->down_) != NULL &&
467308 r2->op() == kVerticalBar) {
467309 Regexp* r3;
467310 if ((r3 = r2->down_) != NULL &&
467311 (r1->op() == kRegexpAnyChar || r3->op() == kRegexpAnyChar)) {
467312 // AnyChar is above or below the vertical bar. Let it subsume
467313 // the other when the other is Literal, CharClass or AnyChar.
467314 if (r3->op() == kRegexpAnyChar &&
467315 (r1->op() == kRegexpLiteral ||
467316 r1->op() == kRegexpCharClass ||
467317 r1->op() == kRegexpAnyChar)) {
467318 // Discard r1.
467319 stacktop_ = r2;
467320 r1->Decref();
467321 return true;
467322 }
467323 if (r1->op() == kRegexpAnyChar &&
467324 (r3->op() == kRegexpLiteral ||
467325 r3->op() == kRegexpCharClass ||
467326 r3->op() == kRegexpAnyChar)) {
467327 // Rearrange the stack and discard r3.
467328 r1->down_ = r3->down_;
467329 r2->down_ = r1;
467330 stacktop_ = r2;
467331 r3->Decref();
467332 return true;
467333 }
467334 }
467335 // Swap r1 below vertical bar (r2).
467336 r1->down_ = r2->down_;
467337 r2->down_ = r1;
467338 stacktop_ = r2;
467339 return true;
467340 }
467341 return PushSimpleOp(kVerticalBar);
467342}

◆ DoRightParen()

bool duckdb_re2::Regexp::ParseState::DoRightParen ( )
467345 {
467346 // Finish the current concatenation and alternation.
467347 DoAlternation();
467348
467349 // The stack should be: LeftParen regexp
467350 // Remove the LeftParen, leaving the regexp,
467351 // parenthesized.
467352 Regexp* r1;
467353 Regexp* r2;
467354 if ((r1 = stacktop_) == NULL ||
467355 (r2 = r1->down_) == NULL ||
467356 r2->op() != kLeftParen) {
467357 status_->set_code(kRegexpUnexpectedParen);
467358 status_->set_error_arg(whole_regexp_);
467359 return false;
467360 }
467361
467362 // Pop off r1, r2. Will Decref or reuse below.
467363 stacktop_ = r2->down_;
467364
467365 // Restore flags from when paren opened.
467366 Regexp* re = r2;
467367 flags_ = re->parse_flags();
467368
467369 // Rewrite LeftParen as capture if needed.
467370 if (re->arguments.capture.cap_ > 0) {
467371 re->op_ = kRegexpCapture;
467372 // re->cap_ is already set
467373 re->AllocSub(1);
467374 re->sub()[0] = FinishRegexp(r1);
467375 re->simple_ = re->ComputeSimple();
467376 } else {
467377 re->Decref();
467378 re = r1;
467379 }
467380 return PushRegexp(re);
467381}

◆ DoFinish()

Regexp * duckdb_re2::Regexp::ParseState::DoFinish ( )
467384 {
467385 DoAlternation();
467386 Regexp* re = stacktop_;
467387 if (re != NULL && re->down_ != NULL) {
467388 status_->set_code(kRegexpMissingParen);
467389 status_->set_error_arg(whole_regexp_);
467390 return NULL;
467391 }
467392 stacktop_ = NULL;
467393 return FinishRegexp(re);
467394}

◆ FinishRegexp()

Regexp * duckdb_re2::Regexp::ParseState::FinishRegexp ( Regexp * re)
466887 {
466888 if (re == NULL)
466889 return NULL;
466890 re->down_ = NULL;
466891
466892 if (re->op_ == kRegexpCharClass && re->arguments.char_class.ccb_ != NULL) {
466893 CharClassBuilder* ccb = re->arguments.char_class.ccb_;
466894 re->arguments.char_class.ccb_ = NULL;
466895 re->arguments.char_class.cc_ = ccb->GetCharClass();
466896 delete ccb;
466897 }
466898
466899 return re;
466900}

◆ ParseCharClass()

bool duckdb_re2::Regexp::ParseState::ParseCharClass ( StringPiece * s,
Regexp ** out_re,
RegexpStatus * status )
468578 {
468579 StringPiece whole_class = *s;
468580 if (s->empty() || (*s)[0] != '[') {
468581 // Caller checked this.
468582 status->set_code(kRegexpInternalError);
468583 status->set_error_arg(StringPiece());
468584 return false;
468585 }
468586 bool negated = false;
468587 Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase);
468588 re->arguments.char_class.ccb_ = new CharClassBuilder;
468589 s->remove_prefix(1); // '['
468590 if (!s->empty() && (*s)[0] == '^') {
468591 s->remove_prefix(1); // '^'
468592 negated = true;
468593 if (!(flags_ & ClassNL) || (flags_ & NeverNL)) {
468594 // If NL can't match implicitly, then pretend
468595 // negated classes include a leading \n.
468596 re->arguments.char_class.ccb_->AddRange('\n', '\n');
468597 }
468598 }
468599 bool first = true; // ] is okay as first char in class
468600 while (!s->empty() && ((*s)[0] != ']' || first)) {
468601 // - is only okay unescaped as first or last in class.
468602 // Except that Perl allows - anywhere.
468603 if ((*s)[0] == '-' && !first && !(flags_&PerlX) &&
468604 (s->size() == 1 || (*s)[1] != ']')) {
468605 StringPiece t = *s;
468606 t.remove_prefix(1); // '-'
468607 Rune r;
468608 int n = StringPieceToRune(&r, &t, status);
468609 if (n < 0) {
468610 re->Decref();
468611 return false;
468612 }
468613 status->set_code(kRegexpBadCharRange);
468614 status->set_error_arg(StringPiece(s->data(), 1+n));
468615 re->Decref();
468616 return false;
468617 }
468618 first = false;
468619
468620 // Look for [:alnum:] etc.
468621 if (s->size() > 2 && (*s)[0] == '[' && (*s)[1] == ':') {
468622 switch (ParseCCName(s, flags_, re->arguments.char_class.ccb_, status)) {
468623 case kParseOk:
468624 continue;
468625 case kParseError:
468626 re->Decref();
468627 return false;
468628 case kParseNothing:
468629 break;
468630 }
468631 }
468632
468633 // Look for Unicode character group like \p{Han}
468634 if (s->size() > 2 &&
468635 (*s)[0] == '\\' &&
468636 ((*s)[1] == 'p' || (*s)[1] == 'P')) {
468637 switch (ParseUnicodeGroup(s, flags_, re->arguments.char_class.ccb_, status)) {
468638 case kParseOk:
468639 continue;
468640 case kParseError:
468641 re->Decref();
468642 return false;
468643 case kParseNothing:
468644 break;
468645 }
468646 }
468647
468648 // Look for Perl character class symbols (extension).
468649 const UGroup *g = MaybeParsePerlCCEscape(s, flags_);
468650 if (g != NULL) {
468651 AddUGroup(re->arguments.char_class.ccb_, g, g->sign, flags_);
468652 continue;
468653 }
468654
468655 // Otherwise assume single character or simple range.
468656 RuneRange rr;
468657 if (!ParseCCRange(s, &rr, whole_class, status)) {
468658 re->Decref();
468659 return false;
468660 }
468661 // AddRangeFlags is usually called in response to a class like
468662 // \p{Foo} or [[:foo:]]; for those, it filters \n out unless
468663 // Regexp::ClassNL is set. In an explicit range or singleton
468664 // like we just parsed, we do not filter \n out, so set ClassNL
468665 // in the flags.
468666 re->arguments.char_class.ccb_->AddRangeFlags(rr.lo, rr.hi, flags_ | Regexp::ClassNL);
468667 }
468668 if (s->empty()) {
468669 status->set_code(kRegexpMissingBracket);
468670 status->set_error_arg(whole_class);
468671 re->Decref();
468672 return false;
468673 }
468674 s->remove_prefix(1); // ']'
468675
468676 if (negated)
468677 re->arguments.char_class.ccb_->Negate();
468678
468679 *out_re = re;
468680 return true;
468681}

◆ ParseCCCharacter()

bool duckdb_re2::Regexp::ParseState::ParseCCCharacter ( StringPiece * s,
Rune * rp,
const StringPiece & whole_class,
RegexpStatus * status )
468529 {
468530 if (s->empty()) {
468531 status->set_code(kRegexpMissingBracket);
468532 status->set_error_arg(whole_class);
468533 return false;
468534 }
468535
468536 // Allow regular escape sequences even though
468537 // many need not be escaped in this context.
468538 if ((*s)[0] == '\\')
468539 return ParseEscape(s, rp, status, rune_max_);
468540
468541 // Otherwise take the next rune.
468542 return StringPieceToRune(rp, s, status) >= 0;
468543}

◆ ParseCCRange()

bool duckdb_re2::Regexp::ParseState::ParseCCRange ( StringPiece * s,
RuneRange * rr,
const StringPiece & whole_class,
RegexpStatus * status )
468552 {
468553 StringPiece os = *s;
468554 if (!ParseCCCharacter(s, &rr->lo, whole_class, status))
468555 return false;
468556 // [a-] means (a|-), so check for final ].
468557 if (s->size() >= 2 && (*s)[0] == '-' && (*s)[1] != ']') {
468558 s->remove_prefix(1); // '-'
468559 if (!ParseCCCharacter(s, &rr->hi, whole_class, status))
468560 return false;
468561 if (rr->hi < rr->lo) {
468562 status->set_code(kRegexpBadCharRange);
468563 status->set_error_arg(
468564 StringPiece(os.data(), static_cast<size_t>(s->data() - os.data())));
468565 return false;
468566 }
468567 } else {
468568 rr->hi = rr->lo;
468569 }
468570 return true;
468571}

◆ ParsePerlFlags()

bool duckdb_re2::Regexp::ParseState::ParsePerlFlags ( StringPiece * s)
468722 {
468723 StringPiece t = *s;
468724
468725 // Caller is supposed to check this.
468726 if (!(flags_ & PerlX) || t.size() < 2 || t[0] != '(' || t[1] != '?') {
468727 status_->set_code(kRegexpInternalError);
468728 LOG(DFATAL) << "Bad call to ParseState::ParsePerlFlags";
468729 return false;
468730 }
468731
468732 t.remove_prefix(2); // "(?"
468733
468734 // Check for named captures, first introduced in Python's regexp library.
468735 // As usual, there are three slightly different syntaxes:
468736 //
468737 // (?P<name>expr) the original, introduced by Python
468738 // (?<name>expr) the .NET alteration, adopted by Perl 5.10
468739 // (?'name'expr) another .NET alteration, adopted by Perl 5.10
468740 //
468741 // Perl 5.10 gave in and implemented the Python version too,
468742 // but they claim that the last two are the preferred forms.
468743 // PCRE and languages based on it (specifically, PHP and Ruby)
468744 // support all three as well. EcmaScript 4 uses only the Python form.
468745 //
468746 // In both the open source world (via Code Search) and the
468747 // Google source tree, (?P<expr>name) is the dominant form,
468748 // so that's the one we implement. One is enough.
468749 if (t.size() > 2 && t[0] == 'P' && t[1] == '<') {
468750 // Pull out name.
468751 size_t end = t.find('>', 2);
468752 if (end == StringPiece::npos) {
468753 if (!IsValidUTF8(*s, status_))
468754 return false;
468755 status_->set_code(kRegexpBadNamedCapture);
468756 status_->set_error_arg(*s);
468757 return false;
468758 }
468759
468760 // t is "P<name>...", t[end] == '>'
468761 StringPiece capture(t.data()-2, end+3); // "(?P<name>"
468762 StringPiece name(t.data()+2, end-2); // "name"
468763 if (!IsValidUTF8(name, status_))
468764 return false;
468765 if (!IsValidCaptureName(name)) {
468766 status_->set_code(kRegexpBadNamedCapture);
468767 status_->set_error_arg(capture);
468768 return false;
468769 }
468770
468771 if (!DoLeftParen(name)) {
468772 // DoLeftParen's failure set status_.
468773 return false;
468774 }
468775
468776 s->remove_prefix(
468777 static_cast<size_t>(capture.data() + capture.size() - s->data()));
468778 return true;
468779 }
468780
468781 bool negated = false;
468782 bool sawflags = false;
468783 int nflags = flags_;
468784 Rune c;
468785 for (bool done = false; !done; ) {
468786 if (t.empty())
468787 goto BadPerlOp;
468788 if (StringPieceToRune(&c, &t, status_) < 0)
468789 return false;
468790 switch (c) {
468791 default:
468792 goto BadPerlOp;
468793
468794 // Parse flags.
468795 case 'i':
468796 sawflags = true;
468797 if (negated)
468798 nflags &= ~FoldCase;
468799 else
468800 nflags |= FoldCase;
468801 break;
468802
468803 case 'm': // opposite of our OneLine
468804 sawflags = true;
468805 if (negated)
468806 nflags |= OneLine;
468807 else
468808 nflags &= ~OneLine;
468809 break;
468810
468811 case 's':
468812 sawflags = true;
468813 if (negated)
468814 nflags &= ~DotNL;
468815 else
468816 nflags |= DotNL;
468817 break;
468818
468819 case 'U':
468820 sawflags = true;
468821 if (negated)
468822 nflags &= ~NonGreedy;
468823 else
468824 nflags |= NonGreedy;
468825 break;
468826
468827 // Negation
468828 case '-':
468829 if (negated)
468830 goto BadPerlOp;
468831 negated = true;
468832 sawflags = false;
468833 break;
468834
468835 // Open new group.
468836 case ':':
468837 if (!DoLeftParenNoCapture()) {
468838 // DoLeftParenNoCapture's failure set status_.
468839 return false;
468840 }
468841 done = true;
468842 break;
468843
468844 // Finish flags.
468845 case ')':
468846 done = true;
468847 break;
468848 }
468849 }
468850
468851 if (negated && !sawflags)
468852 goto BadPerlOp;
468853
468854 flags_ = static_cast<Regexp::ParseFlags>(nflags);
468855 *s = t;
468856 return true;
468857
468858BadPerlOp:
468859 status_->set_code(kRegexpBadPerlOp);
468860 status_->set_error_arg(
468861 StringPiece(s->data(), static_cast<size_t>(t.data() - s->data())));
468862 return false;
468863}

◆ DoConcatenation()

void duckdb_re2::Regexp::ParseState::DoConcatenation ( )
467914 {
467915 Regexp* r1 = stacktop_;
467916 if (r1 == NULL || IsMarker(r1->op())) {
467917 // empty concatenation is special case
467918 Regexp* re = new Regexp(kRegexpEmptyMatch, flags_);
467919 PushRegexp(re);
467920 }
467921 DoCollapse(kRegexpConcat);
467922}

◆ DoAlternation()

void duckdb_re2::Regexp::ParseState::DoAlternation ( )
467926 {
467927 DoVerticalBar();
467928 // Now stack top is kVerticalBar.
467929 Regexp* r1 = stacktop_;
467930 stacktop_ = r1->down_;
467931 r1->Decref();
467932 DoCollapse(kRegexpAlternate);
467933}

◆ DoCollapse()

void duckdb_re2::Regexp::ParseState::DoCollapse ( RegexpOp op)
467872 {
467873 // Scan backward to marker, counting children of composite.
467874 int n = 0;
467875 Regexp* next = NULL;
467876 Regexp* sub;
467877 for (sub = stacktop_; sub != NULL && !IsMarker(sub->op()); sub = next) {
467878 next = sub->down_;
467879 if (sub->op_ == op)
467880 n += sub->nsub_;
467881 else
467882 n++;
467883 }
467884
467885 // If there's just one child, leave it alone.
467886 // (Concat of one thing is that one thing; alternate of one thing is same.)
467887 if (stacktop_ != NULL && stacktop_->down_ == next)
467888 return;
467889
467890 // Construct op (alternation or concatenation), flattening op of op.
467891 PODArray<Regexp*> subs(n);
467892 next = NULL;
467893 int i = n;
467894 for (sub = stacktop_; sub != NULL && !IsMarker(sub->op()); sub = next) {
467895 next = sub->down_;
467896 if (sub->op_ == op) {
467897 Regexp** sub_subs = sub->sub();
467898 for (int k = sub->nsub_ - 1; k >= 0; k--)
467899 subs[--i] = sub_subs[k]->Incref();
467900 sub->Decref();
467901 } else {
467902 subs[--i] = FinishRegexp(sub);
467903 }
467904 }
467905
467906 Regexp* re = ConcatOrAlternate(op, subs.data(), n, flags_, true);
467907 re->simple_ = re->ComputeSimple();
467908 re->down_ = next;
467909 stacktop_ = re;
467910}
GMat sub(const GMat &src1, const GMat &src2, int ddepth=-1)

◆ MaybeConcatString()

bool duckdb_re2::Regexp::ParseState::MaybeConcatString ( int r,
ParseFlags flags )
467945 {
467946 Regexp* re1;
467947 Regexp* re2;
467948 if ((re1 = stacktop_) == NULL || (re2 = re1->down_) == NULL)
467949 return false;
467950
467951 if (re1->op_ != kRegexpLiteral && re1->op_ != kRegexpLiteralString)
467952 return false;
467953 if (re2->op_ != kRegexpLiteral && re2->op_ != kRegexpLiteralString)
467954 return false;
467955 if ((re1->parse_flags_ & FoldCase) != (re2->parse_flags_ & FoldCase))
467956 return false;
467957
467958 if (re2->op_ == kRegexpLiteral) {
467959 // convert into string
467960 Rune rune = re2->arguments.rune_;
467961 re2->op_ = kRegexpLiteralString;
467962 re2->arguments.literal_string.nrunes_ = 0;
467963 re2->arguments.literal_string.runes_ = NULL;
467964 re2->AddRuneToString(rune);
467965 }
467966
467967 // push re1 into re2.
467968 if (re1->op_ == kRegexpLiteral) {
467969 re2->AddRuneToString(re1->arguments.rune_);
467970 } else {
467971 for (int i = 0; i < re1->arguments.literal_string.nrunes_; i++)
467972 re2->AddRuneToString(re1->arguments.literal_string.runes_[i]);
467973 re1->arguments.literal_string.nrunes_ = 0;
467974 delete[] re1->arguments.literal_string.runes_;
467975 re1->arguments.literal_string.runes_ = NULL;
467976 }
467977
467978 // reuse re1 if possible
467979 if (r >= 0) {
467980 re1->op_ = kRegexpLiteral;
467981 re1->arguments.rune_ = r;
467982 re1->parse_flags_ = static_cast<uint16_t>(flags);
467983 return true;
467984 }
467985
467986 stacktop_ = re2;
467987 re1->Decref();
467988 return false;
467989}
::uint16_t uint16_t

The documentation for this class was generated from the following file: