Sha256: de5b577846e6b7358eaa45370b6cc4fa52b2f26ff1d470fbcfb41e0063ac22bc

Contents?: true

Size: 925 Bytes

Versions: 7

Compression:

Stored size: 925 Bytes

Contents

module Ruby2JS
  class Converter

    # (and
    #   (...)
    #   (...))

    # (or
    #   (...)
    #   (...))

    # (not
    #   (...))

    handle :and, :or, :not do |left, right=nil|
      type = @ast.type
      op_index = operator_index type

      left = left.children.first if left and left.type == :begin
      lgroup   = LOGICAL.include?( left.type ) && 
        op_index <= operator_index( left.type )
      left     = parse left
      left     = "(#{ left })" if lgroup

      if right
        right = right.children.first if right.type == :begin
        rgroup = LOGICAL.include?( right.type ) && 
          op_index <= operator_index( right.type )
        right    = parse right
        right    = "(#{ right })" if rgroup
      end

      case type
      when :and
        "#{ left } && #{ right }"
      when :or
        "#{ left } || #{ right }"
      else
        "!#{ left }"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ruby2js-1.2.0 lib/ruby2js/converter/logical.rb
ruby2js-1.1.5 lib/ruby2js/converter/logical.rb
ruby2js-1.1.4 lib/ruby2js/converter/logical.rb
ruby2js-1.1.3 lib/ruby2js/converter/logical.rb
ruby2js-1.1.2 lib/ruby2js/converter/logical.rb
ruby2js-1.1.1 lib/ruby2js/converter/logical.rb
ruby2js-1.1.0 lib/ruby2js/converter/logical.rb