Sha256: 136b1e103bb595690f5020462b7cbcc4dc069e4e62231fed81a158c3e1d787f8

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module Steep
  module AST
    module Types
      class Literal
        attr_reader :location
        attr_reader :value

        def initialize(value:, location: nil)
          @location = location
          @value = value
        end

        def ==(other)
          other.is_a?(Literal) &&
            other.value == value
        end

        def hash
          self.class.hash
        end

        alias eql? ==

        def subst(s)
          self
        end

        def to_s
          value.inspect
        end

        def free_variables
          Set.new
        end

        def level
          [0]
        end

        def with_location(new_location)
          self.class.new(location: new_location)
        end

        def back_type
          case value
          when Integer
            Name.new_instance(name: "::Integer")
          when String
            Name.new_instance(name: "::String")
          when Symbol
            Name.new_instance(name: "::Symbol")
          else
            raise "Unexpected literal type: #{value.inspect}"
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
steep-0.5.1 lib/steep/ast/types/literal.rb
steep-0.5.0 lib/steep/ast/types/literal.rb
steep-0.4.0 lib/steep/ast/types/literal.rb