lib/ruby_less/processor.rb in rubyless-0.6.0 vs lib/ruby_less/processor.rb in rubyless-0.7.0
- old
+ new
@@ -7,13 +7,13 @@
attr_reader :ruby
INFIX_OPERATOR = ['<=>', '==', '<', '>', '<=', '>=', '-', '+', '*', '/', '%']
PREFIX_OPERATOR = ['-@']
- def self.translate(string, helper)
+ def self.translate(receiver, string)
if sexp = RubyParser.new.parse(string)
- self.new(helper).process(sexp)
+ self.new(receiver).process(sexp)
elsif string.size == 0
''
else
raise RubyLess::SyntaxError.new("Syntax error")
end
@@ -83,21 +83,19 @@
opts[:class] = true_res ? true_res.klass : false_res.klass
t "#{cond} ? #{true_res || 'nil'} : #{false_res || 'nil'}", opts
end
def process_call(exp)
- receiver_node_type = exp.first.nil? ? nil : exp.first.first
- receiver = process exp.shift
+ unless receiver = process(exp.shift)
+ receiver = @helper.kind_of?(TypedString) ? @helper : nil
+ end
- # receiver = t("(#{receiver})", receiver.klass) if
- # Ruby2Ruby::ASSIGN_NODES.include? receiver_node_type
-
method_call(receiver, exp)
end
def process_fcall(exp)
- method_call(nil, exp)
+ method_call(@helper.kind_of?(TypedString) ? @helper : nil, exp)
end
def process_arglist(exp)
code = t("")
until exp.empty? do
@@ -123,13 +121,14 @@
res.opts[:class] = Array
res.opts[:array_content_class] = content_class
t "[#{list * ','}]", res.opts.merge(:literal => nil)
end
+ # Is this used ?
def process_vcall(exp)
var_name = exp.shift
- unless opts = get_method([var_name], @helper, false)
+ unless opts = get_method(nil, [var_name])
raise RubyLess::Error.new("Unknown variable or method '#{var_name}'.")
end
method = opts[:method]
if args = opts[:prepend_args]
method = "#{method}(#{args.raw})"
@@ -326,10 +325,10 @@
end
def get_method(receiver, signature)
klass = receiver ? receiver.klass : @helper
- type = klass.respond_to?(:safe_method_type) ? klass.safe_method_type(signature) : SafeClass.safe_method_type_for(klass, signature)
+ type = klass.respond_to?(:safe_method_type) ? klass.safe_method_type(signature, receiver) : SafeClass.safe_method_type_for(klass, signature)
if type.nil?
# We try to match with the superclass of the arguments
end
raise RubyLess::NoMethodError.new(receiver, klass, signature) if !type || type[:class].kind_of?(Symbol) # we cannot send: no object.