rbs 3.10.0 → 4.0.0.dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +24 -35
  4. data/.github/workflows/typecheck.yml +3 -1
  5. data/.github/workflows/windows.yml +2 -2
  6. data/.gitignore +0 -4
  7. data/CHANGELOG.md +0 -88
  8. data/README.md +1 -38
  9. data/Rakefile +20 -142
  10. data/Steepfile +1 -0
  11. data/config.yml +43 -1
  12. data/core/array.rbs +46 -100
  13. data/core/complex.rbs +21 -32
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +9 -6
  16. data/core/enumerable.rbs +3 -90
  17. data/core/enumerator.rbs +1 -18
  18. data/core/errno.rbs +0 -8
  19. data/core/errors.rbs +1 -28
  20. data/core/exception.rbs +2 -2
  21. data/core/fiber.rbs +4 -5
  22. data/core/file.rbs +12 -27
  23. data/core/file_test.rbs +1 -1
  24. data/core/float.rbs +22 -209
  25. data/core/gc.rbs +281 -417
  26. data/core/hash.rbs +727 -1024
  27. data/core/integer.rbs +38 -78
  28. data/core/io/buffer.rbs +7 -18
  29. data/core/io/wait.rbs +33 -11
  30. data/core/io.rbs +12 -14
  31. data/core/kernel.rbs +51 -57
  32. data/core/marshal.rbs +1 -1
  33. data/core/match_data.rbs +1 -1
  34. data/core/math.rbs +3 -42
  35. data/core/method.rbs +6 -14
  36. data/core/module.rbs +17 -88
  37. data/core/nil_class.rbs +3 -3
  38. data/core/numeric.rbs +16 -16
  39. data/core/object.rbs +3 -3
  40. data/core/object_space.rbs +15 -21
  41. data/core/proc.rbs +8 -15
  42. data/core/process.rbs +2 -2
  43. data/core/ractor.rbs +437 -278
  44. data/core/range.rbs +8 -7
  45. data/core/rational.rbs +24 -37
  46. data/core/rbs/unnamed/argf.rbs +2 -2
  47. data/core/rbs/unnamed/env_class.rbs +1 -1
  48. data/core/rbs/unnamed/random.rbs +2 -4
  49. data/core/regexp.rbs +20 -25
  50. data/core/ruby_vm.rbs +4 -6
  51. data/core/rubygems/errors.rbs +70 -3
  52. data/core/rubygems/rubygems.rbs +79 -11
  53. data/core/rubygems/version.rbs +3 -2
  54. data/core/set.rbs +359 -488
  55. data/core/string.rbs +1228 -3153
  56. data/core/struct.rbs +1 -1
  57. data/core/symbol.rbs +4 -4
  58. data/core/thread.rbs +29 -92
  59. data/core/time.rbs +9 -35
  60. data/core/trace_point.rbs +4 -7
  61. data/core/unbound_method.rbs +6 -14
  62. data/docs/collection.md +2 -2
  63. data/docs/gem.md +1 -0
  64. data/docs/sigs.md +3 -3
  65. data/ext/rbs_extension/ast_translation.c +1077 -944
  66. data/ext/rbs_extension/ast_translation.h +0 -7
  67. data/ext/rbs_extension/class_constants.c +83 -71
  68. data/ext/rbs_extension/class_constants.h +7 -4
  69. data/ext/rbs_extension/extconf.rb +2 -24
  70. data/ext/rbs_extension/legacy_location.c +172 -173
  71. data/ext/rbs_extension/legacy_location.h +3 -8
  72. data/ext/rbs_extension/main.c +289 -239
  73. data/ext/rbs_extension/rbs_extension.h +0 -3
  74. data/ext/rbs_extension/rbs_string_bridging.h +0 -4
  75. data/include/rbs/ast.h +98 -37
  76. data/include/rbs/defines.h +12 -38
  77. data/include/rbs/lexer.h +114 -126
  78. data/include/rbs/location.h +14 -14
  79. data/include/rbs/parser.h +37 -21
  80. data/include/rbs/string.h +5 -3
  81. data/include/rbs/util/rbs_allocator.h +19 -40
  82. data/include/rbs/util/rbs_assert.h +1 -12
  83. data/include/rbs/util/rbs_constant_pool.h +3 -3
  84. data/include/rbs/util/rbs_encoding.h +1 -3
  85. data/include/rbs/util/rbs_unescape.h +1 -2
  86. data/lib/rbs/ast/ruby/annotations.rb +119 -0
  87. data/lib/rbs/ast/ruby/comment_block.rb +221 -0
  88. data/lib/rbs/ast/ruby/declarations.rb +86 -0
  89. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
  90. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  91. data/lib/rbs/ast/ruby/members.rb +213 -0
  92. data/lib/rbs/buffer.rb +104 -24
  93. data/lib/rbs/cli/validate.rb +40 -35
  94. data/lib/rbs/cli.rb +5 -6
  95. data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
  96. data/lib/rbs/collection.rb +0 -1
  97. data/lib/rbs/definition.rb +6 -1
  98. data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
  99. data/lib/rbs/definition_builder/method_builder.rb +45 -30
  100. data/lib/rbs/definition_builder.rb +44 -9
  101. data/lib/rbs/environment/class_entry.rb +69 -0
  102. data/lib/rbs/environment/module_entry.rb +66 -0
  103. data/lib/rbs/environment.rb +244 -218
  104. data/lib/rbs/environment_loader.rb +3 -3
  105. data/lib/rbs/errors.rb +5 -4
  106. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  107. data/lib/rbs/inline_parser.rb +206 -0
  108. data/lib/rbs/location_aux.rb +35 -3
  109. data/lib/rbs/parser_aux.rb +11 -6
  110. data/lib/rbs/prototype/runtime.rb +2 -2
  111. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  112. data/lib/rbs/resolver/type_name_resolver.rb +38 -124
  113. data/lib/rbs/source.rb +99 -0
  114. data/lib/rbs/subtractor.rb +4 -3
  115. data/lib/rbs/test/type_check.rb +0 -14
  116. data/lib/rbs/types.rb +1 -3
  117. data/lib/rbs/version.rb +1 -1
  118. data/lib/rbs.rb +13 -1
  119. data/lib/rdoc/discover.rb +1 -1
  120. data/lib/rdoc_plugin/parser.rb +1 -1
  121. data/rbs.gemspec +1 -0
  122. data/sig/ancestor_builder.rbs +1 -1
  123. data/sig/ast/ruby/annotations.rbs +110 -0
  124. data/sig/ast/ruby/comment_block.rbs +119 -0
  125. data/sig/ast/ruby/declarations.rbs +60 -0
  126. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  127. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  128. data/sig/ast/ruby/members.rbs +72 -0
  129. data/sig/buffer.rbs +63 -5
  130. data/sig/definition.rbs +1 -0
  131. data/sig/definition_builder.rbs +1 -1
  132. data/sig/environment/class_entry.rbs +50 -0
  133. data/sig/environment/module_entry.rbs +50 -0
  134. data/sig/environment.rbs +28 -133
  135. data/sig/errors.rbs +13 -6
  136. data/sig/inline_parser/comment_association.rbs +71 -0
  137. data/sig/inline_parser.rbs +87 -0
  138. data/sig/location.rbs +32 -7
  139. data/sig/manifest.yaml +1 -0
  140. data/sig/method_builder.rbs +7 -4
  141. data/sig/parser.rbs +16 -20
  142. data/sig/resolver/type_name_resolver.rbs +7 -38
  143. data/sig/source.rbs +48 -0
  144. data/sig/types.rbs +1 -4
  145. data/src/ast.c +290 -201
  146. data/src/lexer.c +2813 -2902
  147. data/src/lexer.re +4 -0
  148. data/src/lexstate.c +155 -169
  149. data/src/location.c +40 -40
  150. data/src/parser.c +2665 -2433
  151. data/src/string.c +48 -0
  152. data/src/util/rbs_allocator.c +77 -80
  153. data/src/util/rbs_assert.c +10 -10
  154. data/src/util/rbs_buffer.c +2 -2
  155. data/src/util/rbs_constant_pool.c +15 -13
  156. data/src/util/rbs_encoding.c +4062 -20097
  157. data/src/util/rbs_unescape.c +48 -85
  158. data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
  159. data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
  160. data/stdlib/cgi/0/core.rbs +396 -2
  161. data/stdlib/cgi/0/manifest.yaml +0 -1
  162. data/stdlib/coverage/0/coverage.rbs +1 -3
  163. data/stdlib/date/0/date.rbs +59 -67
  164. data/stdlib/date/0/date_time.rbs +1 -1
  165. data/stdlib/delegate/0/delegator.rbs +7 -10
  166. data/stdlib/erb/0/erb.rbs +347 -737
  167. data/stdlib/fileutils/0/fileutils.rbs +13 -18
  168. data/stdlib/forwardable/0/forwardable.rbs +0 -3
  169. data/stdlib/json/0/json.rbs +48 -68
  170. data/stdlib/net-http/0/net-http.rbs +0 -3
  171. data/stdlib/objspace/0/objspace.rbs +4 -9
  172. data/stdlib/open-uri/0/open-uri.rbs +0 -40
  173. data/stdlib/openssl/0/openssl.rbs +228 -331
  174. data/stdlib/optparse/0/optparse.rbs +3 -3
  175. data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
  176. data/stdlib/psych/0/psych.rbs +3 -3
  177. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  178. data/stdlib/resolv/0/resolv.rbs +68 -25
  179. data/stdlib/ripper/0/ripper.rbs +2 -5
  180. data/stdlib/singleton/0/singleton.rbs +0 -3
  181. data/stdlib/socket/0/socket.rbs +1 -13
  182. data/stdlib/socket/0/tcp_socket.rbs +2 -10
  183. data/stdlib/stringio/0/stringio.rbs +85 -1176
  184. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  185. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  186. data/stdlib/time/0/time.rbs +1 -1
  187. data/stdlib/timeout/0/timeout.rbs +7 -63
  188. data/stdlib/tsort/0/cyclic.rbs +0 -3
  189. data/stdlib/uri/0/common.rbs +2 -11
  190. data/stdlib/uri/0/file.rbs +1 -1
  191. data/stdlib/uri/0/generic.rbs +16 -17
  192. data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
  193. data/stdlib/zlib/0/zstream.rbs +0 -1
  194. metadata +40 -12
  195. data/.clang-format +0 -74
  196. data/.clangd +0 -2
  197. data/.github/workflows/c-check.yml +0 -54
  198. data/core/ruby.rbs +0 -53
  199. data/docs/aliases.md +0 -79
  200. data/docs/encoding.md +0 -56
  201. data/ext/rbs_extension/compat.h +0 -10
  202. data/stdlib/cgi-escape/0/escape.rbs +0 -153
