Write you own iterator

(pseudo code, not checked even for indentations)
    
    
    import parseUtils # for parseint suitable to advance cursors
    
    iterator customSplit(splitToken: char, tokenStream: string): int =
      var cursor = 0
      var code = low(int) # just a default value to detect bugs
      
      while cursor < tokenStream.len:
        cursor += parseInt(tokenStream, code, cursor)
        case code
        of 1:
          yield(123)
          yield(456)
          yield(789)
          # This will yield 123, 456, 789 for the next 3 iterations
         of 2:
           yield(123456)
           # This will yield 123456
         of 99:
           discard
         else:
           quit "Cannot parse instructions"
    
    
    Run

Reply via email to