rbs-relaxed 3.9.0.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 (484) hide show
  1. checksums.yaml +7 -0
  2. data/.github/dependabot.yml +22 -0
  3. data/.github/workflows/comments.yml +35 -0
  4. data/.github/workflows/dependabot.yml +30 -0
  5. data/.github/workflows/ruby.yml +82 -0
  6. data/.github/workflows/typecheck.yml +38 -0
  7. data/.github/workflows/windows.yml +43 -0
  8. data/.gitignore +23 -0
  9. data/.rubocop.yml +68 -0
  10. data/BSDL +22 -0
  11. data/CHANGELOG.md +1868 -0
  12. data/COPYING +56 -0
  13. data/README.md +203 -0
  14. data/Rakefile +417 -0
  15. data/Steepfile +44 -0
  16. data/config.yml +313 -0
  17. data/core/array.rbs +4062 -0
  18. data/core/basic_object.rbs +375 -0
  19. data/core/binding.rbs +150 -0
  20. data/core/builtin.rbs +277 -0
  21. data/core/class.rbs +220 -0
  22. data/core/comparable.rbs +171 -0
  23. data/core/complex.rbs +786 -0
  24. data/core/constants.rbs +96 -0
  25. data/core/data.rbs +415 -0
  26. data/core/dir.rbs +981 -0
  27. data/core/encoding.rbs +1371 -0
  28. data/core/enumerable.rbs +2405 -0
  29. data/core/enumerator/product.rbs +92 -0
  30. data/core/enumerator.rbs +630 -0
  31. data/core/env.rbs +6 -0
  32. data/core/errno.rbs +673 -0
  33. data/core/errors.rbs +760 -0
  34. data/core/exception.rbs +485 -0
  35. data/core/false_class.rbs +82 -0
  36. data/core/fiber.rbs +550 -0
  37. data/core/fiber_error.rbs +11 -0
  38. data/core/file.rbs +2936 -0
  39. data/core/file_test.rbs +331 -0
  40. data/core/float.rbs +1151 -0
  41. data/core/gc.rbs +644 -0
  42. data/core/global_variables.rbs +184 -0
  43. data/core/hash.rbs +1861 -0
  44. data/core/integer.rbs +1413 -0
  45. data/core/io/buffer.rbs +984 -0
  46. data/core/io/wait.rbs +70 -0
  47. data/core/io.rbs +3406 -0
  48. data/core/kernel.rbs +3096 -0
  49. data/core/marshal.rbs +207 -0
  50. data/core/match_data.rbs +635 -0
  51. data/core/math.rbs +729 -0
  52. data/core/method.rbs +386 -0
  53. data/core/module.rbs +1704 -0
  54. data/core/nil_class.rbs +209 -0
  55. data/core/numeric.rbs +818 -0
  56. data/core/object.rbs +110 -0
  57. data/core/object_space/weak_key_map.rbs +166 -0
  58. data/core/object_space.rbs +190 -0
  59. data/core/proc.rbs +868 -0
  60. data/core/process.rbs +2296 -0
  61. data/core/ractor.rbs +1068 -0
  62. data/core/random.rbs +237 -0
  63. data/core/range.rbs +1107 -0
  64. data/core/rational.rbs +531 -0
  65. data/core/rb_config.rbs +88 -0
  66. data/core/rbs/unnamed/argf.rbs +1229 -0
  67. data/core/rbs/unnamed/env_class.rbs +1209 -0
  68. data/core/rbs/unnamed/random.rbs +293 -0
  69. data/core/refinement.rbs +59 -0
  70. data/core/regexp.rbs +1930 -0
  71. data/core/ruby_vm.rbs +765 -0
  72. data/core/rubygems/basic_specification.rbs +6 -0
  73. data/core/rubygems/config_file.rbs +38 -0
  74. data/core/rubygems/dependency_installer.rbs +6 -0
  75. data/core/rubygems/errors.rbs +176 -0
  76. data/core/rubygems/installer.rbs +15 -0
  77. data/core/rubygems/path_support.rbs +6 -0
  78. data/core/rubygems/platform.rbs +7 -0
  79. data/core/rubygems/request_set.rbs +49 -0
  80. data/core/rubygems/requirement.rbs +148 -0
  81. data/core/rubygems/rubygems.rbs +1171 -0
  82. data/core/rubygems/source_list.rbs +15 -0
  83. data/core/rubygems/specification.rbs +23 -0
  84. data/core/rubygems/stream_ui.rbs +5 -0
  85. data/core/rubygems/uninstaller.rbs +10 -0
  86. data/core/rubygems/version.rbs +294 -0
  87. data/core/set.rbs +621 -0
  88. data/core/signal.rbs +100 -0
  89. data/core/string.rbs +3583 -0
  90. data/core/struct.rbs +667 -0
  91. data/core/symbol.rbs +475 -0
  92. data/core/thread.rbs +1765 -0
  93. data/core/thread_group.rbs +79 -0
  94. data/core/time.rbs +1762 -0
  95. data/core/trace_point.rbs +477 -0
  96. data/core/true_class.rbs +98 -0
  97. data/core/unbound_method.rbs +329 -0
  98. data/core/warning.rbs +87 -0
  99. data/docs/CONTRIBUTING.md +106 -0
  100. data/docs/architecture.md +110 -0
  101. data/docs/collection.md +192 -0
  102. data/docs/data_and_struct.md +86 -0
  103. data/docs/gem.md +57 -0
  104. data/docs/rbs_by_example.md +309 -0
  105. data/docs/repo.md +125 -0
  106. data/docs/sigs.md +167 -0
  107. data/docs/stdlib.md +147 -0
  108. data/docs/syntax.md +910 -0
  109. data/docs/tools.md +17 -0
  110. data/exe/rbs +7 -0
  111. data/ext/rbs_extension/extconf.rb +15 -0
  112. data/ext/rbs_extension/lexer.c +2728 -0
  113. data/ext/rbs_extension/lexer.h +179 -0
  114. data/ext/rbs_extension/lexer.re +147 -0
  115. data/ext/rbs_extension/lexstate.c +175 -0
  116. data/ext/rbs_extension/location.c +325 -0
  117. data/ext/rbs_extension/location.h +85 -0
  118. data/ext/rbs_extension/main.c +33 -0
  119. data/ext/rbs_extension/parser.c +2973 -0
  120. data/ext/rbs_extension/parser.h +18 -0
  121. data/ext/rbs_extension/parserstate.c +397 -0
  122. data/ext/rbs_extension/parserstate.h +163 -0
  123. data/ext/rbs_extension/rbs_extension.h +31 -0
  124. data/ext/rbs_extension/unescape.c +32 -0
  125. data/goodcheck.yml +91 -0
  126. data/include/rbs/constants.h +82 -0
  127. data/include/rbs/ruby_objs.h +72 -0
  128. data/include/rbs/util/rbs_constant_pool.h +219 -0
  129. data/include/rbs.h +7 -0
  130. data/lib/rbs/ancestor_graph.rb +92 -0
  131. data/lib/rbs/annotate/annotations.rb +199 -0
  132. data/lib/rbs/annotate/formatter.rb +92 -0
  133. data/lib/rbs/annotate/rdoc_annotator.rb +400 -0
  134. data/lib/rbs/annotate/rdoc_source.rb +131 -0
  135. data/lib/rbs/annotate.rb +8 -0
  136. data/lib/rbs/ast/annotation.rb +29 -0
  137. data/lib/rbs/ast/comment.rb +29 -0
  138. data/lib/rbs/ast/declarations.rb +467 -0
  139. data/lib/rbs/ast/directives.rb +49 -0
  140. data/lib/rbs/ast/members.rb +451 -0
  141. data/lib/rbs/ast/type_param.rb +225 -0
  142. data/lib/rbs/ast/visitor.rb +137 -0
  143. data/lib/rbs/buffer.rb +67 -0
  144. data/lib/rbs/builtin_names.rb +58 -0
  145. data/lib/rbs/cli/colored_io.rb +48 -0
  146. data/lib/rbs/cli/diff.rb +83 -0
  147. data/lib/rbs/cli/validate.rb +357 -0
  148. data/lib/rbs/cli.rb +1223 -0
  149. data/lib/rbs/collection/cleaner.rb +38 -0
  150. data/lib/rbs/collection/config/lockfile.rb +92 -0
  151. data/lib/rbs/collection/config/lockfile_generator.rb +218 -0
  152. data/lib/rbs/collection/config.rb +81 -0
  153. data/lib/rbs/collection/installer.rb +32 -0
  154. data/lib/rbs/collection/sources/base.rb +14 -0
  155. data/lib/rbs/collection/sources/git.rb +258 -0
  156. data/lib/rbs/collection/sources/local.rb +81 -0
  157. data/lib/rbs/collection/sources/rubygems.rb +48 -0
  158. data/lib/rbs/collection/sources/stdlib.rb +50 -0
  159. data/lib/rbs/collection/sources.rb +38 -0
  160. data/lib/rbs/collection.rb +16 -0
  161. data/lib/rbs/constant.rb +28 -0
  162. data/lib/rbs/definition.rb +401 -0
  163. data/lib/rbs/definition_builder/ancestor_builder.rb +620 -0
  164. data/lib/rbs/definition_builder/method_builder.rb +254 -0
  165. data/lib/rbs/definition_builder.rb +845 -0
  166. data/lib/rbs/diff.rb +125 -0
  167. data/lib/rbs/environment/use_map.rb +77 -0
  168. data/lib/rbs/environment.rb +829 -0
  169. data/lib/rbs/environment_loader.rb +173 -0
  170. data/lib/rbs/environment_walker.rb +155 -0
  171. data/lib/rbs/errors.rb +645 -0
  172. data/lib/rbs/factory.rb +18 -0
  173. data/lib/rbs/file_finder.rb +28 -0
  174. data/lib/rbs/location_aux.rb +138 -0
  175. data/lib/rbs/locator.rb +243 -0
  176. data/lib/rbs/method_type.rb +143 -0
  177. data/lib/rbs/namespace.rb +125 -0
  178. data/lib/rbs/parser/lex_result.rb +15 -0
  179. data/lib/rbs/parser/token.rb +23 -0
  180. data/lib/rbs/parser_aux.rb +114 -0
  181. data/lib/rbs/prototype/helpers.rb +140 -0
  182. data/lib/rbs/prototype/node_usage.rb +99 -0
  183. data/lib/rbs/prototype/rb.rb +840 -0
  184. data/lib/rbs/prototype/rbi.rb +641 -0
  185. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  186. data/lib/rbs/prototype/runtime/reflection.rb +19 -0
  187. data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
  188. data/lib/rbs/prototype/runtime.rb +667 -0
  189. data/lib/rbs/repository.rb +127 -0
  190. data/lib/rbs/resolver/constant_resolver.rb +219 -0
  191. data/lib/rbs/resolver/type_name_resolver.rb +91 -0
  192. data/lib/rbs/sorter.rb +198 -0
  193. data/lib/rbs/substitution.rb +83 -0
  194. data/lib/rbs/subtractor.rb +201 -0
  195. data/lib/rbs/test/errors.rb +80 -0
  196. data/lib/rbs/test/guaranteed.rb +30 -0
  197. data/lib/rbs/test/hook.rb +212 -0
  198. data/lib/rbs/test/observer.rb +19 -0
  199. data/lib/rbs/test/setup.rb +84 -0
  200. data/lib/rbs/test/setup_helper.rb +50 -0
  201. data/lib/rbs/test/tester.rb +167 -0
  202. data/lib/rbs/test/type_check.rb +435 -0
  203. data/lib/rbs/test.rb +112 -0
  204. data/lib/rbs/type_alias_dependency.rb +100 -0
  205. data/lib/rbs/type_alias_regularity.rb +126 -0
  206. data/lib/rbs/type_name.rb +109 -0
  207. data/lib/rbs/types.rb +1596 -0
  208. data/lib/rbs/unit_test/convertibles.rb +176 -0
  209. data/lib/rbs/unit_test/spy.rb +138 -0
  210. data/lib/rbs/unit_test/type_assertions.rb +347 -0
  211. data/lib/rbs/unit_test/with_aliases.rb +143 -0
  212. data/lib/rbs/unit_test.rb +6 -0
  213. data/lib/rbs/validator.rb +186 -0
  214. data/lib/rbs/variance_calculator.rb +189 -0
  215. data/lib/rbs/vendorer.rb +71 -0
  216. data/lib/rbs/version.rb +5 -0
  217. data/lib/rbs/writer.rb +424 -0
  218. data/lib/rbs.rb +94 -0
  219. data/lib/rdoc/discover.rb +20 -0
  220. data/lib/rdoc_plugin/parser.rb +163 -0
  221. data/rbs-relaxed.gemspec +48 -0
  222. data/schema/annotation.json +14 -0
  223. data/schema/comment.json +26 -0
  224. data/schema/decls.json +326 -0
  225. data/schema/function.json +87 -0
  226. data/schema/location.json +56 -0
  227. data/schema/members.json +266 -0
  228. data/schema/methodType.json +50 -0
  229. data/schema/typeParam.json +36 -0
  230. data/schema/types.json +317 -0
  231. data/sig/ancestor_builder.rbs +163 -0
  232. data/sig/ancestor_graph.rbs +60 -0
  233. data/sig/annotate/annotations.rbs +102 -0
  234. data/sig/annotate/formatter.rbs +24 -0
  235. data/sig/annotate/rdoc_annotater.rbs +82 -0
  236. data/sig/annotate/rdoc_source.rbs +30 -0
  237. data/sig/annotation.rbs +27 -0
  238. data/sig/buffer.rbs +32 -0
  239. data/sig/builtin_names.rbs +44 -0
  240. data/sig/cli/colored_io.rbs +15 -0
  241. data/sig/cli/diff.rbs +21 -0
  242. data/sig/cli/validate.rbs +43 -0
  243. data/sig/cli.rbs +87 -0
  244. data/sig/collection/cleaner.rbs +13 -0
  245. data/sig/collection/config/lockfile.rbs +74 -0
  246. data/sig/collection/config/lockfile_generator.rbs +66 -0
  247. data/sig/collection/config.rbs +46 -0
  248. data/sig/collection/installer.rbs +17 -0
  249. data/sig/collection/sources.rbs +214 -0
  250. data/sig/collection.rbs +4 -0
  251. data/sig/comment.rbs +26 -0
  252. data/sig/constant.rbs +21 -0
  253. data/sig/declarations.rbs +267 -0
  254. data/sig/definition.rbs +173 -0
  255. data/sig/definition_builder.rbs +165 -0
  256. data/sig/diff.rbs +28 -0
  257. data/sig/directives.rbs +77 -0
  258. data/sig/environment.rbs +279 -0
  259. data/sig/environment_loader.rbs +111 -0
  260. data/sig/environment_walker.rbs +65 -0
  261. data/sig/errors.rbs +405 -0
  262. data/sig/factory.rbs +5 -0
  263. data/sig/file_finder.rbs +28 -0
  264. data/sig/location.rbs +110 -0
  265. data/sig/locator.rbs +58 -0
  266. data/sig/manifest.yaml +7 -0
  267. data/sig/members.rbs +258 -0
  268. data/sig/method_builder.rbs +84 -0
  269. data/sig/method_types.rbs +58 -0
  270. data/sig/namespace.rbs +146 -0
  271. data/sig/parser.rbs +100 -0
  272. data/sig/prototype/helpers.rbs +27 -0
  273. data/sig/prototype/node_usage.rbs +20 -0
  274. data/sig/prototype/rb.rbs +96 -0
  275. data/sig/prototype/rbi.rbs +75 -0
  276. data/sig/prototype/runtime.rbs +182 -0
  277. data/sig/rbs.rbs +21 -0
  278. data/sig/rdoc/rbs.rbs +67 -0
  279. data/sig/repository.rbs +85 -0
  280. data/sig/resolver/constant_resolver.rbs +92 -0
  281. data/sig/resolver/context.rbs +34 -0
  282. data/sig/resolver/type_name_resolver.rbs +35 -0
  283. data/sig/shims/bundler.rbs +38 -0
  284. data/sig/shims/enumerable.rbs +5 -0
  285. data/sig/shims/rubygems.rbs +19 -0
  286. data/sig/sorter.rbs +41 -0
  287. data/sig/substitution.rbs +48 -0
  288. data/sig/subtractor.rbs +37 -0
  289. data/sig/test/errors.rbs +52 -0
  290. data/sig/test/guranteed.rbs +9 -0
  291. data/sig/test/type_check.rbs +19 -0
  292. data/sig/test.rbs +82 -0
  293. data/sig/type_alias_dependency.rbs +53 -0
  294. data/sig/type_alias_regularity.rbs +98 -0
  295. data/sig/type_param.rbs +110 -0
  296. data/sig/typename.rbs +79 -0
  297. data/sig/types.rbs +579 -0
  298. data/sig/unit_test/convertibles.rbs +154 -0
  299. data/sig/unit_test/spy.rbs +30 -0
  300. data/sig/unit_test/type_assertions.rbs +196 -0
  301. data/sig/unit_test/with_aliases.rbs +136 -0
  302. data/sig/use_map.rbs +35 -0
  303. data/sig/util.rbs +9 -0
  304. data/sig/validator.rbs +63 -0
  305. data/sig/variance_calculator.rbs +87 -0
  306. data/sig/vendorer.rbs +51 -0
  307. data/sig/version.rbs +3 -0
  308. data/sig/visitor.rbs +47 -0
  309. data/sig/writer.rbs +127 -0
  310. data/src/constants.c +153 -0
  311. data/src/ruby_objs.c +795 -0
  312. data/src/util/rbs_constant_pool.c +342 -0
  313. data/stdlib/abbrev/0/abbrev.rbs +66 -0
  314. data/stdlib/abbrev/0/array.rbs +26 -0
  315. data/stdlib/base64/0/base64.rbs +355 -0
  316. data/stdlib/benchmark/0/benchmark.rbs +452 -0
  317. data/stdlib/bigdecimal/0/big_decimal.rbs +1629 -0
  318. data/stdlib/bigdecimal-math/0/big_math.rbs +119 -0
  319. data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
  320. data/stdlib/cgi/0/core.rbs +1285 -0
  321. data/stdlib/cgi/0/manifest.yaml +3 -0
  322. data/stdlib/coverage/0/coverage.rbs +263 -0
  323. data/stdlib/csv/0/csv.rbs +3776 -0
  324. data/stdlib/csv/0/manifest.yaml +3 -0
  325. data/stdlib/date/0/date.rbs +1585 -0
  326. data/stdlib/date/0/date_time.rbs +616 -0
  327. data/stdlib/date/0/time.rbs +26 -0
  328. data/stdlib/dbm/0/dbm.rbs +421 -0
  329. data/stdlib/delegate/0/delegator.rbs +184 -0
  330. data/stdlib/delegate/0/kernel.rbs +47 -0
  331. data/stdlib/delegate/0/simple_delegator.rbs +96 -0
  332. data/stdlib/did_you_mean/0/did_you_mean.rbs +343 -0
  333. data/stdlib/digest/0/digest.rbs +577 -0
  334. data/stdlib/erb/0/erb.rbs +532 -0
  335. data/stdlib/etc/0/etc.rbs +865 -0
  336. data/stdlib/fileutils/0/fileutils.rbs +1734 -0
  337. data/stdlib/find/0/find.rbs +49 -0
  338. data/stdlib/forwardable/0/forwardable.rbs +268 -0
  339. data/stdlib/io-console/0/io-console.rbs +414 -0
  340. data/stdlib/ipaddr/0/ipaddr.rbs +428 -0
  341. data/stdlib/json/0/json.rbs +1916 -0
  342. data/stdlib/kconv/0/kconv.rbs +166 -0
  343. data/stdlib/logger/0/formatter.rbs +45 -0
  344. data/stdlib/logger/0/log_device.rbs +100 -0
  345. data/stdlib/logger/0/logger.rbs +796 -0
  346. data/stdlib/logger/0/manifest.yaml +2 -0
  347. data/stdlib/logger/0/period.rbs +17 -0
  348. data/stdlib/logger/0/severity.rbs +34 -0
  349. data/stdlib/minitest/0/kernel.rbs +42 -0
  350. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
  351. data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
  352. data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
  353. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
  354. data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
  355. data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
  356. data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
  357. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  358. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  359. data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
  360. data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
  361. data/stdlib/minitest/0/minitest/guard.rbs +64 -0
  362. data/stdlib/minitest/0/minitest/mock.rbs +64 -0
  363. data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
  364. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
  365. data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
  366. data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
  367. data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
  368. data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
  369. data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
  370. data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
  371. data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
  372. data/stdlib/minitest/0/minitest/result.rbs +28 -0
  373. data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
  374. data/stdlib/minitest/0/minitest/skip.rbs +6 -0
  375. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
  376. data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
  377. data/stdlib/minitest/0/minitest/spec.rbs +11 -0
  378. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
  379. data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
  380. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
  381. data/stdlib/minitest/0/minitest/test.rbs +69 -0
  382. data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
  383. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  384. data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
  385. data/stdlib/minitest/0/minitest/unit.rbs +4 -0
  386. data/stdlib/minitest/0/minitest.rbs +115 -0
  387. data/stdlib/monitor/0/monitor.rbs +363 -0
  388. data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
  389. data/stdlib/net-http/0/manifest.yaml +3 -0
  390. data/stdlib/net-http/0/net-http.rbs +5552 -0
  391. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  392. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  393. data/stdlib/net-smtp/0/manifest.yaml +2 -0
  394. data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
  395. data/stdlib/nkf/0/nkf.rbs +402 -0
  396. data/stdlib/objspace/0/objspace.rbs +487 -0
  397. data/stdlib/observable/0/observable.rbs +217 -0
  398. data/stdlib/open-uri/0/manifest.yaml +4 -0
  399. data/stdlib/open-uri/0/open-uri.rbs +393 -0
  400. data/stdlib/open3/0/open3.rbs +147 -0
  401. data/stdlib/openssl/0/manifest.yaml +3 -0
  402. data/stdlib/openssl/0/openssl.rbs +12113 -0
  403. data/stdlib/optparse/0/optparse.rbs +1725 -0
  404. data/stdlib/pathname/0/pathname.rbs +1406 -0
  405. data/stdlib/pp/0/manifest.yaml +2 -0
  406. data/stdlib/pp/0/pp.rbs +300 -0
  407. data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
  408. data/stdlib/pstore/0/pstore.rbs +603 -0
  409. data/stdlib/psych/0/core_ext.rbs +12 -0
  410. data/stdlib/psych/0/dbm.rbs +237 -0
  411. data/stdlib/psych/0/manifest.yaml +3 -0
  412. data/stdlib/psych/0/psych.rbs +402 -0
  413. data/stdlib/psych/0/store.rbs +59 -0
  414. data/stdlib/pty/0/pty.rbs +237 -0
  415. data/stdlib/rdoc/0/code_object.rbs +51 -0
  416. data/stdlib/rdoc/0/comment.rbs +59 -0
  417. data/stdlib/rdoc/0/context.rbs +153 -0
  418. data/stdlib/rdoc/0/markup.rbs +117 -0
  419. data/stdlib/rdoc/0/parser.rbs +56 -0
  420. data/stdlib/rdoc/0/rdoc.rbs +391 -0
  421. data/stdlib/rdoc/0/ri.rbs +17 -0
  422. data/stdlib/rdoc/0/store.rbs +48 -0
  423. data/stdlib/rdoc/0/top_level.rbs +97 -0
  424. data/stdlib/resolv/0/manifest.yaml +3 -0
  425. data/stdlib/resolv/0/resolv.rbs +1830 -0
  426. data/stdlib/ripper/0/ripper.rbs +1648 -0
  427. data/stdlib/securerandom/0/securerandom.rbs +62 -0
  428. data/stdlib/shellwords/0/shellwords.rbs +229 -0
  429. data/stdlib/singleton/0/singleton.rbs +131 -0
  430. data/stdlib/socket/0/addrinfo.rbs +666 -0
  431. data/stdlib/socket/0/basic_socket.rbs +590 -0
  432. data/stdlib/socket/0/constants.rbs +2295 -0
  433. data/stdlib/socket/0/ip_socket.rbs +92 -0
  434. data/stdlib/socket/0/socket.rbs +4157 -0
  435. data/stdlib/socket/0/socket_error.rbs +5 -0
  436. data/stdlib/socket/0/tcp_server.rbs +192 -0
  437. data/stdlib/socket/0/tcp_socket.rbs +79 -0
  438. data/stdlib/socket/0/udp_socket.rbs +133 -0
  439. data/stdlib/socket/0/unix_server.rbs +169 -0
  440. data/stdlib/socket/0/unix_socket.rbs +172 -0
  441. data/stdlib/stringio/0/stringio.rbs +567 -0
  442. data/stdlib/strscan/0/string_scanner.rbs +1627 -0
  443. data/stdlib/tempfile/0/tempfile.rbs +479 -0
  444. data/stdlib/time/0/time.rbs +432 -0
  445. data/stdlib/timeout/0/timeout.rbs +81 -0
  446. data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
  447. data/stdlib/tsort/0/cyclic.rbs +5 -0
  448. data/stdlib/tsort/0/interfaces.rbs +20 -0
  449. data/stdlib/tsort/0/tsort.rbs +409 -0
  450. data/stdlib/uri/0/common.rbs +582 -0
  451. data/stdlib/uri/0/file.rbs +118 -0
  452. data/stdlib/uri/0/ftp.rbs +13 -0
  453. data/stdlib/uri/0/generic.rbs +1108 -0
  454. data/stdlib/uri/0/http.rbs +104 -0
  455. data/stdlib/uri/0/https.rbs +14 -0
  456. data/stdlib/uri/0/ldap.rbs +230 -0
  457. data/stdlib/uri/0/ldaps.rbs +14 -0
  458. data/stdlib/uri/0/mailto.rbs +92 -0
  459. data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
  460. data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
  461. data/stdlib/uri/0/ws.rbs +13 -0
  462. data/stdlib/uri/0/wss.rbs +9 -0
  463. data/stdlib/yaml/0/manifest.yaml +2 -0
  464. data/stdlib/yaml/0/yaml.rbs +1 -0
  465. data/stdlib/zlib/0/buf_error.rbs +10 -0
  466. data/stdlib/zlib/0/data_error.rbs +10 -0
  467. data/stdlib/zlib/0/deflate.rbs +210 -0
  468. data/stdlib/zlib/0/error.rbs +20 -0
  469. data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
  470. data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
  471. data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
  472. data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
  473. data/stdlib/zlib/0/gzip_file.rbs +156 -0
  474. data/stdlib/zlib/0/gzip_reader.rbs +293 -0
  475. data/stdlib/zlib/0/gzip_writer.rbs +166 -0
  476. data/stdlib/zlib/0/inflate.rbs +180 -0
  477. data/stdlib/zlib/0/mem_error.rbs +10 -0
  478. data/stdlib/zlib/0/need_dict.rbs +13 -0
  479. data/stdlib/zlib/0/stream_end.rbs +11 -0
  480. data/stdlib/zlib/0/stream_error.rbs +11 -0
  481. data/stdlib/zlib/0/version_error.rbs +11 -0
  482. data/stdlib/zlib/0/zlib.rbs +449 -0
  483. data/stdlib/zlib/0/zstream.rbs +200 -0
  484. metadata +532 -0
