Given fragments for a and b, returns fragment for a|b.
| 299 | |
| 300 | // Given fragments for a and b, returns fragment for a|b. |
| 301 | Frag Compiler::Alt(Frag a, Frag b) { |
| 302 | // Special case for convenience in loops. |
| 303 | if (IsNoMatch(a)) |
| 304 | return b; |
| 305 | if (IsNoMatch(b)) |
| 306 | return a; |
| 307 | |
| 308 | int id = AllocInst(1); |
| 309 | if (id < 0) |
| 310 | return NoMatch(); |
| 311 | |
| 312 | inst_[id].InitAlt(a.begin, b.begin); |
| 313 | return Frag(id, PatchList::Append(inst_.data(), a.end, b.end)); |
| 314 | } |
| 315 | |
| 316 | // When capturing submatches in like-Perl mode, a kOpAlt Inst |
| 317 | // treats out_ as the first choice, out1_ as the second. |