@@ -0,0 +1,71 @@
1
+ use RBS::AST::Ruby::CommentBlock
2
+
3
+ module RBS
4
+ class InlineParser
5
+ # CommentAssociation manages the association between `Prism::Node` and `CommentBlock`
6
+ #
7
+ class CommentAssociation
8
+ attr_reader blocks: Array[CommentBlock]
9
+
10
+ attr_reader start_line_map: Hash[Integer, CommentBlock]
11
+
12
+ attr_reader end_line_map: Hash[Integer, CommentBlock]
13
+
14
+ # CommentBlocks that are already associated to a node, which cannot be associated to another node again
15
+ #
16
+ attr_reader associated_blocks: Set[CommentBlock]
17
+
18
+ def self.build: (Buffer, Prism::Result) -> instance
19
+
20
+ def initialize: (Array[CommentBlock]) -> void
21
+
22
+ class Reference
23
+ attr_reader block: CommentBlock
24
+
25
+ @associated_blocks: Set[CommentBlock]
26
+
27
+ def initialize: (CommentBlock, Set[CommentBlock]) -> void
28
+
29
+ def associate!: () -> self
30
+
31
+ def associated?: () -> bool
32
+ end
33
+
34
+ # Returns an unassociated CommentBlock that can be associated to given node
35
+ #
36
+ # Automatically updates association status.
37
+ #
38
+ def leading_block!: (Prism::Node) -> CommentBlock?
39
+
40
+ # Returns a Reference that is associated to given node
41
+ #
42
+ # Updates association explicitly through the reference.
43
+ #
44
+ def leading_block: (Prism::Node) -> Reference?
45
+
46
+ # Returns a CommentBlock that is associated to given node, or by its location
47
+ #
48
+ # Update association status.
49
+ #
50
+ def trailing_block!: (Prism::Node | Prism::Location) -> CommentBlock?
51
+
52
+ # Returns a Reference that is associated to given node, or by its location
53
+ #
54
+ # Updates association explicitly through the reference.
55
+ #
56
+ def trailing_block: (Prism::Node | Prism::Location) -> Reference?
57
+
58
+ # Yields leading CommentBlocks that is enclosed in the given node
59
+ #
60
+ # Note that `enclosed_blocks` works only after all of the *leading* blocks inside the node is associated.
61
+ #
62
+ # Update association status.
63
+ #
64
+ def each_enclosed_block: (Prism::Node) { (CommentBlock) -> void } -> void
65
+ | (Prism::Node) -> Enumerator[CommentBlock]
66
+
67
+ def each_unassociated_block: () { (CommentBlock) -> void } -> void
68
+ | () -> Enumerator[CommentBlock]
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,87 @@
1
+ use RBS::AST::Ruby::Declarations
2
+
3
+ module RBS
4
+ class InlineParser
5
+ class Result
6
+ attr_reader buffer: Buffer
7
+ attr_reader prism_result: Prism::ParseResult
8
+ attr_reader declarations: Array[AST::Ruby::Declarations::t]
9
+ attr_reader diagnostics: Array[Diagnostic::t]
10
+
11
+ def initialize: (Buffer, Prism::ParseResult) -> void
12
+ end
13
+
14
+ module Diagnostic
15
+ class Base
16
+ attr_reader message: String
17
+
18
+ attr_reader location: Location
19
+
20
+ def initialize: (Location, String) -> void
21
+ end
22
+
23
+ class NotImplementedYet < Base
24
+ end
25
+
26
+ class NonConstantClassName < Base
27
+ end
28
+
29
+ class NonConstantModuleName < Base
30
+ end
31
+
32
+ class TopLevelMethodDefinition < Base
33
+ end
34
+
35
+ class UnusedInlineAnnotation < Base
36
+ end
37
+
38
+ class AnnotationSyntaxError < Base
39
+ end
40
+
41
+ type t = NotImplementedYet
42
+ | NonConstantClassName | NonConstantModuleName
43
+ | TopLevelMethodDefinition
44
+ | UnusedInlineAnnotation | AnnotationSyntaxError
45
+ end
46
+
47
+ def self.parse: (Buffer, Prism::ParseResult) -> Result
48
+
49
+ class Parser < Prism::Visitor
50
+ type module_context = Declarations::ClassDecl | Declarations::ModuleDecl
51
+
52
+ include AST::Ruby::Helpers::ConstantHelper
53
+
54
+ include AST::Ruby::Helpers::LocationHelper
55
+
56
+ attr_reader comments: CommentAssociation
57
+
58
+ attr_reader result: Result
59
+
60
+ attr_reader module_nesting: Array[module_context]
61
+
62
+ def initialize: (Result) -> void
63
+
64
+ def buffer: () -> Buffer
65
+
66
+ %a{pure} def current_module: () -> module_context?
67
+
68
+ %a{pure} def current_module!: () -> module_context
69
+
70
+ def diagnostics: () -> Array[Diagnostic::t]
71
+
72
+ def push_module_nesting: [T] (module_context) { () -> T } -> T
73
+
74
+ # Returns `true` if the node is a comment block including `@rbs skip` annotation
75
+ #
76
+ # Doesn't update the `association` flag if returning `false`.
77
+ #
78
+ def skip_node?: (Prism::Node) -> bool
79
+
80
+ def insert_declaration: (module_context) -> void
81
+
82
+ def report_unused_annotation: (*AST::Ruby::Annotations::t | nil | AST::Ruby::CommentBlock::AnnotationSyntaxError) -> void
83
+
84
+ def report_unused_block: (AST::Ruby::CommentBlock) -> void
85
+ end
86
+ end
87
+ end
data/sig/location.rbs CHANGED
@@ -4,14 +4,20 @@ module RBS
4
4
  #
