class HamlLint::RubyParser
Parser for the Ruby language.
This provides a convenient wrapper around the `parser` gem and the Astrolabe integration (now built-in to RuboCop, so no longer called Astrolabe) 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/haml_lint/ruby_parser.rb, line 16 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/haml_lint/ruby_parser.rb, line 25 def parse(source) buffer = ::Parser::Source::Buffer.new('(string)') buffer.source = source @parser.reset @parser.parse(buffer) end