Sha256: 14c9dd3c3c85b9825b71eb8bb038e43b495cb875c22e4b6adbfdcf1f0627559d

Contents?: true

Size: 1007 Bytes

Versions: 1

Compression:

Stored size: 1007 Bytes

Contents

require 'ripper_ruby_parser/commenting_sexp_builder'
require 'ripper_ruby_parser/sexp_processor'

module RipperRubyParser
  # Main parser class. Brings together Ripper and our
  # RipperRubyParser::SexpProcessor.
  class Parser
    attr_accessor :extra_compatible

    def initialize processor=SexpProcessor.new
      @processor = processor
      @extra_compatible = false
    end

    def parse source, filename='(string)', lineno=1
      # FIXME: Allow parser class to be passed to #initialize also.
      parser = CommentingSexpBuilder.new(source, filename, lineno)

      result = suppress_warnings { parser.parse }
      raise "Ripper parse failed." if result.nil?

      exp = Sexp.from_array(result)

      @processor.filename = filename
      @processor.extra_compatible = extra_compatible
      @processor.process exp
    end

    private

    def suppress_warnings
      old_verbose = $VERBOSE
      $VERBOSE = nil
      result = yield
      $VERBOSE = old_verbose
      result
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ripper_ruby_parser-0.0.5 lib/ripper_ruby_parser/parser.rb