   seek: (position) ->
     @position = Point.zero()
     @sourcePosition = Point.zero()
-    @transformDelegate.reset(@position, @sourcePosition)
+    @transformBuffer.reset(@position, @sourcePosition)
     return if position.isZero()
 
     until @position.compare(position) >= 0


    overshoot = position.column - lastSourcePosition.column
    lastPosition.column += overshoot
    @transformDelegate.reset(lastPosition, position)
    @position = lastPosition
    @sourcePosition = position


  getSourcePosition: ->
    @sourcePosition

class TransformBuffer
  constructor: (@transform, @sourceIterator) ->
    @reset(Point.zero(), Point.zero())

  next: ->
    @transform.operate(this) unless @outputs.length > 0
    @outputs.shift()

  reset: (position, sourcePosition) ->
    @position = position
    @sourcePosition = sourcePosition
    @outputs = []
    @currentSourceOutput = null
    @sourceIterator.seek(sourcePosition)

  read: =>
    @currentSourceOutput or= @sourceIterator.next().value

  consume: (count) =>
    @sourcePosition.column += count
    @currentSourceOutput = @currentSourceOutput.substring(count)

  produce: (output) =>
    switch output
