475129 {
475130 int prec = parent_arg;
475131 switch (re->op()) {
475132 case kRegexpNoMatch:
475133
475134
475135 t_->append("[^\\x00-\\x{10ffff}]");
475136 break;
475137
475138 case kRegexpEmptyMatch:
475139
475140
475141 if (prec < PrecEmpty)
475142 t_->append("(?:)");
475143 break;
475144
475145 case kRegexpLiteral:
475146 AppendLiteral(t_, re->rune(),
475147 (re->parse_flags() & Regexp::FoldCase) != 0);
475148 break;
475149
475150 case kRegexpLiteralString:
475151 for (int i = 0; i < re->nrunes(); i++)
475152 AppendLiteral(t_, re->runes()[i],
475153 (re->parse_flags() & Regexp::FoldCase) != 0);
475154 if (prec < PrecConcat)
475155 t_->append(")");
475156 break;
475157
475158 case kRegexpConcat:
475159 if (prec < PrecConcat)
475160 t_->append(")");
475161 break;
475162
475163 case kRegexpAlternate:
475164
475165
475166 if ((*t_)[t_->size()-1] == '|')
475167 t_->erase(t_->size()-1);
475168 else
475169 LOG(DFATAL) << "Bad final char: " << t_;
475170 if (prec < PrecAlternate)
475171 t_->append(")");
475172 break;
475173
475174 case kRegexpStar:
475175 t_->append("*");
475176 if (re->parse_flags() & Regexp::NonGreedy)
475177 t_->append("?");
475178 if (prec < PrecUnary)
475179 t_->append(")");
475180 break;
475181
475182 case kRegexpPlus:
475183 t_->append("+");
475184 if (re->parse_flags() & Regexp::NonGreedy)
475185 t_->append("?");
475186 if (prec < PrecUnary)
475187 t_->append(")");
475188 break;
475189
475190 case kRegexpQuest:
475191 t_->append("?");
475192 if (re->parse_flags() & Regexp::NonGreedy)
475193 t_->append("?");
475194 if (prec < PrecUnary)
475195 t_->append(")");
475196 break;
475197
475198 case kRegexpRepeat:
475199 if (re->max() == -1)
475200 t_->append(StringPrintf("{%d,}", re->min()));
475201 else if (re->min() == re->max())
475202 t_->append(StringPrintf("{%d}", re->min()));
475203 else
475204 t_->append(StringPrintf("{%d,%d}", re->min(), re->max()));
475205 if (re->parse_flags() & Regexp::NonGreedy)
475206 t_->append("?");
475207 if (prec < PrecUnary)
475208 t_->append(")");
475209 break;
475210
475211 case kRegexpAnyChar:
475212 t_->append(".");
475213 break;
475214
475215 case kRegexpAnyByte:
475216 t_->append("\\C");
475217 break;
475218
475219 case kRegexpBeginLine:
475220 t_->append("^");
475221 break;
475222
475223 case kRegexpEndLine:
475224 t_->append("$");
475225 break;
475226
475227 case kRegexpBeginText:
475228 t_->append("(?-m:^)");
475229 break;
475230
475231 case kRegexpEndText:
475232 if (re->parse_flags() & Regexp::WasDollar)
475233 t_->append("(?-m:$)");
475234 else
475235 t_->append("\\z");
475236 break;
475237
475238 case kRegexpWordBoundary:
475239 t_->append("\\b");
475240 break;
475241
475242 case kRegexpNoWordBoundary:
475243 t_->append("\\B");
475244 break;
475245
475246 case kRegexpCharClass: {
475247 if (re->cc()->size() == 0) {
475248 t_->append("[^\\x00-\\x{10ffff}]");
475249 break;
475250 }
475251 t_->append("[");
475252
475253
475254 CharClass* cc = re->cc();
475255 if (cc->Contains(0xFFFE) && !cc->full()) {
475256 cc = cc->Negate();
475257 t_->append("^");
475258 }
475259 for (CharClass::iterator i = cc->begin(); i != cc->end(); ++i)
475260 AppendCCRange(t_, i->lo, i->hi);
475261 if (cc != re->cc())
475262 cc->Delete();
475263 t_->append("]");
475264 break;
475265 }
475266
475267 case kRegexpCapture:
475268 t_->append(")");
475269 break;
475270
475271 case kRegexpHaveMatch:
475272
475273
475274
475275 t_->append(StringPrintf("(?HaveMatch:%d)", re->match_id()));
475276 break;
475277 }
475278
475279
475280 if (prec == PrecAlternate)
475281 t_->append("|");
475282
475283 return 0;
475284}