rbs 3.9.4 → 4.2.0

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 (354) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +75 -0
  3. data/.clangd +2 -0
  4. data/.dockerignore +37 -0
  5. data/.gitattributes +1 -0
  6. data/.github/dependabot.yml +16 -14
  7. data/.github/workflows/bundle-update.yml +63 -0
  8. data/.github/workflows/c-check.yml +66 -0
  9. data/.github/workflows/changelog.yml +121 -0
  10. data/.github/workflows/comments.yml +6 -4
  11. data/.github/workflows/dependabot.yml +2 -2
  12. data/.github/workflows/jruby.yml +74 -0
  13. data/.github/workflows/release-gems.yml +234 -0
  14. data/.github/workflows/ruby.yml +86 -32
  15. data/.github/workflows/rust.yml +186 -0
  16. data/.github/workflows/truffleruby.yml +54 -0
  17. data/.github/workflows/typecheck.yml +6 -3
  18. data/.github/workflows/wasm.yml +55 -0
  19. data/.github/workflows/windows.yml +10 -4
  20. data/.gitignore +16 -0
  21. data/.rubocop.yml +1 -2
  22. data/CHANGELOG.md +502 -0
  23. data/Dockerfile.jruby +53 -0
  24. data/README.md +42 -5
  25. data/Rakefile +892 -111
  26. data/Steepfile +11 -0
  27. data/config.yml +665 -62
  28. data/core/array.rbs +541 -398
  29. data/core/basic_object.rbs +9 -8
  30. data/core/binding.rbs +0 -2
  31. data/core/builtin.rbs +9 -8
  32. data/core/class.rbs +11 -8
  33. data/core/comparable.rbs +55 -34
  34. data/core/complex.rbs +104 -78
  35. data/core/dir.rbs +61 -49
  36. data/core/encoding.rbs +12 -15
  37. data/core/enumerable.rbs +297 -196
  38. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  39. data/core/enumerator/product.rbs +5 -5
  40. data/core/enumerator.rbs +91 -28
  41. data/core/errno.rbs +11 -2
  42. data/core/errors.rbs +58 -29
  43. data/core/exception.rbs +13 -13
  44. data/core/fiber.rbs +74 -54
  45. data/core/file.rbs +260 -1151
  46. data/core/file_constants.rbs +463 -0
  47. data/core/file_stat.rbs +534 -0
  48. data/core/file_test.rbs +3 -3
  49. data/core/float.rbs +257 -116
  50. data/core/gc.rbs +425 -281
  51. data/core/hash.rbs +1151 -829
  52. data/core/integer.rbs +156 -195
  53. data/core/io/buffer.rbs +53 -42
  54. data/core/io/wait.rbs +13 -35
  55. data/core/io.rbs +222 -155
  56. data/core/kernel.rbs +239 -163
  57. data/core/marshal.rbs +4 -4
  58. data/core/match_data.rbs +16 -14
  59. data/core/math.rbs +107 -66
  60. data/core/method.rbs +69 -33
  61. data/core/module.rbs +302 -150
  62. data/core/nil_class.rbs +7 -6
  63. data/core/numeric.rbs +77 -63
  64. data/core/object.rbs +9 -11
  65. data/core/object_space/weak_key_map.rbs +7 -7
  66. data/core/object_space.rbs +30 -23
  67. data/core/pathname.rbs +1312 -0
  68. data/core/proc.rbs +95 -58
  69. data/core/process.rbs +222 -202
  70. data/core/ractor.rbs +364 -518
  71. data/core/random.rbs +21 -3
  72. data/core/range.rbs +181 -79
  73. data/core/rational.rbs +60 -89
  74. data/core/rbs/ops.rbs +154 -0
  75. data/core/rbs/unnamed/argf.rbs +63 -56
  76. data/core/rbs/unnamed/env_class.rbs +19 -14
  77. data/core/rbs/unnamed/main_class.rbs +123 -0
  78. data/core/rbs/unnamed/random.rbs +11 -118
  79. data/core/regexp.rbs +258 -214
  80. data/core/ruby.rbs +53 -0
  81. data/core/ruby_vm.rbs +78 -34
  82. data/core/rubygems/config_file.rbs +5 -5
  83. data/core/rubygems/errors.rbs +6 -70
  84. data/core/rubygems/requirement.rbs +5 -15
  85. data/core/rubygems/rubygems.rbs +18 -81
  86. data/core/rubygems/specification.rbs +8 -0
  87. data/core/rubygems/version.rbs +2 -163
  88. data/core/set.rbs +493 -363
  89. data/core/signal.rbs +26 -16
  90. data/core/string.rbs +3234 -1285
  91. data/core/struct.rbs +43 -42
  92. data/core/symbol.rbs +41 -34
  93. data/core/thread.rbs +139 -83
  94. data/core/time.rbs +81 -50
  95. data/core/trace_point.rbs +41 -35
  96. data/core/true_class.rbs +2 -2
  97. data/core/unbound_method.rbs +24 -16
  98. data/core/warning.rbs +7 -7
  99. data/docs/CONTRIBUTING.md +3 -2
  100. data/docs/aliases.md +79 -0
  101. data/docs/collection.md +3 -3
  102. data/docs/config.md +171 -0
  103. data/docs/encoding.md +56 -0
  104. data/docs/gem.md +0 -1
  105. data/docs/inline.md +634 -0
  106. data/docs/rbs_by_example.md +20 -20
  107. data/docs/release.md +303 -0
  108. data/docs/rust.md +96 -0
  109. data/docs/sigs.md +3 -3
  110. data/docs/stdlib.md +8 -0
  111. data/docs/syntax.md +60 -18
  112. data/docs/type_fingerprint.md +21 -0
  113. data/docs/wasm_serialization.md +80 -0
  114. data/exe/rbs +1 -1
  115. data/ext/rbs_extension/ast_translation.c +1870 -0
  116. data/ext/rbs_extension/ast_translation.h +41 -0
  117. data/ext/rbs_extension/class_constants.c +189 -0
  118. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +24 -1
  119. data/ext/rbs_extension/compat.h +10 -0
  120. data/ext/rbs_extension/extconf.rb +26 -1
  121. data/ext/rbs_extension/legacy_location.c +299 -0
  122. data/ext/rbs_extension/legacy_location.h +82 -0
  123. data/ext/rbs_extension/main.c +639 -23
  124. data/ext/rbs_extension/rbs_extension.h +6 -21
  125. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  126. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  127. data/include/rbs/ast.h +1055 -0
  128. data/include/rbs/defines.h +104 -0
  129. data/include/rbs/lexer.h +208 -0
  130. data/include/rbs/location.h +40 -0
  131. data/include/rbs/parser.h +187 -0
  132. data/include/rbs/serialize.h +39 -0
  133. data/include/rbs/string.h +47 -0
  134. data/include/rbs/util/rbs_allocator.h +59 -0
  135. data/include/rbs/util/rbs_assert.h +20 -0
  136. data/include/rbs/util/rbs_buffer.h +83 -0
  137. data/include/rbs/util/rbs_constant_pool.h +6 -70
  138. data/include/rbs/util/rbs_encoding.h +282 -0
  139. data/include/rbs/util/rbs_unescape.h +24 -0
  140. data/include/rbs.h +9 -2
  141. data/lib/rbs/annotate/formatter.rb +3 -13
  142. data/lib/rbs/annotate/rdoc_annotator.rb +30 -32
  143. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  144. data/lib/rbs/ast/annotation.rb +1 -1
  145. data/lib/rbs/ast/comment.rb +1 -1
  146. data/lib/rbs/ast/declarations.rb +11 -11
  147. data/lib/rbs/ast/members.rb +14 -14
  148. data/lib/rbs/ast/ruby/annotations.rb +451 -0
  149. data/lib/rbs/ast/ruby/comment_block.rb +247 -0
  150. data/lib/rbs/ast/ruby/declarations.rb +291 -0
  151. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
  152. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  153. data/lib/rbs/ast/ruby/members.rb +762 -0
  154. data/lib/rbs/ast/type_param.rb +25 -5
  155. data/lib/rbs/buffer.rb +142 -20
  156. data/lib/rbs/cli/diff.rb +16 -15
  157. data/lib/rbs/cli/validate.rb +63 -126
  158. data/lib/rbs/cli.rb +59 -29
  159. data/lib/rbs/collection/config/lockfile_generator.rb +28 -3
  160. data/lib/rbs/collection/sources/git.rb +7 -0
  161. data/lib/rbs/definition.rb +6 -1
  162. data/lib/rbs/definition_builder/ancestor_builder.rb +129 -70
  163. data/lib/rbs/definition_builder/method_builder.rb +74 -33
  164. data/lib/rbs/definition_builder.rb +181 -21
  165. data/lib/rbs/diff.rb +7 -1
  166. data/lib/rbs/environment/class_entry.rb +81 -0
  167. data/lib/rbs/environment/module_entry.rb +91 -0
  168. data/lib/rbs/environment.rb +410 -215
  169. data/lib/rbs/environment_loader.rb +2 -8
  170. data/lib/rbs/errors.rb +31 -21
  171. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  172. data/lib/rbs/inline_parser.rb +568 -0
  173. data/lib/rbs/location_aux.rb +36 -4
  174. data/lib/rbs/locator.rb +5 -1
  175. data/lib/rbs/method_type.rb +5 -3
  176. data/lib/rbs/namespace.rb +47 -18
  177. data/lib/rbs/parser_aux.rb +37 -7
  178. data/lib/rbs/prototype/helpers.rb +24 -0
  179. data/lib/rbs/prototype/rb.rb +3 -28
  180. data/lib/rbs/prototype/rbi.rb +196 -45
  181. data/lib/rbs/prototype/runtime/value_object_generator.rb +0 -1
  182. data/lib/rbs/prototype/runtime.rb +13 -3
  183. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  184. data/lib/rbs/resolver/type_name_resolver.rb +120 -44
  185. data/lib/rbs/rewriter.rb +70 -0
  186. data/lib/rbs/source.rb +99 -0
  187. data/lib/rbs/subtractor.rb +7 -4
  188. data/lib/rbs/test/type_check.rb +25 -3
  189. data/lib/rbs/type_name.rb +34 -21
  190. data/lib/rbs/types.rb +135 -81
  191. data/lib/rbs/unit_test/convertibles.rb +1 -0
  192. data/lib/rbs/unit_test/type_assertions.rb +47 -11
  193. data/lib/rbs/validator.rb +2 -2
  194. data/lib/rbs/version.rb +1 -1
  195. data/lib/rbs/wasm/deserializer.rb +213 -0
  196. data/lib/rbs/wasm/location.rb +61 -0
  197. data/lib/rbs/wasm/parser.rb +174 -0
  198. data/lib/rbs/wasm/runtime.rb +211 -0
  199. data/lib/rbs/wasm/serialization_schema.rb +111 -0
  200. data/lib/rbs.rb +25 -2
  201. data/lib/rbs_jars.rb +39 -0
  202. data/lib/rdoc/discover.rb +1 -1
  203. data/lib/rdoc_plugin/parser.rb +8 -3
  204. data/rbs.gemspec +34 -6
  205. data/schema/function.json +12 -1
  206. data/schema/typeParam.json +17 -1
  207. data/sig/ancestor_builder.rbs +1 -1
  208. data/sig/annotate/formatter.rbs +2 -2
  209. data/sig/annotate/rdoc_annotater.rbs +13 -10
  210. data/sig/ast/ruby/annotations.rbs +470 -0
  211. data/sig/ast/ruby/comment_block.rbs +127 -0
  212. data/sig/ast/ruby/declarations.rbs +158 -0
  213. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  214. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  215. data/sig/ast/ruby/members.rbs +198 -0
  216. data/sig/buffer.rbs +81 -5
  217. data/sig/cli/diff.rbs +5 -11
  218. data/sig/cli/validate.rbs +12 -8
  219. data/sig/cli.rbs +18 -18
  220. data/sig/collection/config/lockfile_generator.rbs +2 -0
  221. data/sig/definition.rbs +6 -0
  222. data/sig/definition_builder.rbs +3 -1
  223. data/sig/environment/class_entry.rbs +56 -0
  224. data/sig/environment/module_entry.rbs +65 -0
  225. data/sig/environment.rbs +94 -87
  226. data/sig/errors.rbs +26 -20
  227. data/sig/inline_parser/comment_association.rbs +71 -0
  228. data/sig/inline_parser.rbs +126 -0
  229. data/sig/location.rbs +32 -7
  230. data/sig/locator.rbs +0 -2
  231. data/sig/manifest.yaml +0 -2
  232. data/sig/method_builder.rbs +9 -4
  233. data/sig/namespace.rbs +20 -5
  234. data/sig/parser.rbs +79 -15
  235. data/sig/prototype/helpers.rbs +2 -0
  236. data/sig/prototype/rbi.rbs +33 -4
  237. data/sig/resolver/type_name_resolver.rbs +36 -10
  238. data/sig/rewriter.rbs +45 -0
  239. data/sig/source.rbs +48 -0
  240. data/sig/type_param.rbs +13 -8
  241. data/sig/typename.rbs +15 -5
  242. data/sig/types.rbs +21 -9
  243. data/sig/unit_test/spy.rbs +0 -8
  244. data/sig/unit_test/type_assertions.rbs +17 -2
  245. data/sig/wasm/deserializer.rbs +66 -0
  246. data/sig/wasm/serialization_schema.rbs +13 -0
  247. data/src/ast.c +1644 -0
  248. data/src/lexer.c +3223 -0
  249. data/src/lexer.re +187 -0
  250. data/src/lexstate.c +222 -0
  251. data/src/location.c +31 -0
  252. data/src/parser.c +4318 -0
  253. data/src/serialize.c +965 -0
  254. data/src/string.c +41 -0
  255. data/src/util/rbs_allocator.c +171 -0
  256. data/src/util/rbs_assert.c +19 -0
  257. data/src/util/rbs_buffer.c +54 -0
  258. data/src/util/rbs_constant_pool.c +18 -92
  259. data/src/util/rbs_encoding.c +21454 -0
  260. data/src/util/rbs_unescape.c +167 -0
  261. data/stdlib/abbrev/0/array.rbs +1 -1
  262. data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
  263. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  264. data/stdlib/cgi/0/core.rbs +9 -393
  265. data/stdlib/cgi/0/manifest.yaml +1 -0
  266. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  267. data/stdlib/coverage/0/coverage.rbs +7 -4
  268. data/stdlib/csv/0/csv.rbs +5 -5
  269. data/stdlib/date/0/date.rbs +92 -79
  270. data/stdlib/date/0/date_time.rbs +25 -24
  271. data/stdlib/delegate/0/delegator.rbs +11 -7
  272. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  273. data/stdlib/digest/0/digest.rbs +117 -1
  274. data/stdlib/erb/0/erb.rbs +754 -353
  275. data/stdlib/etc/0/etc.rbs +73 -54
  276. data/stdlib/fileutils/0/fileutils.rbs +179 -160
  277. data/stdlib/forwardable/0/forwardable.rbs +13 -10
  278. data/stdlib/io-console/0/io-console.rbs +2 -2
  279. data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
  280. data/stdlib/json/0/json.rbs +232 -185
  281. data/stdlib/monitor/0/monitor.rbs +9 -9
  282. data/stdlib/net-http/0/net-http.rbs +162 -134
  283. data/stdlib/objspace/0/objspace.rbs +17 -34
  284. data/stdlib/open-uri/0/open-uri.rbs +48 -8
  285. data/stdlib/open3/0/open3.rbs +469 -10
  286. data/stdlib/openssl/0/openssl.rbs +521 -397
  287. data/stdlib/optparse/0/optparse.rbs +26 -17
  288. data/stdlib/pathname/0/pathname.rbs +11 -1381
  289. data/stdlib/pp/0/pp.rbs +9 -8
  290. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  291. data/stdlib/pstore/0/pstore.rbs +35 -30
  292. data/stdlib/psych/0/psych.rbs +65 -12
  293. data/stdlib/psych/0/store.rbs +2 -4
  294. data/stdlib/pty/0/pty.rbs +9 -6
  295. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  296. data/stdlib/rdoc/0/code_object.rbs +4 -3
  297. data/stdlib/rdoc/0/comment.rbs +2 -0
  298. data/stdlib/rdoc/0/options.rbs +76 -0
  299. data/stdlib/rdoc/0/parser.rbs +1 -1
  300. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  301. data/stdlib/rdoc/0/store.rbs +2 -2
  302. data/stdlib/resolv/0/resolv.rbs +26 -69
  303. data/stdlib/ripper/0/ripper.rbs +25 -19
  304. data/stdlib/securerandom/0/manifest.yaml +2 -0
  305. data/stdlib/securerandom/0/securerandom.rbs +7 -20
  306. data/stdlib/shellwords/0/shellwords.rbs +3 -3
  307. data/stdlib/singleton/0/singleton.rbs +6 -0
  308. data/stdlib/socket/0/addrinfo.rbs +9 -9
  309. data/stdlib/socket/0/basic_socket.rbs +3 -3
  310. data/stdlib/socket/0/ip_socket.rbs +10 -8
  311. data/stdlib/socket/0/socket.rbs +23 -10
  312. data/stdlib/socket/0/tcp_server.rbs +1 -1
  313. data/stdlib/socket/0/tcp_socket.rbs +11 -3
  314. data/stdlib/socket/0/udp_socket.rbs +1 -1
  315. data/stdlib/socket/0/unix_server.rbs +1 -1
  316. data/stdlib/stringio/0/stringio.rbs +1211 -96
  317. data/stdlib/strscan/0/string_scanner.rbs +101 -80
  318. data/stdlib/tempfile/0/manifest.yaml +3 -0
  319. data/stdlib/tempfile/0/tempfile.rbs +25 -21
  320. data/stdlib/time/0/time.rbs +8 -6
  321. data/stdlib/timeout/0/timeout.rbs +58 -7
  322. data/stdlib/tsort/0/cyclic.rbs +4 -1
  323. data/stdlib/tsort/0/interfaces.rbs +8 -8
  324. data/stdlib/tsort/0/tsort.rbs +16 -15
  325. data/stdlib/uri/0/common.rbs +42 -20
  326. data/stdlib/uri/0/file.rbs +3 -3
  327. data/stdlib/uri/0/generic.rbs +21 -18
  328. data/stdlib/uri/0/http.rbs +2 -2
  329. data/stdlib/uri/0/ldap.rbs +2 -2
  330. data/stdlib/uri/0/mailto.rbs +3 -3
  331. data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
  332. data/stdlib/zlib/0/deflate.rbs +4 -3
  333. data/stdlib/zlib/0/gzip_file.rbs +1 -1
  334. data/stdlib/zlib/0/gzip_reader.rbs +8 -8
  335. data/stdlib/zlib/0/gzip_writer.rbs +16 -13
  336. data/stdlib/zlib/0/inflate.rbs +1 -1
  337. data/stdlib/zlib/0/need_dict.rbs +1 -1
  338. data/wasm/README.md +109 -0
  339. data/wasm/rbs_wasm.c +479 -0
  340. metadata +133 -19
  341. data/ext/rbs_extension/lexer.c +0 -2728
  342. data/ext/rbs_extension/lexer.h +0 -179
  343. data/ext/rbs_extension/lexer.re +0 -147
  344. data/ext/rbs_extension/lexstate.c +0 -175
  345. data/ext/rbs_extension/location.c +0 -325
  346. data/ext/rbs_extension/location.h +0 -85
  347. data/ext/rbs_extension/parser.c +0 -2982
  348. data/ext/rbs_extension/parser.h +0 -18
  349. data/ext/rbs_extension/parserstate.c +0 -411
  350. data/ext/rbs_extension/parserstate.h +0 -163
  351. data/ext/rbs_extension/unescape.c +0 -32
  352. data/include/rbs/ruby_objs.h +0 -72
  353. data/src/constants.c +0 -153
  354. data/src/ruby_objs.c +0 -799