5
5
  # A location can have _child_ locations.
6
6
  #
7
- class Location[in RequiredChildKeys, in OptionalChildKeys]
7
+ class Location[in RequiredChildKeys = untyped, in OptionalChildKeys = untyped]
8
8
  # The buffer this location points on.
9
9
  attr_reader buffer (): Buffer
10
10
 
11
- # The index of character the range starts from.
11
+ # The absolute start index of character the range starts from
12
+ #
13
+ # It returns the index in the `buffer.top_buffer`.
14
+ #
12
15
  attr_reader start_pos (): Integer
13
16
 
14
- # The index of character the range ends at.
17
+ # The absolute end index of character the range ends at
18
+ #
19
+ # It returns the index in the `buffer.top_buffer`.
20
+ #
15
21
  attr_reader end_pos (): Integer
16
22
 
17
23
  def initialize: (Buffer, Integer start_pos, Integer end_pos) -> void
@@ -24,26 +30,37 @@ module RBS
24
30
  # Returns the name of the buffer.
25
31
  def name: () -> untyped
26
32
 
27
- # Line of the `start_pos` (1 origin)
33
+ # The *raw* index of character the range starts from.
34
+ attr_reader _start_pos (): Integer
35
+
36
+ # The *raw* index of character the range ends at.
37
+ attr_reader _end_pos (): Integer
38
+
39
+ # Line of the `start_pos` (1 origin, absolute)
28
40
  attr_reader start_line (): Integer
