Class: Steep::AST::Node::TypeApplication
- Defined in:
- lib/steep/ast/node/type_application.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(location) ⇒ TypeApplication
constructor
A new instance of TypeApplication.
- #line ⇒ Object
- #node ⇒ Object
- #set_node(node) ⇒ Object
- #source ⇒ Object
- #type_location ⇒ Object
- #type_str ⇒ Object
- #types(context, subtyping, type_vars) ⇒ Object
- #types?(context, subtyping, type_vars) ⇒ Boolean
Constructor Details
#initialize(location) ⇒ TypeApplication
Returns a new instance of TypeApplication.
7 8 9 |
# File 'lib/steep/ast/node/type_application.rb', line 7 def initialize(location) @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
5 6 7 |
# File 'lib/steep/ast/node/type_application.rb', line 5 def location @location end |
Class Method Details
.parse(location) ⇒ Object
80 81 82 83 84 |
# File 'lib/steep/ast/node/type_application.rb', line 80 def self.parse(location) if location.source =~/\A\$\s*(.+)/ TypeApplication.new(location) end end |
Instance Method Details
#line ⇒ Object
19 20 21 |
# File 'lib/steep/ast/node/type_application.rb', line 19 def line location.start_line end |
#node ⇒ Object
11 12 13 |
# File 'lib/steep/ast/node/type_application.rb', line 11 def node @node || raise end |
#set_node(node) ⇒ Object
15 16 17 |
# File 'lib/steep/ast/node/type_application.rb', line 15 def set_node(node) @node = node end |
#source ⇒ Object
23 24 25 |
# File 'lib/steep/ast/node/type_application.rb', line 23 def source location.source end |
#type_location ⇒ Object
75 76 77 78 |
# File 'lib/steep/ast/node/type_application.rb', line 75 def type_location offset = source.size - type_str.size RBS::Location.new(location.buffer, location.start_pos + offset, location.end_pos) end |
#type_str ⇒ Object
71 72 73 |
# File 'lib/steep/ast/node/type_application.rb', line 71 def type_str @type_str ||= source.delete_prefix("$").lstrip end |
#types(context, subtyping, type_vars) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/steep/ast/node/type_application.rb', line 27 def types(context, subtyping, type_vars) resolver = RBS::Resolver::TypeNameResolver.new(subtyping.factory.env) # @type var types: Array[LocatedValue[Types::t]] types = [] loc = type_location while true rbs_ty = RBS::Parser.parse_type(loc.buffer, range: loc.range, variables: type_vars) or break rbs_loc = rbs_ty.location or raise ty = rbs_ty.map_type_name {|name| resolver.resolve(name, context: context) || name.absolute! } validator = Signature::Validator.new(checker: subtyping) validator.rescue_validation_errors do validator.validate_type(ty) end if validator.has_error? return validator.each_error end ty = subtyping.factory.type(ty) types << LocatedValue.new(value: ty, location: rbs_loc) match = RBS::Location.new(loc.buffer, rbs_loc.end_pos, type_location.end_pos).source.match(/\A\s*,\s*/) or break offset = match.length loc = RBS::Location.new(loc.buffer, rbs_loc.end_pos + offset, type_location.end_pos) end types rescue ::RBS::ParsingError => exn exn end |
#types?(context, subtyping, type_vars) ⇒ Boolean
62 63 64 65 66 67 68 69 |
# File 'lib/steep/ast/node/type_application.rb', line 62 def types?(context, subtyping, type_vars) case types = types(context, subtyping, type_vars) when RBS::ParsingError, Enumerator nil else types end end |