class LiveAST::RubyParser

Constants

STOREABLE_SEXP_TYPES

Public Instance Methods

parse(source) click to toggle source

Returns a line-to-sexp hash where sexp corresponds to the method or block defined at the given line.

This method is the only requirement of a LiveAST parser plugin.

# File lib/live_ast/ruby_parser.rb, line 14
def parse(source)
  @defs = {}
  process ::RubyParser.new.parse(source)
  @defs
end
process(sexp) click to toggle source
# File lib/live_ast/ruby_parser.rb, line 22
def process(sexp)
  store_sexp(sexp, sexp.line) if STOREABLE_SEXP_TYPES.include? sexp.first

  sexp.each do |elem|
    process(elem) if elem.is_a? Sexp
  end
end
store_sexp(sexp, line) click to toggle source
# File lib/live_ast/ruby_parser.rb, line 30
def store_sexp(sexp, line)
  @defs[line] = @defs.key?(line) ? :multiple : sexp
end