     @position = TOP
     @previousSide = null
 
+  # Private: Complete handling of an individual CONFLICT_REGEX match.
+  #
   finish: ->
     @previousSide.followingMarker = @previousSide.refBannerMarker
 
+  # Private: Mark the current lines as "ours".
+  #
+  # Returns [Side] marking the current conflict's side.
+  #
   markOurs: -> @_markHunk OurSide
 
+  # Private: Mark the current lines as a separator.
+  #
+  # Returns [Navigator] containing a marker to the separator line.
+  #
   markSeparator: ->
     unless @position is MIDDLE
-      throw new Error "Unexpected position for separator: #{@position}"
+      throw new Error("Unexpected position for separator: #{@position}")
     @position = BOTTOM
 
     sepRowStart = @currentRow

    @previousSide = side
    side

  _advance: (rowCount) -> @currentRow += rowCount

module.exports =
class Conflict

  constructor: (@ours, @theirs, @parent, @navigator, @state) ->
    @emitter = new Emitter


    @navigator.conflict = this
    @resolution = null

  # Public: Has this conflict been resolved in any way?
  #
  # Return [Boolean]
  #
  isResolved: -> @resolution?

  # Public: Attach an event handler to be notified when this conflict is resolved.
  #
  # callback [Function]
  #
  onDidResolveConflict: (callback) ->
    @emitter.on 'resolve-conflict', callback

  # Public: Specify which Side is to be kept. Note that either side may have been modified by the
  # user prior to resolution. Notify any subscribers.
  #
  # side [Side] our changes or their changes.
  #
  resolveAs: (side) ->
    @resolution = side
    @emitter.emit 'resolve-conflict'

  # Public: Locate the position that the editor should scroll to in order to make this conflict
  # visible.
  #
  # Return [Point] buffer coordinates
  #
  scrollTarget: -> @ours.marker.getTailBufferPosition()

  # Public: Audit all Marker instances owned by subobjects within this Conflict.
  #
  # Return [Array<Marker>]
  #
  markers: ->
    _.flatten [@ours.markers(), @theirs.markers(), @navigator.markers()], true

  # Public: Console-friendly identification of this conflict.
  #
  # Return [String] that distinguishes this conflict from others.
  #
  toString: -> "[conflict: #{@ours} #{@theirs}]"

  # Public: Parse any conflict markers in a TextEditor's buffer and return a Conflict that contains
  # markers corresponding to each.
  #
  # state [MergeState] Repository-wide state of the merge.
  # editor [TextEditor] The editor to search.
  # return [Array<Conflict>] A (possibly empty) collection of parsed Conflicts.
  #
  @all: (state, editor) ->
    results = []
    previous = null
    marker = new ConflictParser(state, editor)

    editor.getBuffer().scan CONFLICT_REGEX, (m) ->
      marker.start m