29
41
 
30
- # Column of the `start_pos` (0 origin)
42
+ # Column of the `start_pos` (0 origin, absolute)
31
43
  attr_reader start_column (): Integer
32
44
 
33
- # Line of the `end_pos` (1 origin)
45
+ # Line of the `end_pos` (1 origin, absolute)
34
46
  attr_reader end_line (): Integer
35
47
 
36
- # Column of the `end_pos` (0 origin)
48
+ # Column of the `end_pos` (0 origin, absolute)
37
49
  attr_reader end_column (): Integer
38
50
 
51
+ # The absolute line-column pair of the start position
52
+ #
39
53
  attr_reader start_loc (): Buffer::loc
40
54
 
41
55
  @start_loc: Buffer::loc?
42
56
 
57
+ # The absolute line-column pair of the end position
58
+ #
43
59
  attr_reader end_loc (): Buffer::loc
44
60
 
45
61
  @end_loc: Buffer::loc?
46
62
 
63
+ # The absolute range of the start and end position
47
64
  attr_reader range (): Range[Integer]
48
65
 
49
66
  @range: Range[Integer]?
@@ -97,6 +114,14 @@ module RBS
97
114
 
98
115
  def key?: (Symbol) -> bool
99
116
 
117
+ # Returns the location of the buffer, but the buffer is detached from the parent buffer
118
+ #
119
+ def local_location: () -> self
120
+
121
+ # Returns the source of `#local_location`
122
+ #
123
+ def local_source: () -> String
124
+
100
125
  private