data/core/regexp.rbs ADDED
@@ -0,0 +1,1930 @@
1
+ # <!-- rdoc-file=re.c -->
2
+ # A [regular expression](https://en.wikipedia.org/wiki/Regular_expression) (also
3
+ # called a *regexp*) is a *match pattern* (also simply called a *pattern*).
4
+ #
5
+ # A common notation for a regexp uses enclosing slash characters:
6
+ #
7
+ # /foo/
8
+ #
9
+ # A regexp may be applied to a *target string*; The part of the string (if any)
10
+ # that matches the pattern is called a *match*, and may be said *to match*:
11
+ #
12
+ # re = /red/
13
+ # re.match?('redirect') # => true # Match at beginning of target.
14
+ # re.match?('bored') # => true # Match at end of target.
15
+ # re.match?('credit') # => true # Match within target.
16
+ # re.match?('foo') # => false # No match.
17
+ #
18
+ # ## Regexp Uses
19
+ #
20
+ # A regexp may be used:
21
+ #
22
+ # * To extract substrings based on a given pattern:
23
+ #
24
+ # re = /foo/ # => /foo/
25
+ # re.match('food') # => #<MatchData "foo">
26
+ # re.match('good') # => nil
27
+ #
28
+ # See sections [Method match](rdoc-ref:Regexp@Method+match) and [Operator
29
+ # =~](rdoc-ref:Regexp@Operator+-3D~).
30
+ #
31
+ # * To determine whether a string matches a given pattern:
32
+ #
33
+ # re.match?('food') # => true
34
+ # re.match?('good') # => false
35
+ #
36
+ # See section [Method match?](rdoc-ref:Regexp@Method+match-3F).
37
+ #
38
+ # * As an argument for calls to certain methods in other classes and modules;
39
+ # most such methods accept an argument that may be either a string or the
40
+ # (much more powerful) regexp.
41
+ #
42
+ # See [Regexp Methods](rdoc-ref:regexp/methods.rdoc).
43
+ #
44
+ # ## Regexp Objects
45
+ #
46
+ # A regexp object has:
47
+ #
48
+ # * A source; see [Sources](rdoc-ref:Regexp@Sources).
49
+ #
50
+ # * Several modes; see [Modes](rdoc-ref:Regexp@Modes).
51
+ #
52
+ # * A timeout; see [Timeouts](rdoc-ref:Regexp@Timeouts).
53
+ #
54
+ # * An encoding; see [Encodings](rdoc-ref:Regexp@Encodings).
55
+ #
56
+ # ## Creating a Regexp
57
+ #
58
+ # A regular expression may be created with:
59
+ #
60
+ # * A regexp literal using slash characters (see [Regexp
61
+ # Literals](rdoc-ref:syntax/literals.rdoc@Regexp+Literals)):
62
+ #
63
+ # # This is a very common usage.
64
+ # /foo/ # => /foo/
65
+ #
66
+ # * A `%r` regexp literal (see [%r: Regexp
67
+ # Literals](rdoc-ref:syntax/literals.rdoc@25r-3A+Regexp+Literals)):
68
+ #
69
+ # # Same delimiter character at beginning and end;
70
+ # # useful for avoiding escaping characters
71
+ # %r/name\/value pair/ # => /name\/value pair/
72
+ # %r:name/value pair: # => /name\/value pair/
73
+ # %r|name/value pair| # => /name\/value pair/
74
+ #
75
+ # # Certain "paired" characters can be delimiters.
76
+ # %r[foo] # => /foo/
77
+ # %r{foo} # => /foo/
78
+ # %r(foo) # => /foo/
79
+ # %r<foo> # => /foo/
80
+ #
81
+ # * Method Regexp.new.
82
+ #
83
+ # ## Method `match`
84
+ #
85
+ # Each of the methods Regexp#match, String#match, and Symbol#match returns a
86
+ # MatchData object if a match was found, `nil` otherwise; each also sets [global
87
+ # variables](rdoc-ref:Regexp@Global+Variables):
88
+ #
89
+ # 'food'.match(/foo/) # => #<MatchData "foo">
90
+ # 'food'.match(/bar/) # => nil
91
+ #
92
+ # ## Operator `=~`
93
+ #
94
+ # Each of the operators Regexp#=~, String#=~, and Symbol#=~ returns an integer
95
+ # offset if a match was found, `nil` otherwise; each also sets [global
96
+ # variables](rdoc-ref:Regexp@Global+Variables):
97
+ #
98
+ # /bar/ =~ 'foo bar' # => 4
99
+ # 'foo bar' =~ /bar/ # => 4
100
+ # /baz/ =~ 'foo bar' # => nil
101
+ #
102
+ # ## Method `match?`
103
+ #
104
+ # Each of the methods Regexp#match?, String#match?, and Symbol#match? returns
105
+ # `true` if a match was found, `false` otherwise; none sets [global
106
+ # variables](rdoc-ref:Regexp@Global+Variables):
107
+ #
108
+ # 'food'.match?(/foo/) # => true
109
+ # 'food'.match?(/bar/) # => false
110
+ #
111
+ # ## Global Variables
112
+ #
113
+ # Certain regexp-oriented methods assign values to global variables:
114
+ #
115
+ # * `#match`: see [Method match](rdoc-ref:Regexp@Method+match).
116
+ # * `#=~`: see [Operator =~](rdoc-ref:Regexp@Operator+-3D~).
117
+ #
118
+ # The affected global variables are:
119
+ #
120
+ # * `$~`: Returns a MatchData object, or `nil`.
121
+ # * `$&`: Returns the matched part of the string, or `nil`.
122
+ # * `$``: Returns the part of the string to the left of the match, or `nil`.
123
+ # * `$'`: Returns the part of the string to the right of the match, or `nil`.
124
+ # * `$+`: Returns the last group matched, or `nil`.
125
+ # * `$1`, `$2`, etc.: Returns the first, second, etc., matched group, or
126
+ # `nil`. Note that `$0` is quite different; it returns the name of the
127
+ # currently executing program.
128
+ #
129
+ # Examples:
130
+ #
131
+ # # Matched string, but no matched groups.
132
+ # 'foo bar bar baz'.match('bar')
133
+ # $~ # => #<MatchData "bar">
134
+ # $& # => "bar"
135
+ # $` # => "foo "
136
+ # $' # => " bar baz"
137
+ # $+ # => nil
138
+ # $1 # => nil
139
+ #
140
+ # # Matched groups.
141
+ # /s(\w{2}).*(c)/.match('haystack')
142
+ # $~ # => #<MatchData "stac" 1:"ta" 2:"c">
143
+ # $& # => "stac"
144
+ # $` # => "hay"
145
+ # $' # => "k"
146
+ # $+ # => "c"
147
+ # $1 # => "ta"
148
+ # $2 # => "c"
149
+ # $3 # => nil
150
+ #
151
+ # # No match.
152
+ # 'foo'.match('bar')
153
+ # $~ # => nil
154
+ # $& # => nil
155
+ # $` # => nil
156
+ # $' # => nil
157
+ # $+ # => nil
158
+ # $1 # => nil
159
+ #
160
+ # Note that Regexp#match?, String#match?, and Symbol#match? do not set global
161
+ # variables.
162
+ #
163
+ # ## Sources
164
+ #
165
+ # As seen above, the simplest regexp uses a literal expression as its source:
166
+ #
167
+ # re = /foo/ # => /foo/
168
+ # re.match('food') # => #<MatchData "foo">
169
+ # re.match('good') # => nil
170
+ #
171
+ # A rich collection of available *subexpressions* gives the regexp great power
172
+ # and flexibility:
173
+ #
174
+ # * [Special characters](rdoc-ref:Regexp@Special+Characters)
175
+ # * [Source literals](rdoc-ref:Regexp@Source+Literals)
176
+ # * [Character classes](rdoc-ref:Regexp@Character+Classes)
177
+ # * [Shorthand character classes](rdoc-ref:Regexp@Shorthand+Character+Classes)
178
+ # * [Anchors](rdoc-ref:Regexp@Anchors)
179
+ # * [Alternation](rdoc-ref:Regexp@Alternation)
180
+ # * [Quantifiers](rdoc-ref:Regexp@Quantifiers)
181
+ # * [Groups and captures](rdoc-ref:Regexp@Groups+and+Captures)
182
+ # * [Unicode](rdoc-ref:Regexp@Unicode)
183
+ # * [POSIX Bracket Expressions](rdoc-ref:Regexp@POSIX+Bracket+Expressions)
184
+ # * [Comments](rdoc-ref:Regexp@Comments)
185
+ #
186
+ # ### Special Characters
187
+ #
188
+ # Regexp special characters, called *metacharacters*, have special meanings in
189
+ # certain contexts; depending on the context, these are sometimes
190
+ # metacharacters:
191
+ #
192
+ # . ? - + * ^ \ | $ ( ) [ ] { }
193
+ #
194
+ # To match a metacharacter literally, backslash-escape it:
195
+ #
196
+ # # Matches one or more 'o' characters.
197
+ # /o+/.match('foo') # => #<MatchData "oo">
198
+ # # Would match 'o+'.
199
+ # /o\+/.match('foo') # => nil
200
+ #
201
+ # To match a backslash literally, backslash-escape it:
202
+ #
203
+ # /\./.match('\.') # => #<MatchData ".">
204
+ # /\\./.match('\.') # => #<MatchData "\\.">
205
+ #
206
+ # Method Regexp.escape returns an escaped string:
207
+ #
208
+ # Regexp.escape('.?-+*^\|$()[]{}')
209
+ # # => "\\.\\?\\-\\+\\*\\^\\\\\\|\\$\\(\\)\\[\\]\\{\\}"
210
+ #
211
+ # ### Source Literals
212
+ #
213
+ # The source literal largely behaves like a double-quoted string; see
214
+ # [Double-Quoted String
215
+ # Literals](rdoc-ref:syntax/literals.rdoc@Double-Quoted+String+Literals).
216
+ #
217
+ # In particular, a source literal may contain interpolated expressions:
218
+ #
219
+ # s = 'foo' # => "foo"
220
+ # /#{s}/ # => /foo/
221
+ # /#{s.capitalize}/ # => /Foo/
222
+ # /#{2 + 2}/ # => /4/
223
+ #
224
+ # There are differences between an ordinary string literal and a source literal;
225
+ # see [Shorthand Character
226
+ # Classes](rdoc-ref:Regexp@Shorthand+Character+Classes).
227
+ #
228
+ # * `\s` in an ordinary string literal is equivalent to a space character; in
229
+ # a source literal, it's shorthand for matching a whitespace character.
230
+ # * In an ordinary string literal, these are (needlessly) escaped characters;
231
+ # in a source literal, they are shorthands for various matching characters:
232
+ #
233
+ # \w \W \d \D \h \H \S \R
234
+ #
235
+ # ### Character Classes
236
+ #
237
+ # A *character class* is delimited by square brackets; it specifies that certain
238
+ # characters match at a given point in the target string:
239
+ #
240
+ # # This character class will match any vowel.
241
+ # re = /B[aeiou]rd/
242
+ # re.match('Bird') # => #<MatchData "Bird">
243
+ # re.match('Bard') # => #<MatchData "Bard">
244
+ # re.match('Byrd') # => nil
245
+ #
246
+ # A character class may contain hyphen characters to specify ranges of
247
+ # characters:
248
+ #
249
+ # # These regexps have the same effect.
250
+ # /[abcdef]/.match('foo') # => #<MatchData "f">
251
+ # /[a-f]/.match('foo') # => #<MatchData "f">
252
+ # /[a-cd-f]/.match('foo') # => #<MatchData "f">
253
+ #
254
+ # When the first character of a character class is a caret (`^`), the sense of
255
+ # the class is inverted: it matches any character *except* those specified.
256
+ #
257
+ # /[^a-eg-z]/.match('f') # => #<MatchData "f">
258
+ #
259
+ # A character class may contain another character class. By itself this isn't
260
+ # useful because `[a-z[0-9]]` describes the same set as `[a-z0-9]`.
261
+ #
262
+ # However, character classes also support the `&&` operator, which performs set
263
+ # intersection on its arguments. The two can be combined as follows:
264
+ #
265
+ # /[a-w&&[^c-g]z]/ # ([a-w] AND ([^c-g] OR z))
266
+ #
267
+ # This is equivalent to:
268
+ #
269
+ # /[abh-w]/
270
+ #
271
+ # ### Shorthand Character Classes
272
+ #
273
+ # Each of the following metacharacters serves as a shorthand for a character
274
+ # class:
275
+ #
276
+ # * `/./`: Matches any character except a newline:
277
+ #
278
+ # /./.match('foo') # => #<MatchData "f">
279
+ # /./.match("\n") # => nil
280
+ #
281
+ # * `/./m`: Matches any character, including a newline; see [Multiline
282
+ # Mode](rdoc-ref:Regexp@Multiline+Mode):
283
+ #
284
+ # /./m.match("\n") # => #<MatchData "\n">
285
+ #
286
+ # * `/\w/`: Matches a word character: equivalent to `[a-zA-Z0-9_]`:
287
+ #
288
+ # /\w/.match(' foo') # => #<MatchData "f">
289
+ # /\w/.match(' _') # => #<MatchData "_">
290
+ # /\w/.match(' ') # => nil
291
+ #
292
+ # * `/\W/`: Matches a non-word character: equivalent to `[^a-zA-Z0-9_]`:
293
+ #
294
+ # /\W/.match(' ') # => #<MatchData " ">
295
+ # /\W/.match('_') # => nil
296
+ #
297
+ # * `/\d/`: Matches a digit character: equivalent to `[0-9]`:
298
+ #
299
+ # /\d/.match('THX1138') # => #<MatchData "1">
300
+ # /\d/.match('foo') # => nil
301
+ #
302
+ # * `/\D/`: Matches a non-digit character: equivalent to `[^0-9]`:
303
+ #
304
+ # /\D/.match('123Jump!') # => #<MatchData "J">
305
+ # /\D/.match('123') # => nil
306
+ #
307
+ # * `/\h/`: Matches a hexdigit character: equivalent to `[0-9a-fA-F]`:
308
+ #
309
+ # /\h/.match('xyz fedcba9876543210') # => #<MatchData "f">
310
+ # /\h/.match('xyz') # => nil
311
+ #
312
+ # * `/\H/`: Matches a non-hexdigit character: equivalent to `[^0-9a-fA-F]`:
313
+ #
314
+ # /\H/.match('fedcba9876543210xyz') # => #<MatchData "x">
315
+ # /\H/.match('fedcba9876543210') # => nil
316
+ #
317
+ # * `/\s/`: Matches a whitespace character: equivalent to `/[ \t\r\n\f\v]/`:
318
+ #
319
+ # /\s/.match('foo bar') # => #<MatchData " ">
320
+ # /\s/.match('foo') # => nil
321
+ #
322
+ # * `/\S/`: Matches a non-whitespace character: equivalent to `/[^
323
+ # \t\r\n\f\v]/`:
324
+ #
325
+ # /\S/.match(" \t\r\n\f\v foo") # => #<MatchData "f">
326
+ # /\S/.match(" \t\r\n\f\v") # => nil
327
+ #
328
+ # * `/\R/`: Matches a linebreak, platform-independently:
329
+ #
330
+ # /\R/.match("\r") # => #<MatchData "\r"> # Carriage return (CR)
331
+ # /\R/.match("\n") # => #<MatchData "\n"> # Newline (LF)
332
+ # /\R/.match("\f") # => #<MatchData "\f"> # Formfeed (FF)
333
+ # /\R/.match("\v") # => #<MatchData "\v"> # Vertical tab (VT)
334
+ # /\R/.match("\r\n") # => #<MatchData "\r\n"> # CRLF
335
+ # /\R/.match("\u0085") # => #<MatchData "\u0085"> # Next line (NEL)
336
+ # /\R/.match("\u2028") # => #<MatchData "\u2028"> # Line separator (LSEP)
337
+ # /\R/.match("\u2029") # => #<MatchData "\u2029"> # Paragraph separator (PSEP)
338
+ #
339
+ # ### Anchors
340
+ #
341
+ # An anchor is a metasequence that matches a zero-width position between
342
+ # characters in the target string.
343
+ #
344
+ # For a subexpression with no anchor, matching may begin anywhere in the target
345
+ # string:
346
+ #
347
+ # /real/.match('surrealist') # => #<MatchData "real">
348
+ #
349
+ # For a subexpression with an anchor, matching must begin at the matched anchor.
350
+ #
351
+ # #### Boundary Anchors
352
+ #
353
+ # Each of these anchors matches a boundary:
354
+ #
355
+ # * `^`: Matches the beginning of a line:
356
+ #
357
+ # /^bar/.match("foo\nbar") # => #<MatchData "bar">
358
+ # /^ar/.match("foo\nbar") # => nil
359
+ #
360
+ # * `$`: Matches the end of a line:
361
+ #
362
+ # /bar$/.match("foo\nbar") # => #<MatchData "bar">
363
+ # /ba$/.match("foo\nbar") # => nil
364
+ #
365
+ # * `\A`: Matches the beginning of the string:
366
+ #
367
+ # /\Afoo/.match('foo bar') # => #<MatchData "foo">
368
+ # /\Afoo/.match(' foo bar') # => nil
369
+ #
370
+ # * `\Z`: Matches the end of the string; if string ends with a single newline,
371
+ # it matches just before the ending newline:
372
+ #
373
+ # /foo\Z/.match('bar foo') # => #<MatchData "foo">
374
+ # /foo\Z/.match('foo bar') # => nil
375
+ # /foo\Z/.match("bar foo\n") # => #<MatchData "foo">
376
+ # /foo\Z/.match("bar foo\n\n") # => nil
377
+ #
378
+ # * `\z`: Matches the end of the string:
379
+ #
380
+ # /foo\z/.match('bar foo') # => #<MatchData "foo">
381
+ # /foo\z/.match('foo bar') # => nil
382
+ # /foo\z/.match("bar foo\n") # => nil
383
+ #
384
+ # * `\b`: Matches word boundary when not inside brackets; matches backspace
385
+ # (`"0x08"`) when inside brackets:
386
+ #
387
+ # /foo\b/.match('foo bar') # => #<MatchData "foo">
388
+ # /foo\b/.match('foobar') # => nil
389
+ #
390
+ # * `\B`: Matches non-word boundary:
391
+ #
392
+ # /foo\B/.match('foobar') # => #<MatchData "foo">
393
+ # /foo\B/.match('foo bar') # => nil
394
+ #
395
+ # * `\G`: Matches first matching position:
396
+ #
397
+ # In methods like String#gsub and String#scan, it changes on each iteration.
398
+ # It initially matches the beginning of subject, and in each following
399
+ # iteration it matches where the last match finished.
400
+ #
401
+ # " a b c".gsub(/ /, '_') # => "____a_b_c"
402
+ # " a b c".gsub(/\G /, '_') # => "____a b c"
403
+ #
404
+ # In methods like Regexp#match and String#match that take an optional
405
+ # offset, it matches where the search begins.
406
+ #
407
+ # "hello, world".match(/,/, 3) # => #<MatchData ",">
408
+ # "hello, world".match(/\G,/, 3) # => nil
409
+ #
410
+ # #### Lookaround Anchors
411
+ #
412
+ # Lookahead anchors:
413
+ #
414
+ # * `(?=*pat*)`: Positive lookahead assertion: ensures that the following
415
+ # characters match *pat*, but doesn't include those characters in the
416
+ # matched substring.
417
+ #
418
+ # * `(?!*pat*)`: Negative lookahead assertion: ensures that the following
419
+ # characters *do not* match *pat*, but doesn't include those characters in
420
+ # the matched substring.
421
+ #
422
+ # Lookbehind anchors:
423
+ #
424
+ # * `(?<=*pat*)`: Positive lookbehind assertion: ensures that the preceding
425
+ # characters match *pat*, but doesn't include those characters in the
426
+ # matched substring.
427
+ #
428
+ # * `(?<!*pat*)`: Negative lookbehind assertion: ensures that the preceding
429
+ # characters do not match *pat*, but doesn't include those characters in the
430
+ # matched substring.
431
+ #
432
+ # The pattern below uses positive lookahead and positive lookbehind to match
433
+ # text appearing in **...** tags without including the tags in the match:
434
+ #
435
+ # /(?<=<b>)\w+(?=<\/b>)/.match("Fortune favors the <b>bold</b>.")
436
+ # # => #<MatchData "bold">
437
+ #
438
+ # #### Match-Reset Anchor
439
+ #
440
+ # * `\K`: Match reset: the matched content preceding `\K` in the regexp is
441
+ # excluded from the result. For example, the following two regexps are
442
+ # almost equivalent:
443
+ #
444
+ # /ab\Kc/.match('abc') # => #<MatchData "c">
445
+ # /(?<=ab)c/.match('abc') # => #<MatchData "c">
446
+ #
447
+ # These match same string and `$&` equals `'c'`, while the matched position
448
+ # is different.
449
+ #
450
+ # As are the following two regexps:
451
+ #
452
+ # /(a)\K(b)\Kc/
453
+ # /(?<=(?<=(a))(b))c/
454
+ #
455
+ # ### Alternation
456
+ #
457
+ # The vertical bar metacharacter (`|`) may be used within parentheses to express
458
+ # alternation: two or more subexpressions any of which may match the target
459
+ # string.
460
+ #
461
+ # Two alternatives:
462
+ #
463
+ # re = /(a|b)/
464
+ # re.match('foo') # => nil
465
+ # re.match('bar') # => #<MatchData "b" 1:"b">
466
+ #
467
+ # Four alternatives:
468
+ #
469
+ # re = /(a|b|c|d)/
470
+ # re.match('shazam') # => #<MatchData "a" 1:"a">
471
+ # re.match('cold') # => #<MatchData "c" 1:"c">
472
+ #
473
+ # Each alternative is a subexpression, and may be composed of other
474
+ # subexpressions:
475
+ #
476
+ # re = /([a-c]|[x-z])/
477
+ # re.match('bar') # => #<MatchData "b" 1:"b">
478
+ # re.match('ooz') # => #<MatchData "z" 1:"z">
479
+ #
480
+ # Method Regexp.union provides a convenient way to construct a regexp with
481
+ # alternatives.
482
+ #
483
+ # ### Quantifiers
484
+ #
485
+ # A simple regexp matches one character:
486
+ #
487
+ # /\w/.match('Hello') # => #<MatchData "H">
488
+ #
489
+ # An added *quantifier* specifies how many matches are required or allowed:
490
+ #
491
+ # * `*` - Matches zero or more times:
492
+ #
493
+ # /\w*/.match('')
494
+ # # => #<MatchData "">
495
+ # /\w*/.match('x')
496
+ # # => #<MatchData "x">
497
+ # /\w*/.match('xyz')
498
+ # # => #<MatchData "yz">
499
+ #
500
+ # * `+` - Matches one or more times:
501
+ #
502
+ # /\w+/.match('') # => nil
503
+ # /\w+/.match('x') # => #<MatchData "x">
504
+ # /\w+/.match('xyz') # => #<MatchData "xyz">
505
+ #
506
+ # * `?` - Matches zero or one times:
507
+ #
508
+ # /\w?/.match('') # => #<MatchData "">
509
+ # /\w?/.match('x') # => #<MatchData "x">
510
+ # /\w?/.match('xyz') # => #<MatchData "x">
511
+ #
512
+ # * `{`*n*`}` - Matches exactly *n* times:
513
+ #
514
+ # /\w{2}/.match('') # => nil
515
+ # /\w{2}/.match('x') # => nil
516
+ # /\w{2}/.match('xyz') # => #<MatchData "xy">
517
+ #
518
+ # * `{`*min*`,}` - Matches *min* or more times:
519
+ #
520
+ # /\w{2,}/.match('') # => nil
521
+ # /\w{2,}/.match('x') # => nil
522
+ # /\w{2,}/.match('xy') # => #<MatchData "xy">
523
+ # /\w{2,}/.match('xyz') # => #<MatchData "xyz">
524
+ #
525
+ # * `{,`*max*`}` - Matches *max* or fewer times:
526
+ #
527
+ # /\w{,2}/.match('') # => #<MatchData "">
528
+ # /\w{,2}/.match('x') # => #<MatchData "x">
529
+ # /\w{,2}/.match('xyz') # => #<MatchData "xy">
530
+ #
531
+ # * `{`*min*`,`*max*`}` - Matches at least *min* times and at most *max*
532
+ # times:
533
+ #
534
+ # /\w{1,2}/.match('') # => nil
535
+ # /\w{1,2}/.match('x') # => #<MatchData "x">
536
+ # /\w{1,2}/.match('xyz') # => #<MatchData "xy">
537
+ #
538
+ # #### Greedy, Lazy, or Possessive Matching
539
+ #
540
+ # Quantifier matching may be greedy, lazy, or possessive:
541
+ #
542
+ # * In *greedy* matching, as many occurrences as possible are matched while
543
+ # still allowing the overall match to succeed. Greedy quantifiers: `*`, `+`,
544
+ # `?`, `{min, max}` and its variants.
545
+ # * In *lazy* matching, the minimum number of occurrences are matched. Lazy
546
+ # quantifiers: `*?`, `+?`, `??`, `{min, max}?` and its variants.
547
+ # * In *possessive* matching, once a match is found, there is no backtracking;
548
+ # that match is retained, even if it jeopardises the overall match.
549
+ # Possessive quantifiers: `*+`, `++`, `?+`. Note that `{min, max}` and its
550
+ # variants do *not* support possessive matching.
551
+ #
552
+ # More:
553
+ #
554
+ # * About greedy and lazy matching, see [Choosing Minimal or Maximal
555
+ # Repetition](https://doc.lagout.org/programmation/Regular%20Expressions/Reg
556
+ # ular%20Expressions%20Cookbook_%20Detailed%20Solutions%20in%20Eight%20Progr
557
+ # amming%20Languages%20%282nd%20ed.%29%20%5BGoyvaerts%20%26%20Levithan%20201
558
+ # 2-09-06%5D.pdf#tutorial-backtrack).
559
+ # * About possessive matching, see [Eliminate Needless
560
+ # Backtracking](https://doc.lagout.org/programmation/Regular%20Expressions/R
561
+ # egular%20Expressions%20Cookbook_%20Detailed%20Solutions%20in%20Eight%20Pro
562
+ # gramming%20Languages%20%282nd%20ed.%29%20%5BGoyvaerts%20%26%20Levithan%202
563
+ # 012-09-06%5D.pdf#tutorial-backtrack).
564
+ #
565
+ # ### Groups and Captures
566
+ #
567
+ # A simple regexp has (at most) one match:
568
+ #
569
+ # re = /\d\d\d\d-\d\d-\d\d/
570
+ # re.match('1943-02-04') # => #<MatchData "1943-02-04">
571
+ # re.match('1943-02-04').size # => 1
572
+ # re.match('foo') # => nil
573
+ #
574
+ # Adding one or more pairs of parentheses, `(*subexpression*)`, defines
575
+ # *groups*, which may result in multiple matched substrings, called *captures*:
576
+ #
577
+ # re = /(\d\d\d\d)-(\d\d)-(\d\d)/
578
+ # re.match('1943-02-04') # => #<MatchData "1943-02-04" 1:"1943" 2:"02" 3:"04">
579
+ # re.match('1943-02-04').size # => 4
580
+ #
581
+ # The first capture is the entire matched string; the other captures are the
582
+ # matched substrings from the groups.
583
+ #
584
+ # A group may have a [quantifier](rdoc-ref:Regexp@Quantifiers):
585
+ #
586
+ # re = /July 4(th)?/
587
+ # re.match('July 4') # => #<MatchData "July 4" 1:nil>
588
+ # re.match('July 4th') # => #<MatchData "July 4th" 1:"th">
589
+ #
590
+ # re = /(foo)*/
591
+ # re.match('') # => #<MatchData "" 1:nil>
592
+ # re.match('foo') # => #<MatchData "foo" 1:"foo">
593
+ # re.match('foofoo') # => #<MatchData "foofoo" 1:"foo">
594
+ #
595
+ # re = /(foo)+/
596
+ # re.match('') # => nil
597
+ # re.match('foo') # => #<MatchData "foo" 1:"foo">
598
+ # re.match('foofoo') # => #<MatchData "foofoo" 1:"foo">
599
+ #
600
+ # The returned MatchData object gives access to the matched substrings:
601
+ #
602
+ # re = /(\d\d\d\d)-(\d\d)-(\d\d)/
603
+ # md = re.match('1943-02-04')
604
+ # # => #<MatchData "1943-02-04" 1:"1943" 2:"02" 3:"04">
605
+ # md[0] # => "1943-02-04"
606
+ # md[1] # => "1943"
607
+ # md[2] # => "02"
608
+ # md[3] # => "04"
609
+ #
610
+ # #### Non-Capturing Groups
611
+ #
612
+ # A group may be made non-capturing; it is still a group (and, for example, can
613
+ # have a quantifier), but its matching substring is not included among the
614
+ # captures.
615
+ #
616
+ # A non-capturing group begins with `?:` (inside the parentheses):
617
+ #
618
+ # # Don't capture the year.
619
+ # re = /(?:\d\d\d\d)-(\d\d)-(\d\d)/
620
+ # md = re.match('1943-02-04') # => #<MatchData "1943-02-04" 1:"02" 2:"04">
621
+ #
622
+ # #### Backreferences
623
+ #
624
+ # A group match may also be referenced within the regexp itself; such a
625
+ # reference is called a `backreference`:
626
+ #
627
+ # /[csh](..) [csh]\1 in/.match('The cat sat in the hat')
628
+ # # => #<MatchData "cat sat in" 1:"at">
629
+ #
630
+ # This table shows how each subexpression in the regexp above matches a
631
+ # substring in the target string:
632
+ #
633
+ # | Subexpression in Regexp | Matching Substring in Target String |
634
+ # |---------------------------|-------------------------------------|
635
+ # | First '[csh]' | Character 'c' |
636
+ # | '(..)' | First substring 'at' |
637
+ # | First space ' ' | First space character ' ' |
638
+ # | Second '[csh]' | Character 's' |
639
+ # | '\1' (backreference 'at') | Second substring 'at' |
640
+ # | ' in' | Substring ' in' |
641
+ #
642
+ # A regexp may contain any number of groups:
643
+ #
644
+ # * For a large number of groups:
645
+ #
646
+ # * The ordinary `\*n`* notation applies only for *n* in range (1..9).
647
+ # * The `MatchData[*n*]` notation applies for any non-negative *n*.
648
+ #
649
+ # * `\0` is a special backreference, referring to the entire matched string;
650
+ # it may not be used within the regexp itself, but may be used outside it
651
+ # (for example, in a substitution method call):
652
+ #
653
+ # 'The cat sat in the hat'.gsub(/[csh]at/, '\0s')
654
+ # # => "The cats sats in the hats"
655
+ #
656
+ # #### Named Captures
657
+ #
658
+ # As seen above, a capture can be referred to by its number. A capture can also
659
+ # have a name, prefixed as `?<*name*>` or `?'*name*'`, and the name (symbolized)
660
+ # may be used as an index in `MatchData[]`:
661
+ #
662
+ # md = /\$(?<dollars>\d+)\.(?'cents'\d+)/.match("$3.67")
663
+ # # => #<MatchData "$3.67" dollars:"3" cents:"67">
664
+ # md[:dollars] # => "3"
665
+ # md[:cents] # => "67"
666
+ # # The capture numbers are still valid.
667
+ # md[2] # => "67"
668
+ #
669
+ # When a regexp contains a named capture, there are no unnamed captures:
670
+ #
671
+ # /\$(?<dollars>\d+)\.(\d+)/.match("$3.67")
672
+ # # => #<MatchData "$3.67" dollars:"3">
673
+ #
674
+ # A named group may be backreferenced as `\k<*name*>`:
675
+ #
676
+ # /(?<vowel>[aeiou]).\k<vowel>.\k<vowel>/.match('ototomy')
677
+ # # => #<MatchData "ototo" vowel:"o">
678
+ #
679
+ # When (and only when) a regexp contains named capture groups and appears before
680
+ # the `=~` operator, the captured substrings are assigned to local variables
681
+ # with corresponding names:
682
+ #
683
+ # /\$(?<dollars>\d+)\.(?<cents>\d+)/ =~ '$3.67'
684
+ # dollars # => "3"
685
+ # cents # => "67"
686
+ #
687
+ # Method Regexp#named_captures returns a hash of the capture names and
688
+ # substrings; method Regexp#names returns an array of the capture names.
689
+ #
690
+ # #### Atomic Grouping
691
+ #
692
+ # A group may be made *atomic* with `(?>`*subexpression*`)`.
693
+ #
694
+ # This causes the subexpression to be matched independently of the rest of the
695
+ # expression, so that the matched substring becomes fixed for the remainder of
696
+ # the match, unless the entire subexpression must be abandoned and subsequently
697
+ # revisited.
698
+ #
699
+ # In this way *subexpression* is treated as a non-divisible whole. Atomic
700
+ # grouping is typically used to optimise patterns to prevent needless
701
+ # backtracking .
702
+ #
703
+ # Example (without atomic grouping):
704
+ #
705
+ # /".*"/.match('"Quote"') # => #<MatchData "\"Quote\"">
706
+ #
707
+ # Analysis:
708
+ #
709
+ # 1. The leading subexpression `"` in the pattern matches the first character
710
+ # `"` in the target string.
711
+ # 2. The next subexpression `.*` matches the next substring `Quote“` (including
712
+ # the trailing double-quote).
713
+ # 3. Now there is nothing left in the target string to match the trailing
714
+ # subexpression `"` in the pattern; this would cause the overall match to
715
+ # fail.
716
+ # 4. The matched substring is backtracked by one position: `Quote`.
717
+ # 5. The final subexpression `"` now matches the final substring `"`, and the
718
+ # overall match succeeds.
719
+ #
720
+ # If subexpression `.*` is grouped atomically, the backtracking is disabled, and
721
+ # the overall match fails:
722
+ #
723
+ # /"(?>.*)"/.match('"Quote"') # => nil
724
+ #
725
+ # Atomic grouping can affect performance; see [Atomic
726
+ # Group](https://www.regular-expressions.info/atomic.html).
727
+ #
728
+ # #### Subexpression Calls
729
+ #
730
+ # As seen above, a backreference number (`\*n`*) or name (`\k<*name*>`) gives
731
+ # access to a captured *substring*; the corresponding regexp *subexpression* may
732
+ # also be accessed, via the number (`\\g*n`*) or name (`\g<*name*>`):
733
+ #
734
+ # /\A(?<paren>\(\g<paren>*\))*\z/.match('(())')
735
+ # # ^1
736
+ # # ^2
737
+ # # ^3
738
+ # # ^4
739
+ # # ^5
740
+ # # ^6
741
+ # # ^7
742
+ # # ^8
743
+ # # ^9
744
+ # # ^10
745
+ #
746
+ # The pattern:
747
+ #
748
+ # 1. Matches at the beginning of the string, i.e. before the first character.
749
+ # 2. Enters a named group `paren`.
750
+ # 3. Matches the first character in the string, `'('`.
751
+ # 4. Calls the `paren` group again, i.e. recurses back to the second step.
752
+ # 5. Re-enters the `paren` group.
753
+ # 6. Matches the second character in the string, `'('`.
754
+ # 7. Attempts to call `paren` a third time, but fails because doing so would
755
+ # prevent an overall successful match.
756
+ # 8. Matches the third character in the string, `')'`; marks the end of the
757
+ # second recursive call
758
+ # 9. Matches the fourth character in the string, `')'`.
759
+ # 10. Matches the end of the string.
760
+ #
761
+ # See [Subexpression
762
+ # calls](https://learnbyexample.github.io/Ruby_Regexp/groupings-and-backreferenc
763
+ # es.html?highlight=subexpression#subexpression-calls).
764
+ #
765
+ # #### Conditionals
766
+ #
767
+ # The conditional construct takes the form `(?(*cond*)*yes*|*no*)`, where:
768
+ #
769
+ # * *cond* may be a capture number or name.
770
+ # * The match to be applied is *yes* if *cond* is captured; otherwise the
771
+ # match to be applied is *no*.
772
+ # * If not needed, `|*no`* may be omitted.
773
+ #
774
+ # Examples:
775
+ #
776
+ # re = /\A(foo)?(?(1)(T)|(F))\z/
777
+ # re.match('fooT') # => #<MatchData "fooT" 1:"foo" 2:"T" 3:nil>
778
+ # re.match('F') # => #<MatchData "F" 1:nil 2:nil 3:"F">
779
+ # re.match('fooF') # => nil
780
+ # re.match('T') # => nil
781
+ #
782
+ # re = /\A(?<xyzzy>foo)?(?(<xyzzy>)(T)|(F))\z/
783
+ # re.match('fooT') # => #<MatchData "fooT" xyzzy:"foo">
784
+ # re.match('F') # => #<MatchData "F" xyzzy:nil>
785
+ # re.match('fooF') # => nil
786
+ # re.match('T') # => nil
787
+ #
788
+ # #### Absence Operator
789
+ #
790
+ # The absence operator is a special group that matches anything which does *not*
791
+ # match the contained subexpressions.
792
+ #
793
+ # /(?~real)/.match('surrealist') # => #<MatchData "surrea">
794
+ # /(?~real)ist/.match('surrealist') # => #<MatchData "ealist">
795
+ # /sur(?~real)ist/.match('surrealist') # => nil
796
+ #
797
+ # ### Unicode
798
+ #
799
+ # #### Unicode Properties
800
+ #
801
+ # The `/\p{*property_name*}/` construct (with lowercase `p`) matches characters
802
+ # using a Unicode property name, much like a character class; property `Alpha`
803
+ # specifies alphabetic characters:
804
+ #
805
+ # /\p{Alpha}/.match('a') # => #<MatchData "a">
806
+ # /\p{Alpha}/.match('1') # => nil
807
+ #
808
+ # A property can be inverted by prefixing the name with a caret character (`^`):
809
+ #
810
+ # /\p{^Alpha}/.match('1') # => #<MatchData "1">
811
+ # /\p{^Alpha}/.match('a') # => nil
812
+ #
813
+ # Or by using `\P` (uppercase `P`):
814
+ #
815
+ # /\P{Alpha}/.match('1') # => #<MatchData "1">
816
+ # /\P{Alpha}/.match('a') # => nil
817
+ #
818
+ # See [Unicode Properties](rdoc-ref:regexp/unicode_properties.rdoc) for regexps
819
+ # based on the numerous properties.
820
+ #
821
+ # Some commonly-used properties correspond to POSIX bracket expressions:
822
+ #
823
+ # * `/\p{Alnum}/`: Alphabetic and numeric character
824
+ # * `/\p{Alpha}/`: Alphabetic character
825
+ # * `/\p{Blank}/`: Space or tab
826
+ # * `/\p{Cntrl}/`: Control character
827
+ # * `/\p{Digit}/`: Digit characters, and similar)
828
+ # * `/\p{Lower}/`: Lowercase alphabetical character
829
+ # * `/\p{Print}/`: Like `\p{Graph}`, but includes the space character
830
+ # * `/\p{Punct}/`: Punctuation character
831
+ # * `/\p{Space}/`: Whitespace character (`[:blank:]`, newline, carriage
832
+ # return, etc.)
833
+ # * `/\p{Upper}/`: Uppercase alphabetical
834
+ # * `/\p{XDigit}/`: Digit allowed in a hexadecimal number (i.e., 0-9a-fA-F)
835
+ #
836
+ # These are also commonly used:
837
+ #
838
+ # * `/\p{Emoji}/`: Unicode emoji.
839
+ # * `/\p{Graph}/`: Characters excluding `/\p{Cntrl}/` and `/\p{Space}/`. Note
840
+ # that invisible characters under the Unicode
841
+ # ["Format"](https://www.compart.com/en/unicode/category/Cf) category are
842
+ # included.
843
+ # * `/\p{Word}/`: A member in one of these Unicode character categories (see
844
+ # below) or having one of these Unicode properties:
845
+ #
846
+ # * Unicode categories:
847
+ # * `Mark` (`M`).
848
+ # * `Decimal Number` (`Nd`)
849
+ # * `Connector Punctuation` (`Pc`).
850
+ #
851
+ # * Unicode properties:
852
+ # * `Alpha`
853
+ # * `Join_Control`
854
+ #
855
+ # * `/\p{ASCII}/`: A character in the ASCII character set.
856
+ # * `/\p{Any}/`: Any Unicode character (including unassigned characters).
857
+ # * `/\p{Assigned}/`: An assigned character.
858
+ #
859
+ # #### Unicode Character Categories
860
+ #
861
+ # A Unicode character category name:
862
+ #
863
+ # * May be either its full name or its abbreviated name.
864
+ # * Is case-insensitive.
865
+ # * Treats a space, a hyphen, and an underscore as equivalent.
866
+ #
867
+ # Examples:
868
+ #
869
+ # /\p{lu}/ # => /\p{lu}/
870
+ # /\p{LU}/ # => /\p{LU}/
871
+ # /\p{Uppercase Letter}/ # => /\p{Uppercase Letter}/
872
+ # /\p{Uppercase_Letter}/ # => /\p{Uppercase_Letter}/
873
+ # /\p{UPPERCASE-LETTER}/ # => /\p{UPPERCASE-LETTER}/
874
+ #
875
+ # Below are the Unicode character category abbreviations and names. Enumerations
876
+ # of characters in each category are at the links.
877
+ #
878
+ # Letters:
879
+ #
880
+ # * `L`, `Letter`: `LC`, `Lm`, or `Lo`.
881
+ # * `LC`, `Cased_Letter`: `Ll`, `Lt`, or `Lu`.
882
+ # * [Lu, Lowercase_Letter](https://www.compart.com/en/unicode/category/Ll).
883
+ # * [Lu, Modifier_Letter](https://www.compart.com/en/unicode/category/Lm).
884
+ # * [Lu, Other_Letter](https://www.compart.com/en/unicode/category/Lo).
885
+ # * [Lu, Titlecase_Letter](https://www.compart.com/en/unicode/category/Lt).
886
+ # * [Lu, Uppercase_Letter](https://www.compart.com/en/unicode/category/Lu).
887
+ #
888
+ # Marks:
889
+ #
890
+ # * `M`, `Mark`: `Mc`, `Me`, or `Mn`.
891
+ # * [Mc, Spacing_Mark](https://www.compart.com/en/unicode/category/Mc).
892
+ # * [Me, Enclosing_Mark](https://www.compart.com/en/unicode/category/Me).
893
+ # * [Mn, Nonapacing_Mark](https://www.compart.com/en/unicode/category/Mn).
894
+ #
895
+ # Numbers:
896
+ #
897
+ # * `N`, `Number`: `Nd`, `Nl`, or `No`.
898
+ # * [Nd, Decimal_Number](https://www.compart.com/en/unicode/category/Nd).
899
+ # * [Nl, Letter_Number](https://www.compart.com/en/unicode/category/Nl).
900
+ # * [No, Other_Number](https://www.compart.com/en/unicode/category/No).
901
+ #
902
+ # Punctuation:
903
+ #
904
+ # * `P`, `Punctuation`: `Pc`, `Pd`, `Pe`, `Pf`, `Pi`, `Po`, or `Ps`.
905
+ # * [Pc,
906
+ # Connector_Punctuation](https://www.compart.com/en/unicode/category/Pc).
907
+ # * [Pd, Dash_Punctuation](https://www.compart.com/en/unicode/category/Pd).
908
+ # * [Pe, Close_Punctuation](https://www.compart.com/en/unicode/category/Pe).
909
+ # * [Pf, Final_Punctuation](https://www.compart.com/en/unicode/category/Pf).
910
+ # * [Pi, Initial_Punctuation](https://www.compart.com/en/unicode/category/Pi).
911
+ # * [Po, Other_Punctuation](https://www.compart.com/en/unicode/category/Po).
912
+ # * [Ps, Open_Punctuation](https://www.compart.com/en/unicode/category/Ps).
913
+ #
914
+ # * `S`, `Symbol`: `Sc`, `Sk`, `Sm`, or `So`.
915
+ # * [Sc, Currency_Symbol](https://www.compart.com/en/unicode/category/Sc).
916
+ # * [Sk, Modifier_Symbol](https://www.compart.com/en/unicode/category/Sk).
917
+ # * [Sm, Math_Symbol](https://www.compart.com/en/unicode/category/Sm).
918
+ # * [So, Other_Symbol](https://www.compart.com/en/unicode/category/So).
919
+ #
920
+ # * `Z`, `Separator`: `Zl`, `Zp`, or `Zs`.
921
+ # * [Zl, Line_Separator](https://www.compart.com/en/unicode/category/Zl).
922
+ # * [Zp, Paragraph_Separator](https://www.compart.com/en/unicode/category/Zp).
923
+ # * [Zs, Space_Separator](https://www.compart.com/en/unicode/category/Zs).
924
+ #
925
+ # * `C`, `Other`: `Cc`, `Cf`, `Cn`, `Co`, or `Cs`.
926
+ # * [Cc, Control](https://www.compart.com/en/unicode/category/Cc).
927
+ # * [Cf, Format](https://www.compart.com/en/unicode/category/Cf).
928
+ # * [Cn, Unassigned](https://www.compart.com/en/unicode/category/Cn).
929
+ # * [Co, Private_Use](https://www.compart.com/en/unicode/category/Co).
930
+ # * [Cs, Surrogate](https://www.compart.com/en/unicode/category/Cs).
931
+ #
932
+ # #### Unicode Scripts and Blocks
933
+ #
934
+ # Among the Unicode properties are:
935
+ #
936
+ # * [Unicode scripts](https://en.wikipedia.org/wiki/Script_(Unicode)); see
937
+ # [supported scripts](https://www.unicode.org/standard/supported.html).
938
+ # * [Unicode blocks](https://en.wikipedia.org/wiki/Unicode_block); see
939
+ # [supported blocks](http://www.unicode.org/Public/UNIDATA/Blocks.txt).
940
+ #
941
+ # ### POSIX Bracket Expressions
942
+ #
943
+ # A POSIX *bracket expression* is also similar to a character class. These
944
+ # expressions provide a portable alternative to the above, with the added
945
+ # benefit of encompassing non-ASCII characters:
946
+ #
947
+ # * `/\d/` matches only ASCII decimal digits `0` through `9`.
948
+ # * `/[[:digit:]]/` matches any character in the Unicode `Decimal Number`
949
+ # (`Nd`) category; see below.
950
+ #
951
+ # The POSIX bracket expressions:
952
+ #
953
+ # * `/[[:digit:]]/`: Matches a [Unicode
954
+ # digit](https://www.compart.com/en/unicode/category/Nd):
955
+ #
956
+ # /[[:digit:]]/.match('9') # => #<MatchData "9">
957
+ # /[[:digit:]]/.match("\u1fbf9") # => #<MatchData "9">
958
+ #
959
+ # * `/[[:xdigit:]]/`: Matches a digit allowed in a hexadecimal number;
960
+ # equivalent to `[0-9a-fA-F]`.
961
+ #
962
+ # * `/[[:upper:]]/`: Matches a [Unicode uppercase
963
+ # letter](https://www.compart.com/en/unicode/category/Lu):
964
+ #
965
+ # /[[:upper:]]/.match('A') # => #<MatchData "A">
966
+ # /[[:upper:]]/.match("\u00c6") # => #<MatchData "Æ">
967
+ #
968
+ # * `/[[:lower:]]/`: Matches a [Unicode lowercase
969
+ # letter](https://www.compart.com/en/unicode/category/Ll):
970
+ #
971
+ # /[[:lower:]]/.match('a') # => #<MatchData "a">
972
+ # /[[:lower:]]/.match("\u01fd") # => #<MatchData "ǽ">
973
+ #
974
+ # * `/[[:alpha:]]/`: Matches `/[[:upper:]]/` or `/[[:lower:]]/`.
975
+ #
976
+ # * `/[[:alnum:]]/`: Matches `/[[:alpha:]]/` or `/[[:digit:]]/`.
977
+ #
978
+ # * `/[[:space:]]/`: Matches [Unicode space
979
+ # character](https://www.compart.com/en/unicode/category/Zs):
980
+ #
981
+ # /[[:space:]]/.match(' ') # => #<MatchData " ">
982
+ # /[[:space:]]/.match("\u2005") # => #<MatchData " ">
983
+ #
984
+ # * `/[[:blank:]]/`: Matches `/[[:space:]]/` or tab character:
985
+ #
986
+ # /[[:blank:]]/.match(' ') # => #<MatchData " ">
987
+ # /[[:blank:]]/.match("\u2005") # => #<MatchData " ">
988
+ # /[[:blank:]]/.match("\t") # => #<MatchData "\t">
989
+ #
990
+ # * `/[[:cntrl:]]/`: Matches [Unicode control
991
+ # character](https://www.compart.com/en/unicode/category/Cc):
992
+ #
993
+ # /[[:cntrl:]]/.match("\u0000") # => #<MatchData "\u0000">
994
+ # /[[:cntrl:]]/.match("\u009f") # => #<MatchData "\u009F">
995
+ #
996
+ # * `/[[:graph:]]/`: Matches any character except `/[[:space:]]/` or
997
+ # `/[[:cntrl:]]/`.
998
+ #
999
+ # * `/[[:print:]]/`: Matches `/[[:graph:]]/` or space character.
1000
+ #
1001
+ # * `/[[:punct:]]/`: Matches any (Unicode punctuation
1002
+ # character}[https://www.compart.com/en/unicode/category/Po]:
1003
+ #
1004
+ # Ruby also supports these (non-POSIX) bracket expressions:
1005
+ #
1006
+ # * `/[[:ascii:]]/`: Matches a character in the ASCII character set.
1007
+ # * `/[[:word:]]/`: Matches a character in one of these Unicode character
1008
+ # categories or having one of these Unicode properties:
1009
+ #
1010
+ # * Unicode categories:
1011
+ # * `Mark` (`M`).
1012
+ # * `Decimal Number` (`Nd`)
1013
+ # * `Connector Punctuation` (`Pc`).
1014
+ #
1015
+ # * Unicode properties:
1016
+ # * `Alpha`
1017
+ # * `Join_Control`
1018
+ #
1019
+ # ### Comments
1020
+ #
1021
+ # A comment may be included in a regexp pattern using the `(?#`*comment*`)`
1022
+ # construct, where *comment* is a substring that is to be ignored. arbitrary
1023
+ # text ignored by the regexp engine:
1024
+ #
1025
+ # /foo(?#Ignore me)bar/.match('foobar') # => #<MatchData "foobar">
1026
+ #
1027
+ # The comment may not include an unescaped terminator character.
1028
+ #
1029
+ # See also [Extended Mode](rdoc-ref:Regexp@Extended+Mode).
1030
+ #
1031
+ # ## Modes
1032
+ #
1033
+ # Each of these modifiers sets a mode for the regexp:
1034
+ #
1035
+ # * `i`: `/*pattern*/i` sets [Case-Insensitive
1036
+ # Mode](rdoc-ref:Regexp@Case-Insensitive+Mode).
1037
+ # * `m`: `/*pattern*/m` sets [Multiline Mode](rdoc-ref:Regexp@Multiline+Mode).
1038
+ # * `x`: `/*pattern*/x` sets [Extended Mode](rdoc-ref:Regexp@Extended+Mode).
1039
+ # * `o`: `/*pattern*/o` sets [Interpolation
1040
+ # Mode](rdoc-ref:Regexp@Interpolation+Mode).
1041
+ #
1042
+ # Any, all, or none of these may be applied.
1043
+ #
1044
+ # Modifiers `i`, `m`, and `x` may be applied to subexpressions:
1045
+ #
1046
+ # * `(?*modifier*)` turns the mode "on" for ensuing subexpressions
1047
+ # * `(?-*modifier*)` turns the mode "off" for ensuing subexpressions
1048
+ # * `(?*modifier*:*subexp*)` turns the mode "on" for *subexp* within the group
1049
+ # * `(?-*modifier*:*subexp*)` turns the mode "off" for *subexp* within the
1050
+ # group
1051
+ #
1052
+ # Example:
1053
+ #
1054
+ # re = /(?i)te(?-i)st/
1055
+ # re.match('test') # => #<MatchData "test">
1056
+ # re.match('TEst') # => #<MatchData "TEst">
1057
+ # re.match('TEST') # => nil
1058
+ # re.match('teST') # => nil
1059
+ #
1060
+ # re = /t(?i:e)st/
1061
+ # re.match('test') # => #<MatchData "test">
1062
+ # re.match('tEst') # => #<MatchData "tEst">
1063
+ # re.match('tEST') # => nil
1064
+ #
1065
+ # Method Regexp#options returns an integer whose value showing the settings for
1066
+ # case-insensitivity mode, multiline mode, and extended mode.
1067
+ #
1068
+ # ### Case-Insensitive Mode
1069
+ #
1070
+ # By default, a regexp is case-sensitive:
1071
+ #
1072
+ # /foo/.match('FOO') # => nil
1073
+ #
1074
+ # Modifier `i` enables case-insensitive mode:
1075
+ #
1076
+ # /foo/i.match('FOO')
1077
+ # # => #<MatchData "FOO">
1078
+ #
1079
+ # Method Regexp#casefold? returns whether the mode is case-insensitive.
1080
+ #
1081
+ # ### Multiline Mode
1082
+ #
1083
+ # The multiline-mode in Ruby is what is commonly called a "dot-all mode":
1084
+ #
1085
+ # * Without the `m` modifier, the subexpression `.` does not match newlines:
1086
+ #
1087
+ # /a.c/.match("a\nc") # => nil
1088
+ #
1089
+ # * With the modifier, it does match:
1090
+ #
1091
+ # /a.c/m.match("a\nc") # => #<MatchData "a\nc">
1092
+ #
1093
+ # Unlike other languages, the modifier `m` does not affect the anchors `^` and
1094
+ # `$`. These anchors always match at line-boundaries in Ruby.
1095
+ #
1096
+ # ### Extended Mode
1097
+ #
1098
+ # Modifier `x` enables extended mode, which means that:
1099
+ #
1100
+ # * Literal white space in the pattern is to be ignored.
1101
+ # * Character `#` marks the remainder of its containing line as a comment,
1102
+ # which is also to be ignored for matching purposes.
1103
+ #
1104
+ # In extended mode, whitespace and comments may be used to form a
1105
+ # self-documented regexp.
1106
+ #
1107
+ # Regexp not in extended mode (matches some Roman numerals):
1108
+ #
1109
+ # pattern = '^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$'
1110
+ # re = /#{pattern}/
1111
+ # re.match('MCMXLIII') # => #<MatchData "MCMXLIII" 1:"CM" 2:"XL" 3:"III">
1112
+ #
1113
+ # Regexp in extended mode:
1114
+ #
1115
+ # pattern = <<-EOT
1116
+ # ^ # beginning of string
1117
+ # M{0,3} # thousands - 0 to 3 Ms
1118
+ # (CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 Cs),
1119
+ # # or 500-800 (D, followed by 0 to 3 Cs)
1120
+ # (XC|XL|L?X{0,3}) # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 Xs),
1121
+ # # or 50-80 (L, followed by 0 to 3 Xs)
1122
+ # (IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 Is),
1123
+ # # or 5-8 (V, followed by 0 to 3 Is)
1124
+ # $ # end of string
1125
+ # EOT
1126
+ # re = /#{pattern}/x
1127
+ # re.match('MCMXLIII') # => #<MatchData "MCMXLIII" 1:"CM" 2:"XL" 3:"III">
1128
+ #
1129
+ # ### Interpolation Mode
1130
+ #
1131
+ # Modifier `o` means that the first time a literal regexp with interpolations is
1132
+ # encountered, the generated Regexp object is saved and used for all future
1133
+ # evaluations of that literal regexp. Without modifier `o`, the generated Regexp
1134
+ # is not saved, so each evaluation of the literal regexp generates a new Regexp
1135
+ # object.
1136
+ #
1137
+ # Without modifier `o`:
1138
+ #
1139
+ # def letters; sleep 5; /[A-Z][a-z]/; end
1140
+ # words = %w[abc def xyz]
1141
+ # start = Time.now
1142
+ # words.each {|word| word.match(/\A[#{letters}]+\z/) }
1143
+ # Time.now - start # => 15.0174892
1144
+ #
1145
+ # With modifier `o`:
1146
+ #
1147
+ # start = Time.now
1148
+ # words.each {|word| word.match(/\A[#{letters}]+\z/o) }
1149
+ # Time.now - start # => 5.0010866
1150
+ #
1151
+ # Note that if the literal regexp does not have interpolations, the `o` behavior
1152
+ # is the default.
1153
+ #
1154
+ # ## Encodings
1155
+ #
1156
+ # By default, a regexp with only US-ASCII characters has US-ASCII encoding:
1157
+ #
1158
+ # re = /foo/
1159
+ # re.source.encoding # => #<Encoding:US-ASCII>
1160
+ # re.encoding # => #<Encoding:US-ASCII>
1161
+ #
1162
+ # A regular expression containing non-US-ASCII characters is assumed to use the
1163
+ # source encoding. This can be overridden with one of the following modifiers.
1164
+ #
1165
+ # * `/*pat*/n`: US-ASCII if only containing US-ASCII characters, otherwise
1166
+ # ASCII-8BIT:
1167
+ #
1168
+ # /foo/n.encoding # => #<Encoding:US-ASCII>
1169
+ # /foo\xff/n.encoding # => #<Encoding:ASCII-8BIT>
1170
+ # /foo\x7f/n.encoding # => #<Encoding:US-ASCII>
1171
+ #
1172
+ # * `/*pat*/u`: UTF-8
1173
+ #
1174
+ # /foo/u.encoding # => #<Encoding:UTF-8>
1175
+ #
1176
+ # * `/*pat*/e`: EUC-JP
1177
+ #
1178
+ # /foo/e.encoding # => #<Encoding:EUC-JP>
1179
+ #
1180
+ # * `/*pat*/s`: Windows-31J
1181
+ #
1182
+ # /foo/s.encoding # => #<Encoding:Windows-31J>
1183
+ #
1184
+ # A regexp can be matched against a target string when either:
1185
+ #
1186
+ # * They have the same encoding.
1187
+ # * The regexp's encoding is a fixed encoding and the string contains only
1188
+ # ASCII characters. Method Regexp#fixed_encoding? returns whether the regexp
1189
+ # has a *fixed* encoding.
1190
+ #
1191
+ # If a match between incompatible encodings is attempted an
1192
+ # `Encoding::CompatibilityError` exception is raised.
1193
+ #
1194
+ # Example:
1195
+ #
1196
+ # re = eval("# encoding: ISO-8859-1\n/foo\\xff?/")
1197
+ # re.encoding # => #<Encoding:ISO-8859-1>
1198
+ # re =~ "foo".encode("UTF-8") # => 0
1199
+ # re =~ "foo\u0100" # Raises Encoding::CompatibilityError
1200
+ #
1201
+ # The encoding may be explicitly fixed by including Regexp::FIXEDENCODING in the
1202
+ # second argument for Regexp.new:
1203
+ #
1204
+ # # Regexp with encoding ISO-8859-1.
1205
+ # re = Regexp.new("a".force_encoding('iso-8859-1'), Regexp::FIXEDENCODING)
1206
+ # re.encoding # => #<Encoding:ISO-8859-1>
1207
+ # # Target string with encoding UTF-8.
1208
+ # s = "a\u3042"
1209
+ # s.encoding # => #<Encoding:UTF-8>
1210
+ # re.match(s) # Raises Encoding::CompatibilityError.
1211
+ #
1212
+ # ## Timeouts
1213
+ #
1214
+ # When either a regexp source or a target string comes from untrusted input,
1215
+ # malicious values could become a denial-of-service attack; to prevent such an
1216
+ # attack, it is wise to set a timeout.
1217
+ #
1218
+ # Regexp has two timeout values:
1219
+ #
1220
+ # * A class default timeout, used for a regexp whose instance timeout is
1221
+ # `nil`; this default is initially `nil`, and may be set by method
1222
+ # Regexp.timeout=:
1223
+ #
1224
+ # Regexp.timeout # => nil
1225
+ # Regexp.timeout = 3.0
1226
+ # Regexp.timeout # => 3.0
1227
+ #
1228
+ # * An instance timeout, which defaults to `nil` and may be set in Regexp.new:
1229
+ #
1230
+ # re = Regexp.new('foo', timeout: 5.0)
1231
+ # re.timeout # => 5.0
1232
+ #
1233
+ # When regexp.timeout is `nil`, the timeout "falls through" to Regexp.timeout;
1234
+ # when regexp.timeout is non-`nil`, that value controls timing out:
1235
+ #
1236
+ # | regexp.timeout Value | Regexp.timeout Value | Result |
1237
+ # |----------------------|----------------------|-----------------------------|
1238
+ # | nil | nil | Never times out. |
1239
+ # | nil | Float | Times out in Float seconds. |
1240
+ # | Float | Any | Times out in Float seconds. |
1241
+ #
1242
+ # ## Optimization
1243
+ #
1244
+ # For certain values of the pattern and target string, matching time can grow
1245
+ # polynomially or exponentially in relation to the input size; the potential
1246
+ # vulnerability arising from this is the [regular expression
1247
+ # denial-of-service](https://en.wikipedia.org/wiki/ReDoS) (ReDoS) attack.
1248
+ #
1249
+ # Regexp matching can apply an optimization to prevent ReDoS attacks. When the
1250
+ # optimization is applied, matching time increases linearly (not polynomially or
1251
+ # exponentially) in relation to the input size, and a ReDoS attach is not
1252
+ # possible.
1253
+ #
1254
+ # This optimization is applied if the pattern meets these criteria:
1255
+ #
1256
+ # * No backreferences.
1257
+ # * No subexpression calls.
1258
+ # * No nested lookaround anchors or atomic groups.
1259
+ # * No nested quantifiers with counting (i.e. no nested `{n}`, `{min,}`,
1260
+ # `{,max}`, or `{min,max}` style quantifiers)
1261
+ #
1262
+ # You can use method Regexp.linear_time? to determine whether a pattern meets
1263
+ # these criteria:
1264
+ #
1265
+ # Regexp.linear_time?(/a*/) # => true
1266
+ # Regexp.linear_time?('a*') # => true
1267
+ # Regexp.linear_time?(/(a*)\1/) # => false
1268
+ #
1269
+ # However, an untrusted source may not be safe even if the method returns
1270
+ # `true`, because the optimization uses memoization (which may invoke large
1271
+ # memory consumption).
1272
+ #
1273
+ # ## References
1274
+ #
1275
+ # Read (online PDF books):
1276
+ #
1277
+ # * [Mastering Regular
1278
+ # Expressions](https://ia902508.us.archive.org/10/items/allitebooks-02/Maste
1279
+ # ring%20Regular%20Expressions%2C%203rd%20Edition.pdf) by Jeffrey E.F.
1280
+ # Friedl.
1281
+ # * [Regular Expressions
1282
+ # Cookbook](https://doc.lagout.org/programmation/Regular%20Expressions/Regul
1283
+ # ar%20Expressions%20Cookbook_%20Detailed%20Solutions%20in%20Eight%20Program
1284
+ # ming%20Languages%20%282nd%20ed.%29%20%5BGoyvaerts%20%26%20Levithan%202012-
1285
+ # 09-06%5D.pdf) by Jan Goyvaerts & Steven Levithan.
1286
+ #
1287
+ # Explore, test (interactive online editor):
1288
+ #
1289
+ # * [Rubular](https://rubular.com/).
1290
+ #
1291
+ class Regexp
1292
+ # Represents an object's ability to be converted to a `Regexp`.
1293
+ #
1294
+ # This is only used in `Regexp.try_convert` and `Regexp.union` within the standard library.
1295
+ interface _ToRegexp
1296
+ # Converts `self` to a `Regexp`.
1297
+ def to_regexp: () -> Regexp
1298
+ end
1299
+
1300
+ class TimeoutError < RegexpError
1301
+ end
1302
+
1303
+ # <!-- rdoc-file=re.c -->
1304
+ # see Regexp.options and Regexp.new
1305
+ #
1306
+ EXTENDED: Integer
1307
+
1308
+ # <!-- rdoc-file=re.c -->
1309
+ # see Regexp.options and Regexp.new
1310
+ #
1311
+ FIXEDENCODING: Integer
1312
+
1313
+ # <!-- rdoc-file=re.c -->
1314
+ # see Regexp.options and Regexp.new
1315
+ #
1316
+ IGNORECASE: Integer
1317
+
1318
+ # <!-- rdoc-file=re.c -->
1319
+ # see Regexp.options and Regexp.new
1320
+ #
1321
+ MULTILINE: Integer
1322
+
1323
+ # <!-- rdoc-file=re.c -->
1324
+ # see Regexp.options and Regexp.new
1325
+ #
1326
+ NOENCODING: Integer
1327
+
1328
+ # <!--
1329
+ # rdoc-file=re.c
1330
+ # - compile(*args)
1331
+ # -->
1332
+ # Alias for Regexp.new
1333
+ #
1334
+ alias self.compile self.new
1335
+
1336
+ # <!--
1337
+ # rdoc-file=re.c
1338
+ # - Regexp.escape(string) -> new_string
1339
+ # -->
1340
+ # Returns a new string that escapes any characters that have special meaning in
1341
+ # a regular expression:
1342
+ #
1343
+ # s = Regexp.escape('\*?{}.') # => "\\\\\\*\\?\\{\\}\\."
1344
+ #
1345
+ # For any string `s`, this call returns a MatchData object:
1346
+ #
1347
+ # r = Regexp.new(Regexp.escape(s)) # => /\\\\\\\*\\\?\\\{\\\}\\\./
1348
+ # r.match(s) # => #<MatchData "\\\\\\*\\?\\{\\}\\.">
1349
+ #
1350
+ def self.escape: (interned str) -> String
1351
+
1352
+ # <!--
1353
+ # rdoc-file=re.c
1354
+ # - Regexp.last_match -> matchdata or nil
1355
+ # - Regexp.last_match(n) -> string or nil
1356
+ # - Regexp.last_match(name) -> string or nil
1357
+ # -->
1358
+ # With no argument, returns the value of `$~`, which is the result of the most
1359
+ # recent pattern match (see [Regexp global
1360
+ # variables](rdoc-ref:Regexp@Global+Variables)):
1361
+ #
1362
+ # /c(.)t/ =~ 'cat' # => 0
1363
+ # Regexp.last_match # => #<MatchData "cat" 1:"a">
1364
+ # /a/ =~ 'foo' # => nil
1365
+ # Regexp.last_match # => nil
1366
+ #
1367
+ # With non-negative integer argument `n`, returns the _n_th field in the
1368
+ # matchdata, if any, or nil if none:
1369
+ #
1370
+ # /c(.)t/ =~ 'cat' # => 0
1371
+ # Regexp.last_match(0) # => "cat"
1372
+ # Regexp.last_match(1) # => "a"
1373
+ # Regexp.last_match(2) # => nil
1374
+ #
1375
+ # With negative integer argument `n`, counts backwards from the last field:
1376
+ #
1377
+ # Regexp.last_match(-1) # => "a"
1378
+ #
1379
+ # With string or symbol argument `name`, returns the string value for the named
1380
+ # capture, if any:
1381
+ #
1382
+ # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ 'var = val'
1383
+ # Regexp.last_match # => #<MatchData "var = val" lhs:"var"rhs:"val">
1384
+ # Regexp.last_match(:lhs) # => "var"
1385
+ # Regexp.last_match('rhs') # => "val"
1386
+ # Regexp.last_match('foo') # Raises IndexError.
1387
+ #
1388
+ def self.last_match: () -> MatchData?
1389
+ | (MatchData::capture capture) -> String?
1390
+
1391
+ # <!--
1392
+ # rdoc-file=re.c
1393
+ # - Regexp.linear_time?(re)
1394
+ # - Regexp.linear_time?(string, options = 0)
1395
+ # -->
1396
+ # Returns `true` if matching against `re` can be done in linear time to the
1397
+ # input string.
1398
+ #
1399
+ # Regexp.linear_time?(/re/) # => true
1400
+ #
1401
+ # Note that this is a property of the ruby interpreter, not of the argument
1402
+ # regular expression. Identical regexp can or cannot run in linear time
1403
+ # depending on your ruby binary. Neither forward nor backward compatibility is
1404
+ # guaranteed about the return value of this method. Our current algorithm is
1405
+ # (*1) but this is subject to change in the future. Alternative implementations
1406
+ # can also behave differently. They might always return false for everything.
1407
+ #
1408
+ # (*1): https://doi.org/10.1109/SP40001.2021.00032
1409
+ #
1410
+ def self.linear_time?: (Regexp regex, ?nil, ?timeout: untyped) -> bool
1411
+ | (string regex, ?int | string | bool | nil options, ?timeout: untyped) -> bool
1412
+
1413
+ # <!--
1414
+ # rdoc-file=re.c
1415
+ # - Regexp.escape(string) -> new_string
1416
+ # -->
1417
+ # Returns a new string that escapes any characters that have special meaning in
1418
+ # a regular expression:
1419
+ #
1420
+ # s = Regexp.escape('\*?{}.') # => "\\\\\\*\\?\\{\\}\\."
1421
+ #
1422
+ # For any string `s`, this call returns a MatchData object:
1423
+ #
1424
+ # r = Regexp.new(Regexp.escape(s)) # => /\\\\\\\*\\\?\\\{\\\}\\\./
1425
+ # r.match(s) # => #<MatchData "\\\\\\*\\?\\{\\}\\.">
1426
+ #
1427
+ alias self.quote self.escape
1428
+
1429
+ # <!--
1430
+ # rdoc-file=re.c
1431
+ # - Regexp.try_convert(object) -> regexp or nil
1432
+ # -->
1433
+ # Returns `object` if it is a regexp:
1434
+ #
1435
+ # Regexp.try_convert(/re/) # => /re/
1436
+ #
1437
+ # Otherwise if `object` responds to `:to_regexp`, calls `object.to_regexp` and
1438
+ # returns the result.
1439
+ #
1440
+ # Returns `nil` if `object` does not respond to `:to_regexp`.
1441
+ #
1442
+ # Regexp.try_convert('re') # => nil
1443
+ #
1444
+ # Raises an exception unless `object.to_regexp` returns a regexp.
1445
+ #
1446
+ def self.try_convert: (Regexp | _ToRegexp regexp_like) -> Regexp
1447
+ | (untyped other) -> Regexp?
1448
+
1449
+ # <!--
1450
+ # rdoc-file=re.c
1451
+ # - Regexp.timeout -> float or nil
1452
+ # -->
1453
+ # It returns the current default timeout interval for Regexp matching in second.
1454
+ # `nil` means no default timeout configuration.
1455
+ #
1456
+ def self.timeout: () -> Float?
1457
+
1458
+ # <!--
1459
+ # rdoc-file=re.c
1460
+ # - Regexp.timeout = float or nil
1461
+ # -->
1462
+ # It sets the default timeout interval for Regexp matching in second. `nil`
1463
+ # means no default timeout configuration. This configuration is process-global.
1464
+ # If you want to set timeout for each Regexp, use `timeout` keyword for
1465
+ # `Regexp.new`.
1466
+ #
1467
+ # Regexp.timeout = 1
1468
+ # /^a*b?a*$/ =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)
1469
+ #
1470
+ def self.timeout=: [T < _ToF] (T timeout) -> T
1471
+
1472
+ # <!--
1473
+ # rdoc-file=re.c
1474
+ # - Regexp.union(*patterns) -> regexp
1475
+ # - Regexp.union(array_of_patterns) -> regexp
1476
+ # -->
1477
+ # Returns a new regexp that is the union of the given patterns:
1478
+ #
1479
+ # r = Regexp.union(%w[cat dog]) # => /cat|dog/
1480
+ # r.match('cat') # => #<MatchData "cat">
1481
+ # r.match('dog') # => #<MatchData "dog">
1482
+ # r.match('cog') # => nil
1483
+ #
1484
+ # For each pattern that is a string, `Regexp.new(pattern)` is used:
1485
+ #
1486
+ # Regexp.union('penzance') # => /penzance/
1487
+ # Regexp.union('a+b*c') # => /a\+b\*c/
1488
+ # Regexp.union('skiing', 'sledding') # => /skiing|sledding/
1489
+ # Regexp.union(['skiing', 'sledding']) # => /skiing|sledding/
1490
+ #
1491
+ # For each pattern that is a regexp, it is used as is, including its flags:
1492
+ #
1493
+ # Regexp.union(/foo/i, /bar/m, /baz/x)
1494
+ # # => /(?i-mx:foo)|(?m-ix:bar)|(?x-mi:baz)/
1495
+ # Regexp.union([/foo/i, /bar/m, /baz/x])
1496
+ # # => /(?i-mx:foo)|(?m-ix:bar)|(?x-mi:baz)/
1497
+ #
1498
+ # With no arguments, returns `/(?!)/`:
1499
+ #
1500
+ # Regexp.union # => /(?!)/
1501
+ #
1502
+ # If any regexp pattern contains captures, the behavior is unspecified.
1503
+ #
1504
+ def self.union: (*Regexp | _ToRegexp | string patterns) -> Regexp
1505
+ | (array[Regexp | _ToRegexp | string] patterns) -> Regexp
1506
+ | (Symbol | [Symbol] symbol_pattern) -> Regexp
1507
+
1508
+ # <!--
1509
+ # rdoc-file=re.c
1510
+ # - Regexp.new(string, options = 0, timeout: nil) -> regexp
1511
+ # - Regexp.new(regexp, timeout: nil) -> regexp
1512
+ # -->
1513
+ # With argument `string` given, returns a new regexp with the given string and
1514
+ # options:
1515
+ #
1516
+ # r = Regexp.new('foo') # => /foo/
1517
+ # r.source # => "foo"
1518
+ # r.options # => 0
1519
+ #
1520
+ # Optional argument `options` is one of the following:
1521
+ #
1522
+ # * A String of options:
1523
+ #
1524
+ # Regexp.new('foo', 'i') # => /foo/i
1525
+ # Regexp.new('foo', 'im') # => /foo/im
1526
+ #
1527
+ # * The bit-wise OR of one or more of the constants Regexp::EXTENDED,
1528
+ # Regexp::IGNORECASE, Regexp::MULTILINE, and Regexp::NOENCODING:
1529
+ #
1530
+ # Regexp.new('foo', Regexp::IGNORECASE) # => /foo/i
1531
+ # Regexp.new('foo', Regexp::EXTENDED) # => /foo/x
1532
+ # Regexp.new('foo', Regexp::MULTILINE) # => /foo/m
1533
+ # Regexp.new('foo', Regexp::NOENCODING) # => /foo/n
1534
+ # flags = Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE
1535
+ # Regexp.new('foo', flags) # => /foo/mix
1536
+ #
1537
+ # * `nil` or `false`, which is ignored.
1538
+ # * Any other truthy value, in which case the regexp will be case-insensitive.
1539
+ #
1540
+ # If optional keyword argument `timeout` is given, its float value overrides the
1541
+ # timeout interval for the class, Regexp.timeout. If `nil` is passed as
1542
+ # +timeout, it uses the timeout interval for the class, Regexp.timeout.
1543
+ #
1544
+ # With argument `regexp` given, returns a new regexp. The source, options,
1545
+ # timeout are the same as `regexp`. `options` and `n_flag` arguments are
1546
+ # ineffective. The timeout can be overridden by `timeout` keyword.
1547
+ #
1548
+ # options = Regexp::MULTILINE
1549
+ # r = Regexp.new('foo', options, timeout: 1.1) # => /foo/m
1550
+ # r2 = Regexp.new(r) # => /foo/m
1551
+ # r2.timeout # => 1.1
1552
+ # r3 = Regexp.new(r, timeout: 3.14) # => /foo/m
1553
+ # r3.timeout # => 3.14
1554
+ #
1555
+ def initialize: (Regexp regexp, ?timeout: _ToF?) -> void
1556
+ | (string pattern, ?int | string | bool | nil options, ?timeout: _ToF?) -> void
1557
+
1558
+ def initialize_copy: (self object) -> self
1559
+
1560
+ # <!-- rdoc-file=re.c -->
1561
+ # Returns `true` if `object` is another Regexp whose pattern, flags, and
1562
+ # encoding are the same as `self`, `false` otherwise:
1563
+ #
1564
+ # /foo/ == Regexp.new('foo') # => true
1565
+ # /foo/ == /foo/i # => false
1566
+ # /foo/ == Regexp.new('food') # => false
1567
+ # /foo/ == Regexp.new("abc".force_encoding("euc-jp")) # => false
1568
+ #
1569
+ def ==: (untyped other) -> bool
1570
+
1571
+ # <!--
1572
+ # rdoc-file=re.c
1573
+ # - regexp === string -> true or false
1574
+ # -->
1575
+ # Returns `true` if `self` finds a match in `string`:
1576
+ #
1577
+ # /^[a-z]*$/ === 'HELLO' # => false
1578
+ # /^[A-Z]*$/ === 'HELLO' # => true
1579
+ #
1580
+ # This method is called in case statements:
1581
+ #
1582
+ # s = 'HELLO'
1583
+ # case s
1584
+ # when /\A[a-z]*\z/; print "Lower case\n"
1585
+ # when /\A[A-Z]*\z/; print "Upper case\n"
1586
+ # else print "Mixed case\n"
1587
+ # end # => "Upper case"
1588
+ #
1589
+ def ===: (untyped other) -> bool
1590
+
1591
+ # <!--
1592
+ # rdoc-file=re.c
1593
+ # - regexp =~ string -> integer or nil
1594
+ # -->
1595
+ # Returns the integer index (in characters) of the first match for `self` and
1596
+ # `string`, or `nil` if none; also sets the [rdoc-ref:Regexp global
1597
+ # variables](rdoc-ref:Regexp@Global+Variables):
1598
+ #
1599
+ # /at/ =~ 'input data' # => 7
1600
+ # $~ # => #<MatchData "at">
1601
+ # /ax/ =~ 'input data' # => nil
1602
+ # $~ # => nil
1603
+ #
1604
+ # Assigns named captures to local variables of the same names if and only if
1605
+ # `self`:
1606
+ #
1607
+ # * Is a regexp literal; see [Regexp
1608
+ # Literals](rdoc-ref:syntax/literals.rdoc@Regexp+Literals).
1609
+ # * Does not contain interpolations; see [Regexp
1610
+ # interpolation](rdoc-ref:Regexp@Interpolation+Mode).
1611
+ # * Is at the left of the expression.
1612
+ #
1613
+ # Example:
1614
+ #
1615
+ # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ ' x = y '
1616
+ # p lhs # => "x"
1617
+ # p rhs # => "y"
1618
+ #
1619
+ # Assigns `nil` if not matched:
1620
+ #
1621
+ # /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ ' x = '
1622
+ # p lhs # => nil
1623
+ # p rhs # => nil
1624
+ #
1625
+ # Does not make local variable assignments if `self` is not a regexp literal:
1626
+ #
1627
+ # r = /(?<foo>\w+)\s*=\s*(?<foo>\w+)/
1628
+ # r =~ ' x = y '
1629
+ # p foo # Undefined local variable
1630
+ # p bar # Undefined local variable
1631
+ #
1632
+ # The assignment does not occur if the regexp is not at the left:
1633
+ #
1634
+ # ' x = y ' =~ /(?<foo>\w+)\s*=\s*(?<foo>\w+)/
1635
+ # p foo, foo # Undefined local variables
1636
+ #
1637
+ # A regexp interpolation, `#{}`, also disables the assignment:
1638
+ #
1639
+ # r = /(?<foo>\w+)/
1640
+ # /(?<foo>\w+)\s*=\s*#{r}/ =~ 'x = y'
1641
+ # p foo # Undefined local variable
1642
+ #
1643
+ def =~: (interned? string) -> Integer?
1644
+ | (nil) -> nil
1645
+
1646
+ # <!--
1647
+ # rdoc-file=re.c
1648
+ # - casefold?-> true or false
1649
+ # -->
1650
+ # Returns `true` if the case-insensitivity flag in `self` is set, `false`
1651
+ # otherwise:
1652
+ #
1653
+ # /a/.casefold? # => false
1654
+ # /a/i.casefold? # => true
1655
+ # /(?i:a)/.casefold? # => false
1656
+ #
1657
+ def casefold?: () -> bool
1658
+
1659
+ # <!--
1660
+ # rdoc-file=re.c
1661
+ # - obj.encoding -> encoding
1662
+ # -->
1663
+ # Returns the Encoding object that represents the encoding of obj.
1664
+ #
1665
+ def encoding: () -> Encoding
1666
+
1667
+ # <!--
1668
+ # rdoc-file=re.c
1669
+ # - regexp == object -> true or false
1670
+ # -->
1671
+ # Returns `true` if `object` is another Regexp whose pattern, flags, and
1672
+ # encoding are the same as `self`, `false` otherwise:
1673
+ #
1674
+ # /foo/ == Regexp.new('foo') # => true
1675
+ # /foo/ == /foo/i # => false
1676
+ # /foo/ == Regexp.new('food') # => false
1677
+ # /foo/ == Regexp.new("abc".force_encoding("euc-jp")) # => false
1678
+ #
1679
+ alias eql? ==
1680
+
1681
+ # <!--
1682
+ # rdoc-file=re.c
1683
+ # - fixed_encoding? -> true or false
1684
+ # -->
1685
+ # Returns `false` if `self` is applicable to a string with any ASCII-compatible
1686
+ # encoding; otherwise returns `true`:
1687
+ #
1688
+ # r = /a/ # => /a/
1689
+ # r.fixed_encoding? # => false
1690
+ # r.match?("\u{6666} a") # => true
1691
+ # r.match?("\xa1\xa2 a".force_encoding("euc-jp")) # => true
1692
+ # r.match?("abc".force_encoding("euc-jp")) # => true
1693
+ #
1694
+ # r = /a/u # => /a/
1695
+ # r.fixed_encoding? # => true
1696
+ # r.match?("\u{6666} a") # => true
1697
+ # r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception.
1698
+ # r.match?("abc".force_encoding("euc-jp")) # => true
1699
+ #
1700
+ # r = /\u{6666}/ # => /\u{6666}/
1701
+ # r.fixed_encoding? # => true
1702
+ # r.encoding # => #<Encoding:UTF-8>
1703
+ # r.match?("\u{6666} a") # => true
1704
+ # r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception.
1705
+ # r.match?("abc".force_encoding("euc-jp")) # => false
1706
+ #
1707
+ def fixed_encoding?: () -> bool
1708
+
1709
+ # <!--
1710
+ # rdoc-file=re.c
1711
+ # - hash -> integer
1712
+ # -->
1713
+ # Returns the integer hash value for `self`.
1714
+ #
1715
+ # Related: Object#hash.
1716
+ #
1717
+ def hash: () -> Integer
1718
+
1719
+ # <!--
1720
+ # rdoc-file=re.c
1721
+ # - inspect -> string
1722
+ # -->
1723
+ # Returns a nicely-formatted string representation of `self`:
1724
+ #
1725
+ # /ab+c/ix.inspect # => "/ab+c/ix"
1726
+ #
1727
+ # Related: Regexp#to_s.
1728
+ #
1729
+ def inspect: () -> String
1730
+
1731
+ # <!--
1732
+ # rdoc-file=re.c
1733
+ # - match(string, offset = 0) -> matchdata or nil
1734
+ # - match(string, offset = 0) {|matchdata| ... } -> object
1735
+ # -->
1736
+ # With no block given, returns the MatchData object that describes the match, if
1737
+ # any, or `nil` if none; the search begins at the given character `offset` in
1738
+ # `string`:
1739
+ #
1740
+ # /abra/.match('abracadabra') # => #<MatchData "abra">
1741
+ # /abra/.match('abracadabra', 4) # => #<MatchData "abra">
1742
+ # /abra/.match('abracadabra', 8) # => nil
1743
+ # /abra/.match('abracadabra', 800) # => nil
1744
+ #
1745
+ # string = "\u{5d0 5d1 5e8 5d0}cadabra"
1746
+ # /abra/.match(string, 7) #=> #<MatchData "abra">
1747
+ # /abra/.match(string, 8) #=> nil
1748
+ # /abra/.match(string.b, 8) #=> #<MatchData "abra">
1749
+ #
1750
+ # With a block given, calls the block if and only if a match is found; returns
1751
+ # the block's value:
1752
+ #
1753
+ # /abra/.match('abracadabra') {|matchdata| p matchdata }
1754
+ # # => #<MatchData "abra">
1755
+ # /abra/.match('abracadabra', 4) {|matchdata| p matchdata }
1756
+ # # => #<MatchData "abra">
1757
+ # /abra/.match('abracadabra', 8) {|matchdata| p matchdata }
1758
+ # # => nil
1759
+ # /abra/.match('abracadabra', 8) {|marchdata| fail 'Cannot happen' }
1760
+ # # => nil
1761
+ #
1762
+ # Output (from the first two blocks above):
1763
+ #
1764
+ # #<MatchData "abra">
1765
+ # #<MatchData "abra">
1766
+ #
1767
+ # /(.)(.)(.)/.match("abc")[2] # => "b"
1768
+ # /(.)(.)/.match("abc", 1)[2] # => "c"
1769
+ #
1770
+ def match: (interned? str, ?int offset) -> MatchData?
1771
+ | [T] (interned? str, ?int offset) { (MatchData matchdata) -> T } -> T?
1772
+ | (nil, ?int offset) ?{ (MatchData matchdata) -> void } -> nil
1773
+
1774
+ # <!--
1775
+ # rdoc-file=re.c
1776
+ # - match?(string) -> true or false
1777
+ # - match?(string, offset = 0) -> true or false
1778
+ # -->
1779
+ # Returns `true` or `false` to indicate whether the regexp is matched or not
1780
+ # without updating $~ and other related variables. If the second parameter is
1781
+ # present, it specifies the position in the string to begin the search.
1782
+ #
1783
+ # /R.../.match?("Ruby") # => true
1784
+ # /R.../.match?("Ruby", 1) # => false
1785
+ # /P.../.match?("Ruby") # => false
1786
+ # $& # => nil
1787
+ #
1788
+ def match?: (interned str, ?int offset) -> bool
1789
+ | (nil, ?int offset) -> false
1790
+
1791
+ # <!--
1792
+ # rdoc-file=re.c
1793
+ # - named_captures -> hash
1794
+ # -->
1795
+ # Returns a hash representing named captures of `self` (see [Named
1796
+ # Captures](rdoc-ref:Regexp@Named+Captures)):
1797
+ #
1798
+ # * Each key is the name of a named capture.
1799
+ # * Each value is an array of integer indexes for that named capture.
1800
+ #
1801
+ # Examples:
1802
+ #
1803
+ # /(?<foo>.)(?<bar>.)/.named_captures # => {"foo"=>[1], "bar"=>[2]}
1804
+ # /(?<foo>.)(?<foo>.)/.named_captures # => {"foo"=>[1, 2]}
1805
+ # /(.)(.)/.named_captures # => {}
1806
+ #
1807
+ def named_captures: () -> Hash[String, Array[Integer]]
1808
+
1809
+ # <!--
1810
+ # rdoc-file=re.c
1811
+ # - names -> array_of_names
1812
+ # -->
1813
+ # Returns an array of names of captures (see [Named
1814
+ # Captures](rdoc-ref:Regexp@Named+Captures)):
1815
+ #
1816
+ # /(?<foo>.)(?<bar>.)(?<baz>.)/.names # => ["foo", "bar", "baz"]
1817
+ # /(?<foo>.)(?<foo>.)/.names # => ["foo"]
1818
+ # /(.)(.)/.names # => []
1819
+ #
1820
+ def names: () -> Array[String]
1821
+
1822
+ # <!--
1823
+ # rdoc-file=re.c
1824
+ # - options -> integer
1825
+ # -->
1826
+ # Returns an integer whose bits show the options set in `self`.
1827
+ #
1828
+ # The option bits are:
1829
+ #
1830
+ # Regexp::IGNORECASE # => 1
1831
+ # Regexp::EXTENDED # => 2
1832
+ # Regexp::MULTILINE # => 4
1833
+ #
1834
+ # Examples:
1835
+ #
1836
+ # /foo/.options # => 0
1837
+ # /foo/i.options # => 1
1838
+ # /foo/x.options # => 2
1839
+ # /foo/m.options # => 4
1840
+ # /foo/mix.options # => 7
1841
+ #
1842
+ # Note that additional bits may be set in the returned integer; these are
1843
+ # maintained internally in `self`, are ignored if passed to Regexp.new, and may
1844
+ # be ignored by the caller:
1845
+ #
1846
+ # Returns the set of bits corresponding to the options used when creating this
1847
+ # regexp (see Regexp::new for details). Note that additional bits may be set in
1848
+ # the returned options: these are used internally by the regular expression
1849
+ # code. These extra bits are ignored if the options are passed to Regexp::new:
1850
+ #
1851
+ # r = /\xa1\xa2/e # => /\xa1\xa2/
1852
+ # r.source # => "\\xa1\\xa2"
1853
+ # r.options # => 16
1854
+ # Regexp.new(r.source, r.options) # => /\xa1\xa2/
1855
+ #
1856
+ def options: () -> Integer
1857
+
1858
+ # <!--
1859
+ # rdoc-file=re.c
1860
+ # - source -> string
1861
+ # -->
1862
+ # Returns the original string of `self`:
1863
+ #
1864
+ # /ab+c/ix.source # => "ab+c"
1865
+ #
1866
+ # Regexp escape sequences are retained:
1867
+ #
1868
+ # /\x20\+/.source # => "\\x20\\+"
1869
+ #
1870
+ # Lexer escape characters are not retained:
1871
+ #
1872
+ # /\//.source # => "/"
1873
+ #
1874
+ def source: () -> String
1875
+
1876
+ # <!--
1877
+ # rdoc-file=re.c
1878
+ # - to_s -> string
1879
+ # -->
1880
+ # Returns a string showing the options and string of `self`:
1881
+ #
1882
+ # r0 = /ab+c/ix
1883
+ # s0 = r0.to_s # => "(?ix-m:ab+c)"
1884
+ #
1885
+ # The returned string may be used as an argument to Regexp.new, or as
1886
+ # interpolated text for a [Regexp
1887
+ # interpolation](rdoc-ref:Regexp@Interpolation+Mode):
1888
+ #
1889
+ # r1 = Regexp.new(s0) # => /(?ix-m:ab+c)/
1890
+ # r2 = /#{s0}/ # => /(?ix-m:ab+c)/
1891
+ #
1892
+ # Note that `r1` and `r2` are not equal to `r0` because their original strings
1893
+ # are different:
1894
+ #
1895
+ # r0 == r1 # => false
1896
+ # r0.source # => "ab+c"
1897
+ # r1.source # => "(?ix-m:ab+c)"
1898
+ #
1899
+ # Related: Regexp#inspect.
1900
+ #
1901
+ def to_s: () -> String
1902
+
1903
+ # <!--
1904
+ # rdoc-file=re.c
1905
+ # - rxp.timeout -> float or nil
1906
+ # -->
1907
+ # It returns the timeout interval for Regexp matching in second. `nil` means no
1908
+ # default timeout configuration.
1909
+ #
1910
+ # This configuration is per-object. The global configuration set by
1911
+ # Regexp.timeout= is ignored if per-object configuration is set.
1912
+ #
1913
+ # re = Regexp.new("^a*b?a*$", timeout: 1)
1914
+ # re.timeout #=> 1.0
1915
+ # re =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)
1916
+ #
1917
+ %a{pure}
1918
+ def timeout: () -> Float?
1919
+
1920
+ # <!--
1921
+ # rdoc-file=re.c
1922
+ # - ~ rxp -> integer or nil
1923
+ # -->
1924
+ # Equivalent to *`rxp* =~ $_`:
1925
+ #
1926
+ # $_ = "input data"
1927
+ # ~ /at/ # => 7
1928
+ #
1929
+ def ~: () -> Integer?
1930
+ end