Sha256: d50b87edb2168813669deb4aba5011ff66961621f84f8036e1a4a2bbf8f7410c

Contents?: true

Size: 900 Bytes

Versions: 14

Compression:

Stored size: 900 Bytes

Contents

# frozen_string_literal: true

require 'rubocop'
require 'rubocop/ast/builder'
require 'parser/current'

module SlimLint
  # Parser for the Ruby language.
  #
  # This provides a convenient wrapper around the `parser` gem and the
  # `astrolabe` integration to go with it. It is intended to be used for linter
  # checks that require deep inspection of Ruby code.
  class RubyParser
    # Creates a reusable parser.
    def initialize
      @builder = ::RuboCop::AST::Builder.new
      @parser = ::Parser::CurrentRuby.new(@builder)
    end

    # Parse the given Ruby source into an abstract syntax tree.
    #
    # @param source [String] Ruby source code
    # @return [Array] syntax tree in the form returned by Parser gem
    def parse(source)
      buffer = ::Parser::Source::Buffer.new('(string)')
      buffer.source = source

      @parser.reset
      @parser.parse(buffer)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
slim_lint-0.23.0 lib/slim_lint/ruby_parser.rb
slim_lint-0.22.1 lib/slim_lint/ruby_parser.rb
slim_lint-0.22.0 lib/slim_lint/ruby_parser.rb
slim_lint-0.21.1 lib/slim_lint/ruby_parser.rb
slim_lint-0.21.0 lib/slim_lint/ruby_parser.rb
slim_lint-0.20.2 lib/slim_lint/ruby_parser.rb
slim_lint-0.20.1 lib/slim_lint/ruby_parser.rb
slim_lint-0.20.0 lib/slim_lint/ruby_parser.rb
slim_lint-0.19.0 lib/slim_lint/ruby_parser.rb
slim_lint-0.18.0 lib/slim_lint/ruby_parser.rb
slim_lint-0.17.1 lib/slim_lint/ruby_parser.rb
slim_lint-0.17.0 lib/slim_lint/ruby_parser.rb
slim_lint-0.16.1 lib/slim_lint/ruby_parser.rb
slim_lint-0.16.0 lib/slim_lint/ruby_parser.rb