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
- #each_rbs_type(context, subtyping, type_vars) ⇒ Object
-
#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
86 87 88 89 90 |
# File 'lib/steep/ast/node/type_application.rb', line 86 def self.parse(location) if location.source =~/\A\$\s*(.+)/ TypeApplication.new(location) end end |
Instance Method Details
#each_rbs_type(context, subtyping, type_vars) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/steep/ast/node/type_application.rb', line 59 def each_rbs_type(context, subtyping, type_vars) resolver = RBS::Resolver::TypeNameResolver.build(subtyping.factory.env) loc = type_location while true type = RBS::Parser.parse_type(loc.buffer, range: loc.range, variables: type_vars) or break type_loc = type.location or raise type = type.map_type_name {|name| resolver.resolve(name, context: context) || name.absolute! } yield type match = RBS::Location.new(loc.buffer, type_loc.end_pos, type_location.end_pos).source.match(/\A\s*,\s*/) or break offset = match.length loc = RBS::Location.new(loc.buffer, type_loc.end_pos + offset, type_location.end_pos) end end |
#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
81 82 83 84 |
# File 'lib/steep/ast/node/type_application.rb', line 81 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
77 78 79 |
# File 'lib/steep/ast/node/type_application.rb', line 77 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 |
# File 'lib/steep/ast/node/type_application.rb', line 27 def types(context, subtyping, type_vars) # @type var types: Array[LocatedValue[Types::t]] types = [] each_rbs_type(context, subtyping, type_vars) do |rbs_ty| validator = Signature::Validator.new(checker: subtyping) validator.rescue_validation_errors do validator.validate_type(rbs_ty) end if validator.has_error? return validator.each_error end ty = subtyping.factory.type(rbs_ty) types << LocatedValue.new(value: ty, location: rbs_ty.location || raise) end types rescue ::RBS::ParsingError => exn exn end |
#types?(context, subtyping, type_vars) ⇒ Boolean
50 51 52 53 54 55 56 57 |
# File 'lib/steep/ast/node/type_application.rb', line 50 def types?(context, subtyping, type_vars) case types = types(context, subtyping, type_vars) when RBS::ParsingError, Enumerator nil else types end end |