Sha256: d08a9a4f0a6ea67614c42aeba2fd77f9c0d97980c1532ad334030b931f2f7b6d

Contents?: true

Size: 1.63 KB

Versions: 175

Compression:

Stored size: 1.63 KB

Contents

require 'set'
require 'sass/script/string'
require 'sass/script/number'
require 'sass/script/color'
require 'sass/script/functions'
require 'sass/script/unary_operation'

module Sass::Script
  # A SassScript parse node representing a binary operation,
  # such as `!a + !b` or `"foo" + 1`.
  class Operation < Node
    # @param operand1 [Script::Node] The parse-tree node
    #   for the right-hand side of the operator
    # @param operand2 [Script::Node] The parse-tree node
    #   for the left-hand side of the operator
    # @param operator [Symbol] The operator to perform.
    #   This should be one of the binary operator names in {Lexer::OPERATORS}
    def initialize(operand1, operand2, operator)
      @operand1 = operand1
      @operand2 = operand2
      @operator = operator
    end

    # @return [String] A human-readable s-expression representation of the operation
    def inspect
      "(#{@operator.inspect} #{@operand1.inspect} #{@operand2.inspect})"
    end

    # Evaluates the operation.
    #
    # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
    # @return [Literal] The SassScript object that is the value of the operation
    # @raise [Sass::SyntaxError] if the operation is undefined for the operands
    def perform(environment)
      literal1 = @operand1.perform(environment)
      literal2 = @operand2.perform(environment)
      begin
        literal1.send(@operator, literal2)
      rescue NoMethodError => e
        raise e unless e.name.to_s == @operator.to_s
        raise Sass::SyntaxError.new("Undefined operation: \"#{literal1} #{@operator} #{literal2}\".")
      end
    end
  end
end

Version data entries

175 entries across 174 versions & 7 rubygems

Version Path
radiantcms-couchrest_model-0.1.4 vendor/plugins/haml/lib/sass/script/operation.rb
radiant-0.9.1 vendor/plugins/haml/lib/sass/script/operation.rb
haml-2.2.24 lib/sass/script/operation.rb
radiant-0.9.0.rc2 vendor/plugins/haml/lib/sass/script/operation.rb
haml-2.2.23 lib/sass/script/operation.rb
haml-2.2.22 lib/sass/script/operation.rb
haml-2.2.21 lib/sass/script/operation.rb
drnic-haml-2.3.1 lib/sass/script/operation.rb
haml-2.2.20 lib/sass/script/operation.rb
haml-2.2.19 lib/sass/script/operation.rb
haml-2.2.18 lib/sass/script/operation.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/haml-2.2.17/lib/sass/script/operation.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/haml-2.2.17/lib/sass/script/operation.rb
haml-2.2.17 lib/sass/script/operation.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/haml-2.2.16/lib/sass/script/operation.rb
simple-templater-0.0.1.4 gems/gems/haml-2.2.16/lib/sass/script/operation.rb
haml-2.2.16 lib/sass/script/operation.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/haml-2.2.15/lib/sass/script/operation.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/haml-2.2.15/lib/sass/script/operation.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/haml-2.2.15/lib/sass/script/operation.rb