(&mut self, exprs: &[Hir])
| 472 | } |
| 473 | |
| 474 | fn c_alternate(&mut self, exprs: &[Hir]) -> Result { |
| 475 | debug_assert!( |
| 476 | exprs.len() >= 2, "alternates must have at least 2 exprs"); |
| 477 | |
| 478 | // Initial entry point is always the first split. |
| 479 | let first_split_entry = self.insts.len(); |
| 480 | |
| 481 | // Save up all of the holes from each alternate. They will all get |
| 482 | // patched to point to the same location. |
| 483 | let mut holes = vec![]; |
| 484 | |
| 485 | let mut prev_hole = Hole::None; |
| 486 | for e in &exprs[0..exprs.len() - 1] { |
| 487 | self.fill_to_next(prev_hole); |
| 488 | let split = self.push_split_hole(); |
| 489 | let prev_entry = self.insts.len(); |
| 490 | let Patch { hole, entry } = self.c(e)?; |
| 491 | if prev_entry == self.insts.len() { |
| 492 | // TODO(burntsushi): It is kind of silly that we don't support |
| 493 | // empty-subexpressions in alternates, but it is supremely |
| 494 | // awkward to support them in the existing compiler |
| 495 | // infrastructure. This entire compiler needs to be thrown out |
| 496 | // anyway, so don't feel too bad. |
| 497 | return Err(Error::Syntax( |
| 498 | "alternations cannot currently contain \ |
| 499 | empty sub-expressions".to_string())); |
| 500 | } |
| 501 | holes.push(hole); |
| 502 | prev_hole = self.fill_split(split, Some(entry), None); |
| 503 | } |
| 504 | let prev_entry = self.insts.len(); |
| 505 | let Patch { hole, entry } = self.c(&exprs[exprs.len() - 1])?; |
| 506 | if prev_entry == self.insts.len() { |
| 507 | // TODO(burntsushi): See TODO above. |
| 508 | return Err(Error::Syntax( |
| 509 | "alternations cannot currently contain \ |
| 510 | empty sub-expressions".to_string())); |
| 511 | } |
| 512 | holes.push(hole); |
| 513 | self.fill(prev_hole, entry); |
| 514 | Ok(Patch { hole: Hole::Many(holes), entry: first_split_entry }) |
| 515 | } |
| 516 | |
| 517 | fn c_repeat(&mut self, rep: &hir::Repetition) -> Result { |
| 518 | use syntax::hir::RepetitionKind::*; |
no test coverage detected