101
126
 
102
127
  def _add_required_child: (RequiredChildKeys name, Integer start_pos, Integer end_pos) -> void
data/sig/manifest.yaml CHANGED
@@ -1,5 +1,6 @@
1
1
  dependencies:
2
2
  - name: logger
3
+ - name: pathname
3
4
  - name: json
4
5
  - name: optparse
5
6
  - name: tsort
@@ -16,16 +16,19 @@ module RBS
16
16
  #
17
17
  class Definition
18
18
  type original = AST::Members::MethodDefinition | AST::Members::Alias | AST::Members::AttrAccessor | AST::Members::AttrWriter | AST::Members::AttrReader
19
+ | AST::Ruby::Members::DefMember
20
+
21
+ type overloading_definition = AST::Members::MethodDefinition | AST::Ruby::Members::DefMember
19
22
 
20
23
  type accessibility = RBS::Definition::accessibility
21
24
 
22
25
  attr_reader name: Symbol
23
26
  attr_reader type: instance_type
24
27
  attr_reader originals: Array[original]
25
- attr_reader overloads: Array[AST::Members::MethodDefinition]
28
+ attr_reader overloads: Array[overloading_definition]
26
29
  attr_reader accessibilities: Array[accessibility]
27
30
 
28
- def initialize: (name: Symbol, type: instance_type, originals: Array[original], overloads: Array[AST::Members::MethodDefinition], accessibilities: Array[accessibility]) -> void
31
+ def initialize: (name: Symbol, type: instance_type, originals: Array[original], overloads: Array[overloading_definition], accessibilities: Array[accessibility]) -> void
29
32
 