@@ -0,0 +1,470 @@
1
+ module RBS
2
+ module AST
3
+ module Ruby
4
+ module Annotations
5
+ type leading_annotation = ColonMethodTypeAnnotation
6
+ | MethodTypesAnnotation
7
+ | SkipAnnotation
8
+ | ReturnTypeAnnotation
9
+ | InstanceVariableAnnotation
10
+ | ModuleSelfAnnotation
11
+ | ParamTypeAnnotation
12
+ | SplatParamTypeAnnotation
13
+ | DoubleSplatParamTypeAnnotation
14
+ | BlockParamTypeAnnotation
15
+
16
+ type trailing_annotation = NodeTypeAssertion
17
+ | TypeApplicationAnnotation
18
+ | ClassAliasAnnotation
19
+ | ModuleAliasAnnotation
20
+
21
+ type t = leading_annotation | trailing_annotation
22
+
23
+ class Base
24
+ # Location that covers all of the annotation
25
+ #
26
+ attr_reader location: Location
27
+
28
+ # Location of `@rbs`, `@rbs!`, or `:` prefix
29
+ #
30
+ attr_reader prefix_location: Location
31
+
32
+ def initialize: (Location location, Location prefix_location) -> void
33
+
34
+ def buffer: () -> Buffer
35
+
36
+ # Returns the type fingerprint for this annotation
37
+ def type_fingerprint: () -> untyped
38
+ end
39
+
40
+ # `: TYPE` annotation attached to nodes
41
+ #
42
+ class NodeTypeAssertion < Base
43
+ attr_reader type: Types::t
44
+
45
+ def initialize: (location: Location, prefix_location: Location, type: Types::t) -> void
46
+
47
+ def map_type_name: () { (TypeName) -> TypeName } -> self
48
+
49
+ def type_fingerprint: () -> untyped
50
+ end
51
+
52
+ class AliasAnnotation < Base
53
+ attr_reader keyword_location: Location
54
+
55
+ attr_reader type_name_location: Location?
56
+
57
+ # The name of the module that will be the target of the alias
58
+ #
59
+ # - `nil` if the module/class name is unspecified
60
+ # - `TypeName` object if the module/class name is specified
61
+ #
62
+ attr_reader type_name: TypeName?
63
+
64
+ def initialize: (location: Location, prefix_location: Location, keyword_location: Location, type_name: TypeName?, type_name_location: Location?) -> void
65
+
66
+ def map_type_name: () { (TypeName) -> TypeName } -> self
67
+ end
68
+
69
+ # `: class-alias` annotation
70
+ #
71
+ # ```
72
+ # : class-alias Foo::Bar
73
+ # ^ -- prefix_location
74
+ # ^^^^^^^^^^^^ -- keyword_location
75
+ # ^^^^^^^^ -- type_name_location
76
+ # ```
77
+ #
78
+ class ClassAliasAnnotation < AliasAnnotation
79
+ def type_fingerprint: () -> untyped
80
+ end
81
+
82
+ # `: module-alias` annotation
83
+ #
84
+ # ```
85
+ # : module-alias Foo::Bar
86
+ # ^ -- prefix_location
87
+ # ^^^^^^^^^^^^ -- keyword_location
88
+ # ^^^^^^^^ -- type_name_location
89
+ # ```
90
+ #
91
+ class ModuleAliasAnnotation < AliasAnnotation
92
+ def type_fingerprint: () -> untyped
93
+ end
94
+
95
+ # `: METHOD-TYPE` annotation in leading comments
96
+ #
97
+ class ColonMethodTypeAnnotation < Base
98
+ attr_reader annotations: Array[AST::Annotation]
99
+
100
+ attr_reader method_type: MethodType
101
+
102
+ def initialize: (location: Location, prefix_location: Location, annotations: Array[AST::Annotation], method_type: MethodType) -> void
103
+
104
+ def map_type_name: () { (TypeName) -> TypeName } -> self
105
+
106
+ def type_fingerprint: () -> untyped
107
+ end
108
+
109
+ # `@rbs METHOD-TYPEs` annotation in leading comments
110
+ #
111
+ # ```
112
+ # @rbs () -> void | %a{foo} () -> String | ...
113
+ # ^^^^ -- prefix_location
114
+ # ^ -- vertical_bar_locations[0]
115
+ # ^ -- vertical_bar_locations[1]
116
+ # ^^^ -- dot3_location
117
+ # ```
118
+ class MethodTypesAnnotation < Base
119
+ class Overload = AST::Members::MethodDefinition::Overload
120
+
121
+ attr_reader overloads: Array[Overload]
122
+
123
+ attr_reader vertical_bar_locations: Array[Location]
124
+
125
+ attr_reader dot3_location: Location?
126
+
127
+ def initialize: (location: Location, prefix_location: Location, overloads: Array[Overload], vertical_bar_locations: Array[Location], dot3_location: Location?) -> void
128
+
129
+ def map_type_name: () { (TypeName) -> TypeName } -> self
130
+
131
+ def type_fingerprint: () -> untyped
132
+ end
133
+
134
+ # `@rbs skip -- comment` annotation in leading comments
135
+ #
136
+ class SkipAnnotation < Base
137
+ attr_reader skip_location: Location
138
+ attr_reader comment_location: Location?
139
+
140
+ def initialize: (location: Location, prefix_location: Location, skip_location: Location, comment_location: Location?) -> void
141
+
142
+ def type_fingerprint: () -> untyped
143
+ end
144
+
145
+ # `@rbs return: T -- comment` annotation in leading comments
146
+ #
147
+ # ```
148
+ # @rbs return: String -- Returns a string
149
+ # ^^^ -- prefix_location
150
+ # ^^^^^^ -- return_location
151
+ # ^ -- colon_location
152
+ # ^^^^^^^^^^^^^^^^^^^ -- comment
153
+ # ```
154
+ class ReturnTypeAnnotation < Base
155
+ attr_reader return_location: Location
156
+
157
+ attr_reader colon_location: Location
158
+
159
+ attr_reader return_type: Types::t
160
+
161
+ attr_reader comment_location: Location?
162
+
163
+ def initialize: (
164
+ location: Location,
165
+ prefix_location: Location,
166
+ return_location: Location,
167
+ colon_location: Location,
168
+ return_type: Types::t,
169
+ comment_location: Location?,
170
+ ) -> void
171
+
172
+ def map_type_name: () { (TypeName) -> TypeName } -> self
173
+
174
+ def type_fingerprint: () -> untyped
175
+ end
176
+
177
+ # `[T1, T2, ...]` annotation in trailing comments
178
+ #
179
+ # ```
180
+ # #[String, Integer]
181
+ # ^ -- prefix_location
182
+ # ^ -- comma_locations[0]
183
+ # ^ -- close_bracket_location
184
+ # ```
185
+ #
186
+ class TypeApplicationAnnotation < Base
187
+ attr_reader type_args: Array[Types::t]
188
+
189
+ attr_reader close_bracket_location: Location
190
+
191
+ attr_reader comma_locations: Array[Location]
192
+
193
+ def initialize: (
194
+ location: Location,
195
+ prefix_location: Location,
196
+ type_args: Array[Types::t],
197
+ close_bracket_location: Location,
198
+ comma_locations: Array[Location],
199
+ ) -> void
200
+
201
+ def map_type_name: () { (TypeName) -> TypeName } -> self
202
+
203
+ def type_fingerprint: () -> untyped
204
+ end
205
+
206
+ # `@rbs IVAR-NAME : TYPE` annotation in leading comments
207
+ #
208
+ # ```
209
+ # @rbs @foo : String -- comment
210
+ # ^^^^ -- prefix_location
211
+ # ^^^^ -- ivar_name_location
212
+ # ^ -- colon_location
213
+ # ^^^^^^^^^^ -- comment_location
214
+ # ```
215
+ class InstanceVariableAnnotation < Base
216
+ attr_reader ivar_name: Symbol
217
+
218
+ attr_reader ivar_name_location: Location
219
+
220
+ attr_reader colon_location: Location
221
+
222
+ attr_reader type: Types::t
223
+
224
+ attr_reader comment_location: Location?
225
+
226
+ def initialize: (
227
+ location: Location,
228
+ prefix_location: Location,
229
+ ivar_name: Symbol,
230
+ ivar_name_location: Location,
231
+ colon_location: Location,
232
+ type: Types::t,
233
+ comment_location: Location?,
234
+ ) -> void
235
+
236
+ def map_type_name: () { (TypeName) -> TypeName } -> self
237
+
238
+ def type_fingerprint: () -> untyped
239
+ end
240
+
241
+ # `@rbs module-self: NAME[ARGS] -- comment` annotation in leading comments
242
+ #
243
+ # ```
244
+ # @rbs module-self: _Each[String, Integer] -- comment
245
+ # ^^^^ -- prefix_location
246
+ # ^^^^^^^^^^^ -- keyword_location
247
+ # ^ -- colon_location
248
+ # ^ -- open_bracket_location
249
+ # ^ -- args_comma_locations[0]
250
+ # ^ -- close_bracket_location
251
+ # ^^^^^^^^^^ -- comment_location
252
+ # ```
253
+ #
254
+ class ModuleSelfAnnotation < Base
255
+ attr_reader keyword_location: Location
256
+
257
+ attr_reader colon_location: Location
258
+
259
+ attr_reader name: TypeName
260
+
261
+ attr_reader args: Array[Types::t]
262
+
263
+ attr_reader open_bracket_location: Location?
264
+
265
+ attr_reader close_bracket_location: Location?
266
+
267
+ attr_reader args_comma_locations: Array[Location]
268
+
269
+ attr_reader comment_location: Location?
270
+
271
+ def initialize: (
272
+ location: Location,
273
+ prefix_location: Location,
274
+ keyword_location: Location,
275
+ colon_location: Location,
276
+ name: TypeName,
277
+ args: Array[Types::t],
278
+ open_bracket_location: Location?,
279
+ close_bracket_location: Location?,
280
+ args_comma_locations: Array[Location],
281
+ comment_location: Location?,
282
+ ) -> void
283
+
284
+ def map_type_name: () { (TypeName) -> TypeName } -> self
285
+
286
+ def type_fingerprint: () -> untyped
287
+ end
288
+
289
+ class ParamTypeAnnotation < Base
290
+ attr_reader name_location: Location
291
+
292
+ attr_reader colon_location: Location
293
+
294
+ attr_reader param_type: Types::t
295
+
296
+ attr_reader comment_location: Location?
297
+
298
+ def initialize: (
299
+ location: Location,
300
+ prefix_location: Location,
301
+ name_location: Location,
302
+ colon_location: Location,
303
+ param_type: Types::t,
304
+ comment_location: Location?,
305
+ ) -> void
306
+
307
+ def map_type_name: () { (TypeName) -> TypeName } -> self
308
+
309
+ def type_fingerprint: () -> untyped
310
+
311
+ %a{pure}
312
+ def name: () -> Symbol
313
+ end
314
+
315
+ # `@rbs *name: Type -- comment` annotation in leading comments
316
+ #
317
+ # ```
318
+ # @rbs *a: String -- comment
319
+ # ^^^^ -- prefix_location
320
+ # ^ -- star_location
321
+ # ^ -- name_location
322
+ # ^ -- colon_location
323
+ # ^^^^^^^^^^ -- comment_location
324
+ # ```
325
+ #
326
+ # ```
327
+ # @rbs *: String
328
+ # ^^^^ -- prefix_location
329
+ # ^ -- star_location
330
+ # ^ -- colon_location
331
+ # ```
332
+ #
333
+ class SplatParamTypeAnnotation < Base
334
+ attr_reader star_location: Location
335
+
336
+ attr_reader name_location: Location?
337
+
338
+ attr_reader colon_location: Location
339
+
340
+ attr_reader param_type: Types::t
341
+
342
+ attr_reader comment_location: Location?
343
+
344
+ def initialize: (
345
+ location: Location,
346
+ prefix_location: Location,
347
+ star_location: Location,
348
+ name_location: Location?,
349
+ colon_location: Location,
350
+ param_type: Types::t,
351
+ comment_location: Location?,
352
+ ) -> void
353
+
354
+ def map_type_name: () { (TypeName) -> TypeName } -> self
355
+
356
+ def type_fingerprint: () -> untyped
357
+
358
+ %a{pure}
359
+ def name: () -> Symbol?
360
+ end
361
+
362
+ # `@rbs **name: Type -- comment` annotation in leading comments
363
+ #
364
+ # ```
365
+ # @rbs **b: bool -- comment
366
+ # ^^^^ -- prefix_location
367
+ # ^^ -- star2_location
368
+ # ^ -- name_location
369
+ # ^ -- colon_location
370
+ # ^^^^^^^^^^ -- comment_location
371
+ # ```
372
+ #
373
+ # ```
374
+ # @rbs **: bool
375
+ # ^^^^ -- prefix_location
376
+ # ^^ -- star2_location
377
+ # ^ -- colon_location
378
+ # ```
379
+ #
380
+ class DoubleSplatParamTypeAnnotation < Base
381
+ attr_reader star2_location: Location
382
+
383
+ attr_reader name_location: Location?
384
+
385
+ attr_reader colon_location: Location
386
+
387
+ attr_reader param_type: Types::t
388
+
389
+ attr_reader comment_location: Location?
390
+
391
+ def initialize: (
392
+ location: Location,
393
+ prefix_location: Location,
394
+ star2_location: Location,
395
+ name_location: Location?,
396
+ colon_location: Location,
397
+ param_type: Types::t,
398
+ comment_location: Location?,
399
+ ) -> void
400
+
401
+ def map_type_name: () { (TypeName) -> TypeName } -> self
402
+
403
+ def type_fingerprint: () -> untyped
404
+
405
+ %a{pure}
406
+ def name: () -> Symbol?
407
+ end
408
+
409
+ # `@rbs &name: TYPE -- comment` annotation in leading comments
410
+ #
411
+ # ```
412
+ # @rbs &block: () -> void -- comment
413
+ # ^^^^ -- prefix_location
414
+ # ^ -- ampersand_location
415
+ # ^^^^^ -- name_location
416
+ # ^ -- colon_location
417
+ # ^^^^^^^^^^ -- type_location
418
+ # ^^^^^^^^^^ -- comment_location
419
+ # ```
420
+ #
421
+ # ```
422
+ # @rbs &: ? () -> void
423
+ # ^^^^ -- prefix_location
424
+ # ^ -- ampersand_location
425
+ # ^ -- colon_location
426
+ # ^ -- question_location
427
+ # ^^^^^^^^^^ -- type_location
428
+ # ```
429
+ #
430
+ class BlockParamTypeAnnotation < Base
431
+ attr_reader ampersand_location: Location
432
+
433
+ attr_reader name_location: Location?
434
+
435
+ attr_reader colon_location: Location
436
+
437
+ attr_reader type_location: Location
438
+
439
+ attr_reader type: Types::function
440
+
441
+ attr_reader question_location: Location?
442
+
443
+ attr_reader comment_location: Location?
444
+
445
+ def initialize: (
446
+ location: Location,
447
+ prefix_location: Location,
448
+ ampersand_location: Location,
449
+ name_location: Location?,
450
+ colon_location: Location,
451
+ question_location: Location?,
452
+ type_location: Location,
453
+ type: Types::function,
454
+ comment_location: Location?,
455
+ ) -> void
456
+
457
+ def map_type_name: () { (TypeName) -> TypeName } -> self
458
+
459
+ def type_fingerprint: () -> untyped
460
+
461
+ %a{pure} def name: () -> Symbol?
462
+
463
+ def optional?: () -> bool
464
+
465
+ def required?: () -> bool
466
+ end
467
+ end
468
+ end
469
+ end
470
+ end
@@ -0,0 +1,127 @@
1
+ use Prism::Comment
2
+
3
+ module RBS
4
+ module AST
5
+ module Ruby
6
+ # CommentBlock is a collection of comments
7
+ #
8
+ # ```ruby
9
+ # # Comment1 < block1
10
+ # # Comment2 <
11
+ #
12
+ # # Comment3 < block2
13
+ # ```
14
+ #
15
+ # A comment block is a *leading* block or *trailing* block.
16
+ #
17
+ # ```ruby
18
+ # # This is leading block.
19
+ # # This is the second line of the leading block.
20
+ #
21
+ # foo # This is trailing block.
22
+ # # This is second line of the trailing block.
23
+ # ```
24
+ #
25
+ # A leading block is a comment block where all of the comments are at the start of the line content.
26
+ # A trailing block is a comment block where the first comment of the block has something at the line before the comment.
27
+ #
28
+ class CommentBlock
29
+ attr_reader name: Pathname
30
+
31
+ # Sub buffer of the contents of the comments
32
+ #
33
+ attr_reader comment_buffer: Buffer
34
+
35
+ attr_reader offsets: Array[
36
+ [
37
+ Comment,
38
+ Integer, # -- prefix size
39
+ ]
40
+ ]
41
+
42
+ def initialize: (Buffer source_buffer, Array[Comment]) -> void
43
+
44
+ # Build comment block instances
45
+ def self.build: (Buffer, Array[Comment]) -> Array[instance]
46
+
47
+ # Returns true if the comment block is a *leading* comment, which is attached to the successor node
48
+ def leading?: () -> bool
49
+
50
+ # Returns true if the comment block is a *trailing* comment, which is attached to the predecessor node
51
+ def trailing?: () -> bool
52
+
53
+ # The line number of the first comment in the block
54
+ def start_line: () -> Integer
55
+
56
+ # The line number of the last comment in the block
57
+ def end_line: () -> Integer
58
+
59
+ # The character index of `#comment_buffer` at the start of the lines
60
+ #
61
+ def line_starts: () -> Array[Integer]
62
+
63
+ # Returns the text content of the comment
64
+ def text: (Integer index) -> String
65
+
66
+ # Yields paragraph and annotation
67
+ #
68
+ # A paragraph is a sequence of lines that are separated by annotations.
69
+ # An annotation starts with a line starting with `@rbs` or `:`, and may continue with lines that has more leading spaces.
70
+ #
71
+ # ```
72
+ # # Line 1 ^ Paragraph 1
73
+ # # Line 2 |
74
+ # # |
75
+ # # Line 3 v
76
+ # # @rbs ... < Annotation 1
77
+ # # @rbs ... ^ Annotation 2
78
+ # # ... |
79
+ # # |
80
+ # # ... v
81
+ # # ^ Paragraph 2
82
+ # # Line 4 |
83
+ # # Line 5 v
84
+ # ```
85
+ #
86
+ def each_paragraph: (Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void
87
+ | (Array[Symbol] variables) -> Enumerator[Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError]
88
+
89
+ # Returns a trailing annotation if it exists
90
+ #
91
+ # * Returns `nil` if the block is not a type annotation
92
+ # * Returns an annotation if the block has a type annotation
93
+ # * Returns AnnotationSyntaxError if the annotation has a syntax error
94
+ #
95
+ def trailing_annotation: (Array[Symbol] variables) -> (AST::Ruby::Annotations::trailing_annotation | AnnotationSyntaxError | nil)
96
+
97
+ class AnnotationSyntaxError
98
+ attr_reader location: Location
99
+
100
+ attr_reader error: ParsingError
101
+
102
+ def initialize: (Location, ParsingError) -> void
103
+ end
104
+
105
+ private def yield_paragraph: (Integer start_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void
106
+
107
+ private def yield_annotation: (Integer start_line, Integer end_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void
108
+
109
+ private def parse_annotation_lines: (Integer start_line, Integer end_line, Array[Symbol] variables) -> (AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError)
110
+
111
+ def comments: () -> Array[Comment]
112
+
113
+ def line_location: (Integer start_line, Integer end_line) -> Location
114
+
115
+ def location: () -> Location
116
+
117
+ private def leading_annotation?: (Integer index) -> bool
118
+
119
+ # Returns an comment object that contains the docs of from the comment block
120
+ #
121
+ # It ignores type annotations and syntax errors.
122
+ #
123
+ def as_comment: () -> AST::Comment?
124
+ end
125
+ end
126
+ end
127
+ end