> Note that parsing files was discussed in the Manning book, and I recently 
> added a section to my book too[...]

what about using streams and an iterator?
    
    
    import streams
    
    proc pgmRead(strm: FileStream, filePos: int=0): auto=
      var data: char
      strm.setPosition(filePos)
      return iterator: (int, char)=
        while not strm.atEnd:
          let idx = getPosition(strm)
          read(strm, data)
          yield (idx, data)
        strm.close()
    
    
    Run

full code for parsing pgm 
<https://gist.github.com/ingoogni/b422eaa251e9c9192071be94d8269de9>

Reply via email to