Class: RBI::RBS::TypeTranslator
- Inherits:
-
Object
- Object
- RBI::RBS::TypeTranslator
- Defined in:
- lib/rbi/rbs/type_translator.rb
Constant Summary collapse
- NodeType =
T.type_alias do T.any( ::RBS::Types::Alias, ::RBS::Types::Bases::Any, ::RBS::Types::Bases::Bool, ::RBS::Types::Bases::Bottom, ::RBS::Types::Bases::Class, ::RBS::Types::Bases::Instance, ::RBS::Types::Bases::Nil, ::RBS::Types::Bases::Self, ::RBS::Types::Bases::Top, ::RBS::Types::Bases::Void, ::RBS::Types::ClassSingleton, ::RBS::Types::ClassInstance, ::RBS::Types::Function, ::RBS::Types::Interface, ::RBS::Types::Intersection, ::RBS::Types::Literal, ::RBS::Types::Optional, ::RBS::Types::Proc, ::RBS::Types::Record, ::RBS::Types::Tuple, ::RBS::Types::Union, ::RBS::Types::UntypedFunction, ::RBS::Types::Variable, ) end
Class Method Summary collapse
-
.translate(type) ⇒ Object
: (NodeType) -> Type.
Class Method Details
.translate(type) ⇒ Object
: (NodeType) -> Type
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rbi/rbs/type_translator.rb', line 37 def translate(type) case type when ::RBS::Types::Alias # TODO: unsupported yet Type.untyped when ::RBS::Types::Bases::Any Type.untyped when ::RBS::Types::Bases::Bool Type.boolean when ::RBS::Types::Bases::Bottom Type.noreturn when ::RBS::Types::Bases::Class # TODO: unsupported yet Type.untyped when ::RBS::Types::Bases::Instance Type.attached_class when ::RBS::Types::Bases::Nil Type.simple("NilClass") when ::RBS::Types::Bases::Self Type.self_type when ::RBS::Types::Bases::Top Type.anything when ::RBS::Types::Bases::Void Type.void when ::RBS::Types::ClassSingleton Type.class_of(Type.simple(type.name.to_s)) when ::RBS::Types::ClassInstance translate_class_instance(type) when ::RBS::Types::Function translate_function(type) when ::RBS::Types::Interface # TODO: unsupported yet Type.untyped when ::RBS::Types::Intersection Type.all(*type.types.map { |t| translate(t) }) when ::RBS::Types::Literal # TODO: unsupported yet Type.untyped when ::RBS::Types::Optional Type.nilable(translate(type.type)) when ::RBS::Types::Proc proc = translate(type.type) #: as Type::Proc proc.bind(translate(type.self_type)) if type.self_type proc when ::RBS::Types::Record Type.shape(type.fields.map { |name, type| [name, translate(type)] }.to_h) when ::RBS::Types::Tuple Type.tuple(type.types.map { |t| translate(t) }) when ::RBS::Types::Union Type.any(*type.types.map { |t| translate(t) }) when ::RBS::Types::UntypedFunction Type.proc.params(arg0: Type.untyped).returns(Type.untyped) when ::RBS::Types::Variable Type.type_parameter(type.name) else T.absurd(type) end end |