Class: SlimLint::RubyParser
- Inherits:
-
Object
- Object
- SlimLint::RubyParser
- Defined in:
- lib/slim_lint/ruby_parser.rb
Overview
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.
Instance Method Summary collapse
-
#initialize ⇒ RubyParser
constructor
Creates a reusable parser.
-
#parse(source) ⇒ Array
Parse the given Ruby source into an abstract syntax tree.
Constructor Details
#initialize ⇒ RubyParser
Creates a reusable parser.
22 23 24 25 26 |
# File 'lib/slim_lint/ruby_parser.rb', line 22 def initialize require_parser('current') @builder = ::RuboCop::AST::Builder.new @parser = ::Parser::CurrentRuby.new(@builder) end |
Instance Method Details
#parse(source) ⇒ Array
Parse the given Ruby source into an abstract syntax tree.
32 33 34 35 36 37 38 |
# File 'lib/slim_lint/ruby_parser.rb', line 32 def parse(source) buffer = ::Parser::Source::Buffer.new('(string)') buffer.source = source @parser.reset @parser.parse(buffer) end |