30
33
  def original: () -> original?
31
34
 
@@ -74,9 +77,9 @@ module RBS
74
77
 
75
78
  def build_attribute: (Methods, Methods::instance_type, member: AST::Members::AttrAccessor | AST::Members::AttrReader | AST::Members::AttrWriter, accessibility: Definition::accessibility) -> void
76
79
 
77
- def build_method: (Methods, Methods::instance_type, member: AST::Members::MethodDefinition, accessibility: Definition::accessibility) -> void
80
+ def build_method: (Methods, Methods::instance_type, member: AST::Members::MethodDefinition | AST::Ruby::Members::DefMember, accessibility: Definition::accessibility) -> void
78
81
 
79
- def each_member_with_accessibility: (Array[AST::Members::t | AST::Declarations::t], ?accessibility: Definition::accessibility) { (AST::Members::t | AST::Declarations::t, Definition::accessibility) -> void } -> void
82
+ def each_rbs_member_with_accessibility: (Array[AST::Members::t | AST::Declarations::t], ?accessibility: Definition::accessibility) { (AST::Members::t | AST::Declarations::t, Definition::accessibility) -> void } -> void
80
83
 
81
84
  def update: (env: Environment, except: _Each[TypeName]) -> MethodBuilder
82
85
  end
data/sig/parser.rbs CHANGED
@@ -68,24 +68,6 @@ module RBS
68
68
  #
69
69
  def self.parse_signature: (Buffer | String) -> [Buffer, Array[AST::Directives::t], Array[AST::Declarations::t]]
70
70
 
