module RBS module Types # _TypeBase interface represents the operations common to all of the types. # interface _TypeBase # Location for types in the RBS source code. # `nil` means there is no RBS source code for the type. # def location: () -> Location? # Returns names of free variables of a type. # You can pass a Set instance to add the free variables to the set to avoid Set object allocation. # def free_variables: (?Set[Symbol]) -> Set[Symbol] # Receives a substitution and returns a new type applied the substitution. # def sub: (Substitution) -> t # Maps type names included in the type and returns new instance of type. def map_type_name: () { (TypeName, Location?, t) -> TypeName } -> t # Yields all direct sub types included in the type. # It doesn't yield the type itself. # # parse("Hash[String, Array[Symbol]]").each_type do |ty| # ... # Yields String and Array[Symbol] # end # def each_type: () { (t) -> void } -> void | () -> Enumerator[t, void] # Returns a JSON representation. # def to_json: (*untyped) -> String # Returns a String representation. # `level` is used internally. # # parse("String").to_s # => "String" # parse("String | Integer").to_s() # => "String | Integer" # parse("String | Integer").to_s(1) # => "(String | Integer)" # def to_s: (?Integer level) -> String end # t represents union of all possible types. # type t = Bases::Bool | Bases::Void | Bases::Any | Bases::Nil | Bases::Top | Bases::Bottom | Bases::Self | Bases::Instance | Bases::Class | Variable | ClassSingleton | Interface | ClassInstance | Alias | Tuple | Record | Optional | Union | Intersection | Proc | Literal module NoFreeVariables def free_variables: (?Set[Symbol]) -> Set[Symbol] end module NoSubst def sub: (Substitution) -> self end module EmptyEachType def each_type: () { (t) -> void } -> void | () -> Enumerator[t, void] end module NoTypeName def map_type_name: () { (TypeName, Location?, t) -> TypeName } -> self end module Bases class Base include _TypeBase def initialize: (location: Location?) -> void def ==: (untyped other) -> bool def hash: () -> Integer alias eql? == include NoFreeVariables include NoSubst include EmptyEachType include NoTypeName end class Bool < Base end class Void < Base end class Any < Base end class Nil < Base end class Top < Base end class Bottom < Base end class Self < Base end class Instance < Base def sub: (Substitution sub) -> t end class Class < Base end end class Variable attr_reader name: Symbol attr_reader location: Location? @@count: Integer include _TypeBase include NoTypeName include EmptyEachType def initialize: (name: Symbol, location: Location?) -> void def ==: (untyped other) -> bool alias eql? == def hash: () -> Integer def self.build: (Symbol) -> Variable | (Array[Symbol]) -> Array[Variable] def self.fresh: (?Symbol) -> Variable end class ClassSingleton attr_reader name: TypeName attr_reader location: Location? include _TypeBase def initialize: (name: TypeName, location: Location?) -> void def ==: (untyped other) -> bool alias eql? == def hash: () -> Integer include NoFreeVariables include NoSubst include EmptyEachType end module Application attr_reader name: TypeName attr_reader args: Array[t] def ==: (untyped) -> bool alias eql? == def hash: () -> Integer def free_variables: (?Set[Symbol]) -> Set[Symbol] def to_s: (?Integer level) -> String def each_type: () { (t) -> void } -> void | () -> Enumerator[t, void] end class Interface include Application attr_reader location: Location? def initialize: (name: TypeName, args: Array[t], location: Location?) -> void include _TypeBase end # ClassInstance represents a type of an instance of a class. # # String # Type of an instance of String class. # Array[String] # Type of an instance of Array class with instances of String. # Kernel # Type of an instance of a class which includes Kernel. # class ClassInstance include Application attr_reader location: Location? def initialize: (name: TypeName, args: Array[t], location: Location?) -> void include _TypeBase end class Alias attr_reader location: Location? attr_reader name: TypeName def initialize: (name: TypeName, location: Location?) -> void include _TypeBase include NoFreeVariables include NoSubst include EmptyEachType end class Tuple attr_reader types: Array[t] attr_reader location: Location? def initialize: (types: Array[t], location: Location?) -> void include _TypeBase end class Record attr_reader fields: Hash[Symbol, t] attr_reader location: Location? def initialize: (fields: Hash[Symbol, t], location: Location?) -> void include _TypeBase end class Optional attr_reader type: t attr_reader location: Location? def initialize: (type: t, location: Location?) -> void include _TypeBase end class Union attr_reader types: Array[t] attr_reader location: Location? def initialize: (types: Array[t], location: Location?) -> void include _TypeBase def map_type: () { (t) -> t } -> Union | () -> Enumerator[t, Union] end class Intersection attr_reader types: Array[t] attr_reader location: Location? def initialize: (types: Array[t], location: Location?) -> void include _TypeBase def map_type: () { (t) -> t } -> Intersection | () -> Enumerator[t, Intersection] end class Function class Param attr_reader type: t attr_reader name: Symbol? def initialize: (type: t, name: Symbol?) -> void def map_type: { (t) -> t } -> Param | -> Enumerator[t, Param] end attr_reader required_positionals: Array[Param] attr_reader optional_positionals: Array[Param] attr_reader rest_positionals: Param? attr_reader trailing_positionals: Array[Param] attr_reader required_keywords: Hash[Symbol, Param] attr_reader optional_keywords: Hash[Symbol, Param] attr_reader rest_keywords: Param? attr_reader return_type: t def initialize: (required_positionals: Array[Param], optional_positionals: Array[Param], rest_positionals: Param?, trailing_positionals: Array[Param], required_keywords: Hash[Symbol, Param], optional_keywords: Hash[Symbol, Param], rest_keywords: Param?, return_type: t) -> void def free_variables: (?Set[Symbol]) -> Set[Symbol] def map_type: { (t) -> t } -> Function | -> Enumerator[t, Function] def map_type_name: () { (TypeName, Location?, t) -> TypeName } -> Function def each_type: () { (t) -> void } -> void | -> Enumerator[t, void] def each_param: () { (Param) -> void } -> void | -> Enumerator[Param, void] def to_json: (*untyped) -> String def sub: (Substitution) -> Function def self.empty: (t) -> instance def with_return_type: (t) -> Function def update: (?required_positionals: Array[Param], ?optional_positionals: Array[Param], ?rest_positionals: Param?, ?trailing_positionals: Array[Param], ?required_keywords: Hash[Symbol, Param], ?optional_keywords: Hash[Symbol, Param], ?rest_keywords: Param?, ?return_type: t) -> Function def empty?: () -> bool def param_to_s: () -> String def return_to_s: () -> String def drop_head: () -> [Param, Function] def drop_tail: () -> [Param, Function] def has_keyword?: () -> bool end class Proc attr_reader type: Function attr_reader location: Location? def initialize: (location: Location?, type: Function) -> void include _TypeBase end class Literal type literal = String | Integer | Symbol | TrueClass | FalseClass attr_reader literal: literal attr_reader location: Location? def initialize: (literal: literal, location: Location?) -> void include _TypeBase include NoFreeVariables include NoSubst include EmptyEachType include NoTypeName end end end