\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef.upgrade/embedded/lib/ruby/gems/2.3.0/gems/parser-2.4.0.0/lib/

Viewing File: gauntlet_parser.rb

require 'gauntlet'
require 'parser/all'
require 'shellwords'

class ParserGauntlet < Gauntlet
  RUBY20 = 'ruby'
  RUBY19 = 'ruby1.9.1'
  RUBY18 = '/opt/rubies/ruby-1.8.7-p370/bin/ruby'

  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

  def parse(name)
    puts "GEM: #{name}"

    @result = {}

    if ENV.include?('FAST')
      total_size = Dir["**/*.rb"].map(&File.method(:size)).reduce(:+)
      if total_size > 300_000
        puts "Skip."
        return
      end
    end

    Dir["**/*.rb"].each do |file|
      next if File.directory? file

      try(Parser::Ruby20, RUBY20, file) do
        puts "Trying 1.9:"
        try(Parser::Ruby19, RUBY19, file, show_ok: true) do
          puts "Trying 1.8:"
          try(Parser::Ruby18, RUBY18, file, show_ok: true) do
            puts "Invalid syntax."
          end
        end
      end
    end

    @result
  end

  def run(name)
    data[name] = parse(name)
    self.dirty = true
  end

  def should_skip?(name)
    data[name] == {}
  end

  def load_yaml(*)
    data = super
    @was_errors = data.count { |_name, errs| errs != {} }

    data
  end

  def shutdown
    super

    errors  = data.count { |_name, errs| errs != {} }
    total   = data.count
    percent = "%.5f" % [100 - errors.to_f / total * 100]
    puts "!!! was: #{@was_errors} now: #{errors} total: #{total} frac: #{percent}%"
  end
end

filter = ARGV.shift
filter = Regexp.new filter if filter

gauntlet = ParserGauntlet.new

if ENV.include? 'UPDATE'
  gauntlet.source_index
  gauntlet.update_gem_tarballs
end

gauntlet.run_the_gauntlet filter