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.
14 15 16 17 18 |
# File 'lib/live_ast/ruby_parser.rb', line 14 def parse(source) @defs = {} process ::RubyParser.new.parse(source) @defs end |
#process(sexp) ⇒ Object
22 23 24 25 26 27 28 |
# 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) ⇒ Object
30 31 32 |
# File 'lib/live_ast/ruby_parser.rb', line 30 def store_sexp(sexp, line) @defs[line] = @defs.key?(line) ? :multiple : sexp end |