require 'nothing' class Reciver def initialize(eval_class, *args) @i = 0 @translator = Ruby2Ruby.new @eval_class = eval_class @args = args end def check_sexp(p_sexp) (p_sexp.flatten.uniq & [:xstr, :eval, :instance_eval, :class_eval, :module_eval]).empty? end def sexp_to_lambda_str(p_sexp) arg_sexp = p_sexp[1] # first part of sexpression body_sexp = p_sexp[2] if arg_sexp args = case arg_sexp[0] # kind of arguments when :dasgn_curr # single argument arg_sexp[1] when :masgn # multiple argument if arg_sexp[1][0] == :dasgn_curr # actually one but with * "*#{arg_sexp[1][1]}" elsif arg_sexp[1][0] == :array # multiple arg_sexp[1][1..-1].map{|a| a[1]}.join(',') else raise RuntimeError, "not suported node #{arg_sexp[1][0].inspect}" end else raise RuntimeError, "not suported node #{arg_sexp[0]}" end "lambda{|#{args}| \n"+@translator.process(body_sexp)+"\n}" else "lambda{\n"+@translator.process(body_sexp)+"\n}" end end def sexp_to_lambda(p_sexp) if check_sexp(p_sexp) $logger.debug sexp_to_lambda_str(p_sexp) begin @eval_class.new(*@args).instance_eval(sexp_to_lambda_str(p_sexp)) rescue Exception => e raise end else raise RuntimeError, "provided s-expresion didn't pass sanity check" end end end