# File lib/gauntlet_parser.rb, line 10
  def try(parser, ruby, file, show_ok: false)
    try_ruby = lambda do |e|
      Process.spawn(%{#{ruby} -c #{Shellwords.escape file}},
                    :err => '/dev/null', :out => '/dev/null')
      _, status = Process.wait2

      if status.success?
        # Bug in Parser.
        puts "Parser bug."
        @result[file] = { parser.to_s => "#{e.class}: #{e.to_s}" }
      else
        # No, this file is not Ruby.
        yield if block_given?
      end
    end

    begin
      parser.parse_file(file)

    rescue Parser::SyntaxError => e
      if e.diagnostic.location.resize(2).is?('<%')
        puts "ERb."
        return
      end

      try_ruby.call(e)

    rescue ArgumentError, RegexpError,
           Encoding::UndefinedConversionError => e
      puts "#{file}: #{e.class}: #{e.to_s}"

      try_ruby.call(e)

    rescue Interrupt
      raise

    rescue Exception => e
      puts "Parser bug: #{file} #{e.class}: #{e.to_s}"
      @result[file] = { parser.to_s => "#{e.class}: #{e.to_s}" }

    else
      puts "Ok." if show_ok
    end
  end