Class: Pure::Parser::RubyParser::Processor
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- Pure::Parser::RubyParser::Processor
- Includes:
- DupSexp
- Defined in:
- lib/pure/parser/impl/ruby_parser.rb
Instance Method Summary collapse
-
#initialize(file) ⇒ Processor
constructor
A new instance of Processor.
- #process(sexp) ⇒ Object
- #run ⇒ Object
Methods included from DupSexp
Constructor Details
#initialize(file) ⇒ Processor
Returns a new instance of Processor.
36 37 38 39 40 |
# File 'lib/pure/parser/impl/ruby_parser.rb', line 36 def initialize(file) super() @file = file @defs = Hash.new end |
Instance Method Details
#process(sexp) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pure/parser/impl/ruby_parser.rb', line 47 def process(sexp) if sexp[0] == :defn name = sexp[1] args = dup_sexp(sexp[2][1..-1]).to_a args.reject! { |a| a.to_s =~ %r!\A&! } default = ( args.last and args.last.is_a?(Array) and args.last[0] == :block ) splat = args.any? { |arg| arg.to_s =~ %r!\A\*! } @defs[sexp.line] = { :name => name, :args => args, :code => dup_sexp(sexp), :splat => splat, :default => default, } elsif sexp[0] == :iter and sexp[1][0] == :call and sexp[1][1] == nil and (sexp[1][2] == :fun || sexp[1][2] == :fun_map) @defs[sexp[1].line] = { :name => :__fun, :code => dup_sexp(sexp) } end super end |
#run ⇒ Object
42 43 44 45 |
# File 'lib/pure/parser/impl/ruby_parser.rb', line 42 def run process(::RubyParser.new.parse(File.read(@file))) @defs end |