class Bundler::LockfileParser

def initialize(lockfile)

def initialize(lockfile)
  @platforms    = []
  @sources      = []
  @dependencies = {}
  @parse_method = nil
  @specs        = {}
  @lockfile_path = begin
    SharedHelpers.relative_lockfile_path
  rescue GemfileNotFound
    "Gemfile.lock"
  end
  @pos = Position.new(1, 1)
  if lockfile.match?(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/)
    raise LockfileError, "Your #{@lockfile_path} contains merge conflicts.\n" \
      "Run `git checkout HEAD -- #{@lockfile_path}` first to get a clean lock."
  end
  lockfile.split(/((?:\r?\n)+)/) do |line|
    # split alternates between the line and the following whitespace
    next @pos.advance!(line) if line.match?(/^\s*$/)
    if SOURCE.include?(line)
      @parse_method = :parse_source
      parse_source(line)
    elsif line == DEPENDENCIES
      @parse_method = :parse_dependency
    elsif line == CHECKSUMS
      # This is a temporary solution to make this feature disabled by default
      # for all gemfiles that don't already explicitly include the feature.
      @checksums = true
      @parse_method = :parse_checksum
    elsif line == PLATFORMS
      @parse_method = :parse_platform
    elsif line == RUBY
      @parse_method = :parse_ruby
    elsif line == BUNDLED
      @parse_method = :parse_bundled_with
    elsif /^[^\s]/.match?(line)
      @parse_method = nil
    elsif @parse_method
      send(@parse_method, line)
    end
    @pos.advance!(line)
  end
  @specs = @specs.values.sort_by!(&:full_name)
rescue ArgumentError => e
  Bundler.ui.debug(e)
  raise LockfileError, "Your lockfile is unreadable. Run `rm #{@lockfile_path}` " \
    "and then `bundle install` to generate a new lockfile. The error occurred while " \
    "evaluating #{@lockfile_path}:#{@pos}"
end