class SlimLint::RubyParser
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.
Public Class Methods
new()
click to toggle source
Creates a reusable parser.
# File lib/slim_lint/ruby_parser.rb, line 15 def initialize @builder = ::RuboCop::AST::Builder.new @parser = ::Parser::CurrentRuby.new(@builder) end
Public Instance Methods
parse(source)
click to toggle source
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
# File lib/slim_lint/ruby_parser.rb, line 24 def parse(source) buffer = ::Parser::Source::Buffer.new('(string)') buffer.source = source @parser.reset @parser.parse(buffer) end