Class: LiveAST::RubyParser
- Inherits:
-
Object
- Object
- LiveAST::RubyParser
- Defined in:
- lib/live_ast/ruby_parser.rb,
lib/live_ast/ruby_parser/test.rb,
lib/live_ast/ruby_parser/unparser.rb
Defined Under Namespace
Constant Summary collapse
- STOREABLE_SEXP_TYPES =
[:defn, :defs, :iter].freeze
Instance Method Summary collapse
-
#parse(source) ⇒ Object
Returns a line-to-sexp hash where sexp corresponds to the method or block defined at the given line.
- #process(sexp) ⇒ Object
- #store_sexp(sexp, line) ⇒ Object
Instance Method Details
#parse(source) ⇒ Object
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.
12 13 14 15 16 |
# File 'lib/live_ast/ruby_parser.rb', line 12 def parse(source) @defs = {} process ::RubyParser.new.parse(source) @defs end |
#process(sexp) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/live_ast/ruby_parser.rb', line 20 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) ⇒ Object
28 29 30 |
# File 'lib/live_ast/ruby_parser.rb', line 28 def store_sexp(sexp, line) @defs[line] = @defs.key?(line) ? :multiple : sexp end |