Sha256: e9f82663c03c870720d88ef5e7b5f3ead85eefbe241f119a15d83597bd6c9eec

Contents?: true

Size: 923 Bytes

Versions: 12

Compression:

Stored size: 923 Bytes

Contents

old_verbose, $VERBOSE = $VERBOSE, nil
require 'parser/current'
$VERBOSE = old_verbose
require 'reek/source/tree_dresser'
require 'reek/source/ast_node'

module Reek
  module Source
    #
    # A +Source+ object represents a chunk of Ruby source code.
    #
    class SourceCode
      attr_reader :desc

      def initialize(code, desc, parser = Parser::Ruby21)
        @source = code
        @desc = desc
        @parser = parser
      end

      def syntax_tree
        @syntax_tree ||=
          begin
            begin
              ast, comments = @parser.parse_with_comments(@source, @desc)
            rescue Racc::ParseError, Parser::SyntaxError => error
              $stderr.puts "#{desc}: #{error.class.name}: #{error}"
            end

            comment_map = Parser::Source::Comment.associate(ast, comments) if ast
            TreeDresser.new.dress(ast, comment_map)
          end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
reek-2.0.4 lib/reek/source/source_code.rb
reek-2.0.3 lib/reek/source/source_code.rb
reek-2.0.2 lib/reek/source/source_code.rb
reek-2.0.1 lib/reek/source/source_code.rb
reek-2.0.0 lib/reek/source/source_code.rb
reek-1.6.6 lib/reek/source/source_code.rb
reek-1.6.5 lib/reek/source/source_code.rb
reek-1.6.4 lib/reek/source/source_code.rb
reek-1.6.3 lib/reek/source/source_code.rb
reek-1.6.2 lib/reek/source/source_code.rb
reek-1.6.1 lib/reek/source/source_code.rb
reek-1.6.0 lib/reek/source/source_code.rb