71
- # Parse a list of type parameters and return it
72
- #
73
- # ```ruby
74
- # RBS::Parser.parse_type_params("") # => nil
75
- # RBS::Parser.parse_type_params("[U, V]") # => `[:U, :V]`
76
- # RBS::Parser.parse_type_params("[in U, V < Integer]") # => `[:U, :V]`
77
- # ```
78
- #
79
- # When `module_type_params` is `false`, an error is raised if `unchecked`, `in` or `out` are used.
80
- #
81
- # ```ruby
82
- # RBS::Parser.parse_type_params("[unchecked U]", module_type_params: false) # => Raises an error
83
- # RBS::Parser.parse_type_params("[out U]", module_type_params: false) # => Raises an error
84
- # RBS::Parser.parse_type_params("[in U]", module_type_params: false) # => Raises an error
85
- # ```
86
- #
87
- def self.parse_type_params: (Buffer | String, ?module_type_params: bool) -> Array[AST::TypeParam]
88
-
89
71
  # Returns the magic comment from the buffer
90
72
  #
91
73
  def self.magic_comment: (Buffer) -> AST::Directives::ResolveTypeNames?
@@ -100,6 +82,18 @@ module RBS
100
82
 
101
83
  KEYWORDS: Hash[String, bot]
102
84
 
85
+ # Parse a leading annotation and return it
86
+ #
87
+ # Raises an exception if the source text contains a syntax error.
88
+ #
89
+ def self.parse_inline_leading_annotation: (Buffer | String, Range[Integer?], ?variables: Array[Symbol]) -> AST::Ruby::Annotations::leading_annotation
90
+
91
+ # Parse a leading annotation and return it
92
+ #
93
+ # Raises an exception if the source text contains a syntax error.
94
+ #
95
+ def self.parse_inline_trailing_annotation: (Buffer | String, Range[Integer?], ?variables: Array[Symbol]) -> AST::Ruby::Annotations::trailing_annotation
96
+
103
97
  private
104
98
 
105
99
  def self.buffer: (String | Buffer source) -> Buffer
@@ -110,10 +104,12 @@ module RBS
110
104
 
111
105
  def self._parse_signature: (Buffer, Integer start_pos, Integer end_pos) -> [Array[AST::Directives::t], Array[AST::Declarations::t]]
112
106
 
113
- def self._parse_type_params: (Buffer, Integer start_pos, Integer end_pos, bool module_type_params) -> Array[AST::TypeParam]
114
-
115
107
  def self._lex: (Buffer, Integer end_pos) -> Array[[Symbol, Location[untyped, untyped]]]
116
108
 
109
+ def self._parse_inline_leading_annotation: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> AST::Ruby::Annotations::leading_annotation
110
+
111
+ def self._parse_inline_trailing_annotation: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables) -> AST::Ruby::Annotations::trailing_annotation
112
+
117
113
  class LocatedValue
118
114
  end
119
115
  end
@@ -8,59 +8,28 @@ module RBS
8
8
  class TypeNameResolver
9
9
  type query = [TypeName, context]
10
10
 
11
- def initialize: (Set[TypeName] all_names, Hash[TypeName, [TypeName, context]] aliases) -> void
11
+ def initialize: (Environment) -> void
12
12
 
13
- def self.new: %a{deprecated: Use `build` to build TypeNameResolver from Environment} (Environment) -> instance
14
- | (Set[TypeName] all_names, Hash[TypeName, [TypeName, context]] aliases) -> instance
15
-
16
- def self.build: (Environment) -> instance
17
-
18
- # Translates given type name to absolute type name
19
- #
13
+ # Translates given type name to absolute type name.
20
14
  # Returns `nil` if cannot find associated type name.
21
- # Module names in the type name are normalized.
22
15
  #
23
16
  def resolve: (TypeName, context: context) -> TypeName?
24
17
 
25
- # Translates given type name to absolute type name
26
- #
27
- # Returns `false` if a cycle is detected while resolving aliases.
28
- # Returns `nil` if the type name cannot be resolved.
29
- #
30
- def resolve_namespace: (TypeName, context: context) -> (TypeName | false | nil)
31
-
32
18
  private
33
19
 
34
- attr_reader all_names: Set[TypeName]
20
+ attr_reader env: Environment
35
21
 
36
- attr_reader aliases: Hash[TypeName, [TypeName, context]]
22
+ attr_reader all_names: Set[TypeName]
37
23
 
