func readThrough()

in Sources/_StringProcessing/Legacy/TortoiseVM.swift [89:139]


  func readThrough(_ sp: String.Index, _ hatchling: Hatchling) -> Bale {
    var result = Bale()

    var worklist = [hatchling]
    while !worklist.isEmpty {
      var hatchling = worklist.popLast()!
      while !code[hatchling.pc].isMatching {
        switch code[hatchling.pc] {
        case .nop: hatchling.plod()
        case .split(disfavoring: let other):
          var disfavoredHatchling = hatchling
          hatchling.plod()
          disfavoredHatchling.plod(to: code.lookup(other)+1) // read through label
          worklist.append(disfavoredHatchling)
        case .goto(label: let target):
          hatchling.plod(to: code.lookup(target)+1)
        case .label(_):
          hatchling.plod()
        case .beginCapture:
          hatchling.core.beginCapture(sp)
          hatchling.plod()
        case .endCapture(let transform):
          if hatchling.core.endCapture(sp, transform: transform) {
            hatchling.plod()
          } else {
            hatchling.plod(to: code.endIndex)
          }
        case .beginGroup:
          hatchling.core.beginGroup()
          hatchling.plod()
        case .endGroup:
          hatchling.core.endGroup()
          hatchling.plod()
        case .captureSome:
          hatchling.core.captureSome()
          hatchling.plod()
        case .captureNil(let childType):
          hatchling.core.captureNil(childType: childType)
          hatchling.plod()
        case .captureArray(let childType):
          hatchling.core.captureArray(childType: childType)
          hatchling.plod()

        default:
          fatalError("\(code[hatchling.pc]) should of been caught by !isMatching")
        }
      }
      result.append(hatchling)
    }
    return result
  }