2006-12-22 10:28:17 +00:00
|
|
|
require 'sass/constant/string'
|
2006-12-23 21:23:27 +00:00
|
|
|
require 'sass/constant/number'
|
2006-12-23 21:51:44 +00:00
|
|
|
require 'sass/constant/color'
|
2008-06-05 22:06:48 +00:00
|
|
|
require 'sass/constant/functions'
|
2008-06-15 08:15:59 +00:00
|
|
|
require 'sass/constant/unary_operation'
|
2006-12-22 10:28:17 +00:00
|
|
|
|
2008-06-05 22:06:48 +00:00
|
|
|
module Sass::Constant
|
2007-03-01 05:52:47 +00:00
|
|
|
class Operation # :nodoc:
|
2007-01-28 17:24:08 +00:00
|
|
|
def initialize(operand1, operand2, operator)
|
2006-12-23 22:32:05 +00:00
|
|
|
@operand1 = operand1
|
|
|
|
@operand2 = operand2
|
|
|
|
@operator = operator
|
2006-12-22 10:28:17 +00:00
|
|
|
end
|
2008-04-08 06:09:17 +00:00
|
|
|
|
2006-12-23 22:32:05 +00:00
|
|
|
def to_s
|
|
|
|
self.perform.to_s
|
2006-12-22 10:28:17 +00:00
|
|
|
end
|
2008-04-08 06:09:17 +00:00
|
|
|
|
2008-06-01 22:10:02 +00:00
|
|
|
def inspect
|
|
|
|
"(#{@operator.inspect} #{@operand1.inspect} #{@operand2.inspect})"
|
|
|
|
end
|
|
|
|
|
2008-06-05 22:06:48 +00:00
|
|
|
def to_arglist
|
|
|
|
return [self] unless @operator == :comma
|
|
|
|
@operand1.to_arglist + @operand2.to_arglist
|
|
|
|
end
|
|
|
|
|
2006-12-23 03:06:52 +00:00
|
|
|
def perform
|
2006-12-23 22:32:05 +00:00
|
|
|
literal1 = @operand1.perform
|
2008-06-05 22:06:48 +00:00
|
|
|
if @operator == :funcall && Functions.public_instance_methods.include?(literal1.to_s) && literal1.to_s !~ /^__/
|
|
|
|
begin
|
|
|
|
return Functions.send(literal1.to_s, *@operand2.to_arglist)
|
|
|
|
rescue ArgumentError => e
|
|
|
|
raise e unless e.backtrace.first =~ /:in `#{literal1.to_s}'$/
|
|
|
|
raise Sass::SyntaxError.new("#{e.message} for `#{literal1.to_s}'")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-12-23 22:32:05 +00:00
|
|
|
literal2 = @operand2.perform
|
|
|
|
begin
|
|
|
|
literal1.send(@operator, literal2)
|
2006-12-23 22:57:31 +00:00
|
|
|
rescue NoMethodError => e
|
2007-02-10 02:55:55 +00:00
|
|
|
raise e unless e.name.to_s == @operator.to_s
|
2008-04-19 17:16:10 +00:00
|
|
|
raise Sass::SyntaxError.new("Undefined operation: \"#{literal1} #{@operator} #{literal2}\".")
|
2006-12-23 22:32:05 +00:00
|
|
|
end
|
2006-12-22 10:28:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|