Sha256: 85c3599b227c9d51af266f35e3184baa5153d4dcd90551629c2cf7086fb11fb9

Contents?: true

Size: 948 Bytes

Versions: 17

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

module RubyNext
  module Language
    module Rewriters
      class NumericLiterals < Base
        using RubyNext

        NAME = "numeric-literals"
        SYNTAX_PROBE = "2i + 1/2r"
        MIN_SUPPORTED_VERSION = Gem::Version.new("2.1.0")

        def on_rational(node)
          context.track! self

          val = node.children.first

          parts = [s(:int, val.numerator)]

          parts << s(:int, val.denominator) unless val.denominator == 1

          s(:send, nil, :Rational, *parts).tap do |new_node|
            replace(node.loc.expression, new_node)
          end
        end

        def on_complex(node)
          context.track! self

          val = node.children.first

          s(:send, nil, :Complex,
            s(:int, val.real),
            s(:int, val.imaginary)).tap do |new_node|
            replace(node.loc.expression, new_node)
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ruby-next-core-1.1.0 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-1.0.3 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-1.0.2 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-1.0.1 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-1.0.0 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-1.0.0.rc.1 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-0.15.3 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-0.15.2 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-0.15.1 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-0.15.0 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-0.14.1 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-0.14.0 lib/ruby-next/language/rewriters/2.1/numeric_literals.rb
ruby-next-core-0.13.3 lib/ruby-next/language/rewriters/numeric_literals.rb
ruby-next-core-0.13.2 lib/ruby-next/language/rewriters/numeric_literals.rb
ruby-next-core-0.13.1 lib/ruby-next/language/rewriters/numeric_literals.rb
ruby-next-core-0.13.0 lib/ruby-next/language/rewriters/numeric_literals.rb
ruby-next-core-0.12.0 lib/ruby-next/language/rewriters/numeric_literals.rb