38
24
  attr_reader cache: Hash[query, TypeName?]
39
25
 
40
- # Returns the type name if it exists in `all_names` (normalized)
41
- #
42
- def has_type_name?: (TypeName) -> TypeName?
43
-
44
- # Returns the type name if it is an alias (not normalized)
45
- #
46
- def aliased_name?: (TypeName) -> TypeName?
26
+ def has_name?: (TypeName) -> TypeName?
47
27
 
48
28
  def try_cache: (query) { () -> TypeName? } -> TypeName?
49
29
 
50
- # Translates the head module name in the context and returns an absolute type name
51
- #
52
- # Returns `nil` if cannot find associated type name.
53
- # The returned namespace may be an alias
54
- #
55
- def resolve_head_namespace: (Symbol, context) -> TypeName?
56
-
57
- # Resolves the type name in the given context
58
- #
59
- def resolve_type_name: (Symbol, context) -> TypeName?
60
-
61
- def resolve_namespace0: (TypeName, context, Set[TypeName]) -> (TypeName | false | nil)
30
+ def resolve_in: (Symbol, context) -> TypeName?
62
31
 
63
- def normalize_namespace: (TypeName, TypeName rhs, context, Set[TypeName]) -> (TypeName | false | nil)
32
+ def partition: (TypeName) -> [Symbol, TypeName?]
64
33
  end
65
34
  end
66
35
  end
data/sig/source.rbs ADDED
@@ -0,0 +1,48 @@
1
+ module RBS
2
+ module Source
3
+ type t = RBS | Ruby
4
+
5
+ class RBS
6
+ attr_reader buffer: Buffer
7
+
8
+ attr_reader directives: Array[AST::Directives::t]
9
+
10
+ attr_reader declarations: Array[AST::Declarations::t]
11
+
12
+ def initialize: (Buffer, Array[AST::Directives::t], Array[AST::Declarations::t]) -> void
13
+
14
+ # Enumerates defined type names in the source
15
+ #
16
+ # The order is undefined. Deduplicated per source object.
17
+ #
18
+ def each_type_name: () { (TypeName) -> void } -> void
19
+ | () -> Enumerator[TypeName]
20
+
21
+ private def each_declaration_type_name: (Set[TypeName], AST::Declarations::t) { (TypeName) -> void } -> void
22
+ end
23
+
24
+ class Ruby
25
+ attr_reader buffer: Buffer
26
+
27
+ attr_reader prism_result: Prism::ParseResult
28
+
29
+ attr_reader declarations: Array[AST::Ruby::Declarations::t]
30
+
31
+ attr_reader diagnostics: Array[untyped]
32
+
33
+ def initialize: (Buffer, Prism::ParseResult, Array[AST::Ruby::Declarations::t], Array[untyped]) -> void
34
+
35
+ def each_type_name: () { (TypeName) -> void } -> void
36
+ | () -> Enumerator[TypeName]
37
+
38
+ private def each_declaration_type_name: (Set[TypeName], AST::Ruby::Declarations::t) { (TypeName) -> void } -> void
39
+
40
+ # Compares the type declaration between `self` and `other`
41
+ #
42
+ # The comparison is based on the AST structure.
43
+ # Differences on Ruby code implementation may be ignored.
44
+ #
45
+ def ==: (other: Ruby) -> bool
46
+ end
47
+ end
48
+ end
data/sig/types.rbs CHANGED
@@ -518,10 +518,7 @@ module RBS
518
518
 
519
519
  attr_reader self_type: t?
520
520
 
521
- type loc = Location[bot, bot]
522
- attr_reader location: loc?
523
-
524
- def initialize: (?location: loc?, type: function, ?self_type: t?, required: boolish) -> void
521
+ def initialize: (type: function, ?self_type: t?, required: boolish) -> void
525
522
 
526
523
  def ==: (untyped other) -> bool
527
524