rbs 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +2 -2
  3. data/CHANGELOG.md +37 -0
  4. data/Rakefile +3 -2
  5. data/Steepfile +2 -0
  6. data/bin/rbs-prof +1 -1
  7. data/core/array.rbs +8 -4
  8. data/core/thread.rbs +14 -1
  9. data/lib/rbs.rb +3 -0
  10. data/lib/rbs/ancestor_graph.rb +90 -0
  11. data/lib/rbs/char_scanner.rb +20 -0
  12. data/lib/rbs/definition_builder.rb +38 -20
  13. data/lib/rbs/definition_builder/method_builder.rb +14 -0
  14. data/lib/rbs/environment.rb +42 -5
  15. data/lib/rbs/environment_walker.rb +4 -4
  16. data/lib/rbs/errors.rb +32 -17
  17. data/lib/rbs/parser.rb +437 -416
  18. data/lib/rbs/parser.y +29 -16
  19. data/lib/rbs/test/type_check.rb +7 -3
  20. data/lib/rbs/version.rb +1 -1
  21. data/sig/ancestor_graph.rbs +40 -0
  22. data/sig/char_scanner.rbs +9 -0
  23. data/sig/definition_builder.rbs +5 -1
  24. data/sig/environment.rbs +22 -2
  25. data/sig/environment_walker.rbs +39 -0
  26. data/sig/errors.rbs +42 -17
  27. data/sig/method_builder.rbs +2 -0
  28. data/sig/parser.rbs +11 -4
  29. data/sig/polyfill.rbs +0 -14
  30. data/stdlib/cgi/0/core.rbs +595 -0
  31. data/stdlib/rubygems/0/basic_specification.rbs +3 -0
  32. data/stdlib/rubygems/0/config_file.rbs +3 -0
  33. data/stdlib/rubygems/0/dependency_installer.rbs +5 -0
  34. data/stdlib/rubygems/0/installer.rbs +3 -0
  35. data/stdlib/rubygems/0/path_support.rbs +3 -0
  36. data/stdlib/rubygems/0/platform.rbs +3 -0
  37. data/stdlib/rubygems/0/request_set.rbs +7 -0
  38. data/stdlib/rubygems/0/requirement.rbs +3 -0
  39. data/stdlib/rubygems/0/rubygems.rbs +710 -0
  40. data/stdlib/rubygems/0/source_list.rbs +2 -0
  41. data/stdlib/rubygems/0/specification.rbs +3 -0
  42. data/stdlib/rubygems/0/stream_ui.rbs +3 -0
  43. data/stdlib/rubygems/0/uninstaller.rbs +3 -0
  44. data/stdlib/rubygems/0/version.rbs +228 -0
  45. data/stdlib/strscan/0/string_scanner.rbs +582 -0
  46. metadata +23 -2
@@ -0,0 +1,2 @@
1
+ class Gem::SourceList
2
+ end
@@ -0,0 +1,3 @@
1
+ class Gem::Specification < Gem::BasicSpecification
2
+ # TODO: Add sinatures...
3
+ end
@@ -0,0 +1,3 @@
1
+ class Gem::StreamUI
2
+ # TODO: Add sinatures...
3
+ end
@@ -0,0 +1,3 @@
1
+ class Gem::Uninstaller
2
+ # TODO: Add sinatures...
3
+ end
@@ -0,0 +1,228 @@
1
+ module Gem
2
+ # The Version class processes string versions into comparable values. A version
3
+ # string should normally be a series of numbers separated by periods. Each part
4
+ # (digits separated by periods) is considered its own number, and these are used
5
+ # for sorting. So for instance, 3.10 sorts higher than 3.2 because ten is
6
+ # greater than two.
7
+ #
8
+ # If any part contains letters (currently only a-z are supported) then that
9
+ # version is considered prerelease. Versions with a prerelease part in the Nth
10
+ # part sort less than versions with N-1 parts. Prerelease parts are sorted
11
+ # alphabetically using the normal Ruby string sorting rules. If a prerelease
12
+ # part contains both letters and numbers, it will be broken into multiple parts
13
+ # to provide expected sort behavior (1.0.a10 becomes 1.0.a.10, and is greater
14
+ # than 1.0.a9).
15
+ #
16
+ # Prereleases sort between real releases (newest to oldest):
17
+ #
18
+ # 1. 1.0
19
+ # 2. 1.0.b1
20
+ # 3. 1.0.a.2
21
+ # 4. 0.9
22
+ #
23
+ #
24
+ # If you want to specify a version restriction that includes both prereleases
25
+ # and regular releases of the 1.x series this is the best way:
26
+ #
27
+ # s.add_dependency 'example', '>= 1.0.0.a', '< 2.0.0'
28
+ #
29
+ # ## How Software Changes
30
+ #
31
+ # Users expect to be able to specify a version constraint that gives them some
32
+ # reasonable expectation that new versions of a library will work with their
33
+ # software if the version constraint is true, and not work with their software
34
+ # if the version constraint is false. In other words, the perfect system will
35
+ # accept all compatible versions of the library and reject all incompatible
36
+ # versions.
37
+ #
38
+ # Libraries change in 3 ways (well, more than 3, but stay focused here!).
39
+ #
40
+ # 1. The change may be an implementation detail only and have no effect on the
41
+ # client software.
42
+ # 2. The change may add new features, but do so in a way that client software
43
+ # written to an earlier version is still compatible.
44
+ # 3. The change may change the public interface of the library in such a way
45
+ # that old software is no longer compatible.
46
+ #
47
+ #
48
+ # Some examples are appropriate at this point. Suppose I have a Stack class
49
+ # that supports a `push` and a `pop` method.
50
+ #
51
+ # ### Examples of Category 1 changes:
52
+ #
53
+ # * Switch from an array based implementation to a linked-list based
54
+ # implementation.
55
+ # * Provide an automatic (and transparent) backing store for large stacks.
56
+ #
57
+ #
58
+ # ### Examples of Category 2 changes might be:
59
+ #
60
+ # * Add a `depth` method to return the current depth of the stack.
61
+ # * Add a `top` method that returns the current top of stack (without changing
62
+ # the stack).
63
+ # * Change `push` so that it returns the item pushed (previously it had no
64
+ # usable return value).
65
+ #
66
+ #
67
+ # ### Examples of Category 3 changes might be:
68
+ #
69
+ # * Changes `pop` so that it no longer returns a value (you must use `top` to
70
+ # get the top of the stack).
71
+ # * Rename the methods to `push_item` and `pop_item`.
72
+ #
73
+ #
74
+ # ## RubyGems Rational Versioning
75
+ #
76
+ # * Versions shall be represented by three non-negative integers, separated by
77
+ # periods (e.g. 3.1.4). The first integers is the "major" version number,
78
+ # the second integer is the "minor" version number, and the third integer is
79
+ # the "build" number.
80
+ #
81
+ # * A category 1 change (implementation detail) will increment the build
82
+ # number.
83
+ #
84
+ # * A category 2 change (backwards compatible) will increment the minor
85
+ # version number and reset the build number.
86
+ #
87
+ # * A category 3 change (incompatible) will increment the major build number
88
+ # and reset the minor and build numbers.
89
+ #
90
+ # * Any "public" release of a gem should have a different version. Normally
91
+ # that means incrementing the build number. This means a developer can
92
+ # generate builds all day long, but as soon as they make a public release,
93
+ # the version must be updated.
94
+ #
95
+ #
96
+ # ### Examples
97
+ #
98
+ # Let's work through a project lifecycle using our Stack example from above.
99
+ #
100
+ # Version 0.0.1
101
+ # : The initial Stack class is release.
102
+ # Version 0.0.2
103
+ # : Switched to a linked=list implementation because it is cooler.
104
+ # Version 0.1.0
105
+ # : Added a `depth` method.
106
+ # Version 1.0.0
107
+ # : Added `top` and made `pop` return nil (`pop` used to return the old top
108
+ # item).
109
+ # Version 1.1.0
110
+ # : `push` now returns the value pushed (it used it return nil).
111
+ # Version 1.1.1
112
+ # : Fixed a bug in the linked list implementation.
113
+ # Version 1.1.2
114
+ # : Fixed a bug introduced in the last fix.
115
+ #
116
+ #
117
+ # Client A needs a stack with basic push/pop capability. They write to the
118
+ # original interface (no `top`), so their version constraint looks like:
119
+ #
120
+ # gem 'stack', '>= 0.0'
121
+ #
122
+ # Essentially, any version is OK with Client A. An incompatible change to the
123
+ # library will cause them grief, but they are willing to take the chance (we
124
+ # call Client A optimistic).
125
+ #
126
+ # Client B is just like Client A except for two things: (1) They use the `depth`
127
+ # method and (2) they are worried about future incompatibilities, so they write
128
+ # their version constraint like this:
129
+ #
130
+ # gem 'stack', '~> 0.1'
131
+ #
132
+ # The `depth` method was introduced in version 0.1.0, so that version or
133
+ # anything later is fine, as long as the version stays below version 1.0 where
134
+ # incompatibilities are introduced. We call Client B pessimistic because they
135
+ # are worried about incompatible future changes (it is OK to be pessimistic!).
136
+ #
137
+ # ## Preventing Version Catastrophe:
138
+ #
139
+ # From: http://blog.zenspider.com/2008/10/rubygems-howto-preventing-cata.html
140
+ #
141
+ # Let's say you're depending on the fnord gem version 2.y.z. If you specify your
142
+ # dependency as ">= 2.0.0" then, you're good, right? What happens if fnord 3.0
143
+ # comes out and it isn't backwards compatible with 2.y.z? Your stuff will break
144
+ # as a result of using ">=". The better route is to specify your dependency with
145
+ # an "approximate" version specifier ("~>"). They're a tad confusing, so here is
146
+ # how the dependency specifiers work:
147
+ #
148
+ # Specification From ... To (exclusive)
149
+ # ">= 3.0" 3.0 ... &infin;
150
+ # "~> 3.0" 3.0 ... 4.0
151
+ # "~> 3.0.0" 3.0.0 ... 3.1
152
+ # "~> 3.5" 3.5 ... 4.0
153
+ # "~> 3.5.0" 3.5.0 ... 3.6
154
+ # "~> 3" 3.0 ... 4.0
155
+ #
156
+ # For the last example, single-digit versions are automatically extended with a
157
+ # zero to give a sensible result.
158
+ #
159
+ class Version
160
+ include Comparable
161
+
162
+ # True if the `version` string matches RubyGems' requirements.
163
+ #
164
+ def self.correct?: (_ToS version) -> bool
165
+
166
+ # Factory method to create a Version object. Input may be a Version or a String.
167
+ # Intended to simplify client code.
168
+ #
169
+ # ver1 = Version.create('1.3.17') # -> (Version object)
170
+ # ver2 = Version.create(ver1) # -> (ver1)
171
+ # ver3 = Version.create(nil) # -> nil
172
+ #
173
+ def self.create: (_ToS | Version | nil input) -> instance?
174
+
175
+ # Constructs a Version from the `version` string. A version string is a series
176
+ # of digits or ASCII letters separated by dots.
177
+ #
178
+ def initialize: (_ToS version) -> void
179
+
180
+ # is larger, the same, or smaller than this one. Attempts to compare to
181
+ # something that's not a `Gem::Version` return `nil`.
182
+ #
183
+ def <=>: (untyped other) -> Integer?
184
+
185
+ # A recommended version for use with a ~> Requirement.
186
+ #
187
+ def approximate_recommendation: () -> String
188
+
189
+ # Return a new version object where the next to the last revision number is one
190
+ # greater (e.g., 5.3.1 => 5.4).
191
+ #
192
+ # Pre-release (alpha) parts, e.g, 5.3.1.b.2 => 5.4, are ignored.
193
+ #
194
+ def bump: () -> instance
195
+
196
+ def canonical_segments: () -> Array[Integer | String]
197
+
198
+ # A Version is only eql? to another version if it's specified to the same
199
+ # precision. Version "1.0" is not the same as version "1".
200
+ #
201
+ def eql?: (untyped other) -> bool
202
+
203
+ # Dump only the raw version string, not the complete object. It's a string for
204
+ # backwards (RubyGems 1.3.5 and earlier) compatibility.
205
+ #
206
+ def marshal_dump: () -> Array[String]
207
+
208
+ # Load custom marshal format. It's a string for backwards (RubyGems 1.3.5 and
209
+ # earlier) compatibility.
210
+ #
211
+ def marshal_load: (Array[String] array) -> void
212
+
213
+ # A version is considered a prerelease if it contains a letter.
214
+ #
215
+ def prerelease?: () -> bool
216
+
217
+ # The release for this version (e.g. 1.2.0.a -> 1.2.0). Non-prerelease versions
218
+ # return themselves.
219
+ #
220
+ def release: () -> instance
221
+
222
+ # A string representation of this Version.
223
+ #
224
+ def version: () -> String
225
+
226
+ alias to_s version
227
+ end
228
+ end
@@ -0,0 +1,582 @@
1
+ # StringScanner provides for lexical scanning operations on a String. Here is
2
+ # an example of its usage:
3
+ #
4
+ # s = StringScanner.new('This is an example string')
5
+ # s.eos? # -> false
6
+ #
7
+ # p s.scan(/\w+/) # -> "This"
8
+ # p s.scan(/\w+/) # -> nil
9
+ # p s.scan(/\s+/) # -> " "
10
+ # p s.scan(/\s+/) # -> nil
11
+ # p s.scan(/\w+/) # -> "is"
12
+ # s.eos? # -> false
13
+ #
14
+ # p s.scan(/\s+/) # -> " "
15
+ # p s.scan(/\w+/) # -> "an"
16
+ # p s.scan(/\s+/) # -> " "
17
+ # p s.scan(/\w+/) # -> "example"
18
+ # p s.scan(/\s+/) # -> " "
19
+ # p s.scan(/\w+/) # -> "string"
20
+ # s.eos? # -> true
21
+ #
22
+ # p s.scan(/\s+/) # -> nil
23
+ # p s.scan(/\w+/) # -> nil
24
+ #
25
+ # Scanning a string means remembering the position of a *scan pointer*, which is
26
+ # just an index. The point of scanning is to move forward a bit at a time, so
27
+ # matches are sought after the scan pointer; usually immediately after it.
28
+ #
29
+ # Given the string "test string", here are the pertinent scan pointer positions:
30
+ #
31
+ # t e s t s t r i n g
32
+ # 0 1 2 ... 1
33
+ # 0
34
+ #
35
+ # When you #scan for a pattern (a regular expression), the match must occur at
36
+ # the character after the scan pointer. If you use #scan_until, then the match
37
+ # can occur anywhere after the scan pointer. In both cases, the scan pointer
38
+ # moves *just beyond* the last character of the match, ready to scan again from
39
+ # the next character onwards. This is demonstrated by the example above.
40
+ #
41
+ # ## Method Categories
42
+ #
43
+ # There are other methods besides the plain scanners. You can look ahead in the
44
+ # string without actually scanning. You can access the most recent match. You
45
+ # can modify the string being scanned, reset or terminate the scanner, find out
46
+ # or change the position of the scan pointer, skip ahead, and so on.
47
+ #
48
+ # ### Advancing the Scan Pointer
49
+ #
50
+ # * #getch
51
+ # * #get_byte
52
+ # * #scan
53
+ # * #scan_until
54
+ # * #skip
55
+ # * #skip_until
56
+ #
57
+ #
58
+ # ### Looking Ahead
59
+ #
60
+ # * #check
61
+ # * #check_until
62
+ # * #exist?
63
+ # * #match?
64
+ # * #peek
65
+ #
66
+ #
67
+ # ### Finding Where we Are
68
+ #
69
+ # * #beginning_of_line? (#bol?)
70
+ # * #eos?
71
+ # * #rest?
72
+ # * #rest_size
73
+ # * #pos
74
+ #
75
+ #
76
+ # ### Setting Where we Are
77
+ #
78
+ # * #reset
79
+ # * #terminate
80
+ # * #pos=
81
+ #
82
+ #
83
+ # ### Match Data
84
+ #
85
+ # * #matched
86
+ # * #matched?
87
+ # * #matched_size
88
+ #
89
+ #
90
+ # :
91
+ # * #pre_match
92
+ # * #post_match
93
+ #
94
+ #
95
+ # ### Miscellaneous
96
+ #
97
+ # * <<
98
+ # * #concat
99
+ # * #string
100
+ # * #string=
101
+ # * #unscan
102
+ #
103
+ #
104
+ # There are aliases to several of the methods.
105
+ class StringScanner
106
+ # This method is defined for backward compatibility.
107
+ #
108
+ def self.must_C_version: () -> self
109
+
110
+ public
111
+
112
+ # Appends `str` to the string being scanned. This method does not affect scan
113
+ # pointer.
114
+ #
115
+ # s = StringScanner.new("Fri Dec 12 1975 14:39")
116
+ # s.scan(/Fri /)
117
+ # s << " +1000 GMT"
118
+ # s.string # -> "Fri Dec 12 1975 14:39 +1000 GMT"
119
+ # s.scan(/Dec/) # -> "Dec"
120
+ #
121
+ def <<: (String) -> self
122
+
123
+ # Returns the n-th subgroup in the most recent match.
124
+ #
125
+ # s = StringScanner.new("Fri Dec 12 1975 14:39")
126
+ # s.scan(/(\w+) (\w+) (\d+) /) # -> "Fri Dec 12 "
127
+ # s[0] # -> "Fri Dec 12 "
128
+ # s[1] # -> "Fri"
129
+ # s[2] # -> "Dec"
130
+ # s[3] # -> "12"
131
+ # s.post_match # -> "1975 14:39"
132
+ # s.pre_match # -> ""
133
+ #
134
+ # s.reset
135
+ # s.scan(/(?<wday>\w+) (?<month>\w+) (?<day>\d+) /) # -> "Fri Dec 12 "
136
+ # s[0] # -> "Fri Dec 12 "
137
+ # s[1] # -> "Fri"
138
+ # s[2] # -> "Dec"
139
+ # s[3] # -> "12"
140
+ # s[:wday] # -> "Fri"
141
+ # s[:month] # -> "Dec"
142
+ # s[:day] # -> "12"
143
+ # s.post_match # -> "1975 14:39"
144
+ # s.pre_match # -> ""
145
+ #
146
+ def []: (Integer) -> String?
147
+
148
+ # Returns `true` iff the scan pointer is at the beginning of the line.
149
+ #
150
+ # s = StringScanner.new("test\ntest\n")
151
+ # s.bol? # => true
152
+ # s.scan(/te/)
153
+ # s.bol? # => false
154
+ # s.scan(/st\n/)
155
+ # s.bol? # => true
156
+ # s.terminate
157
+ # s.bol? # => true
158
+ #
159
+ def beginning_of_line?: () -> bool
160
+
161
+ alias bol? beginning_of_line?
162
+
163
+ # Returns the subgroups in the most recent match (not including the full match).
164
+ # If nothing was priorly matched, it returns nil.
165
+ #
166
+ # s = StringScanner.new("Fri Dec 12 1975 14:39")
167
+ # s.scan(/(\w+) (\w+) (\d+) /) # -> "Fri Dec 12 "
168
+ # s.captures # -> ["Fri", "Dec", "12"]
169
+ # s.scan(/(\w+) (\w+) (\d+) /) # -> nil
170
+ # s.captures # -> nil
171
+ #
172
+ def captures: () -> Array[String]?
173
+
174
+ # Returns the character position of the scan pointer. In the 'reset' position,
175
+ # this value is zero. In the 'terminated' position (i.e. the string is
176
+ # exhausted), this value is the size of the string.
177
+ #
178
+ # In short, it's a 0-based index into the string.
179
+ #
180
+ # s = StringScanner.new("abcädeföghi")
181
+ # s.charpos # -> 0
182
+ # s.scan_until(/ä/) # -> "abcä"
183
+ # s.pos # -> 5
184
+ # s.charpos # -> 4
185
+ #
186
+ def charpos: () -> Integer
187
+
188
+ # This returns the value that #scan would return, without advancing the scan
189
+ # pointer. The match register is affected, though.
190
+ #
191
+ # s = StringScanner.new("Fri Dec 12 1975 14:39")
192
+ # s.check /Fri/ # -> "Fri"
193
+ # s.pos # -> 0
194
+ # s.matched # -> "Fri"
195
+ # s.check /12/ # -> nil
196
+ # s.matched # -> nil
197
+ #
198
+ # Mnemonic: it "checks" to see whether a #scan will return a value.
199
+ #
200
+ def check: (Regexp) -> String?
201
+
202
+ # This returns the value that #scan_until would return, without advancing the
203
+ # scan pointer. The match register is affected, though.
204
+ #
205
+ # s = StringScanner.new("Fri Dec 12 1975 14:39")
206
+ # s.check_until /12/ # -> "Fri Dec 12"
207
+ # s.pos # -> 0
208
+ # s.matched # -> 12
209
+ #
210
+ # Mnemonic: it "checks" to see whether a #scan_until will return a value.
211
+ #
212
+ def check_until: (Regexp) -> String
213
+
214
+ # Equivalent to #terminate. This method is obsolete; use #terminate instead.
215
+ #
216
+ def clear: () -> void
217
+
218
+ alias concat <<
219
+
220
+ # Equivalent to #eos?. This method is obsolete, use #eos? instead.
221
+ #
222
+ def empty?: () -> bool
223
+
224
+ # Returns `true` if the scan pointer is at the end of the string.
225
+ #
226
+ # s = StringScanner.new('test string')
227
+ # p s.eos? # => false
228
+ # s.scan(/test/)
229
+ # p s.eos? # => false
230
+ # s.terminate
231
+ # p s.eos? # => true
232
+ #
233
+ def eos?: () -> bool
234
+
235
+ # Looks *ahead* to see if the `pattern` exists *anywhere* in the string, without
236
+ # advancing the scan pointer. This predicates whether a #scan_until will return
237
+ # a value.
238
+ #
239
+ # s = StringScanner.new('test string')
240
+ # s.exist? /s/ # -> 3
241
+ # s.scan /test/ # -> "test"
242
+ # s.exist? /s/ # -> 2
243
+ # s.exist? /e/ # -> nil
244
+ #
245
+ def exist?: (Regexp) -> Integer?
246
+
247
+ # Whether `scanner` uses fixed anchor mode or not.
248
+ #
249
+ # If fixed anchor mode is used, `\A` always matches the beginning of the string.
250
+ # Otherwise, `\A` always matches the current position.
251
+ #
252
+ def fixed_anchor?: () -> bool
253
+
254
+ # Scans one byte and returns it. This method is not multibyte character
255
+ # sensitive. See also: #getch.
256
+ #
257
+ # s = StringScanner.new('ab')
258
+ # s.get_byte # => "a"
259
+ # s.get_byte # => "b"
260
+ # s.get_byte # => nil
261
+ #
262
+ # s = StringScanner.new("\244\242".force_encoding("euc-jp"))
263
+ # s.get_byte # => "\xA4"
264
+ # s.get_byte # => "\xA2"
265
+ # s.get_byte # => nil
266
+ #
267
+ def get_byte: () -> String?
268
+
269
+ # Equivalent to #get_byte. This method is obsolete; use #get_byte instead.
270
+ #
271
+ def getbyte: () -> String?
272
+
273
+ # Scans one character and returns it. This method is multibyte character
274
+ # sensitive.
275
+ #
276
+ # s = StringScanner.new("ab")
277
+ # s.getch # => "a"
278
+ # s.getch # => "b"
279
+ # s.getch # => nil
280
+ #
281
+ # s = StringScanner.new("\244\242".force_encoding("euc-jp"))
282
+ # s.getch # => "\x{A4A2}" # Japanese hira-kana "A" in EUC-JP
283
+ # s.getch # => nil
284
+ #
285
+ def getch: () -> String?
286
+
287
+ # Returns a string that represents the StringScanner object, showing:
288
+ # * the current position
289
+ # * the size of the string
290
+ # * the characters surrounding the scan pointer
291
+ #
292
+ # s = StringScanner.new("Fri Dec 12 1975 14:39") s.inspect # ->
293
+ # '#<StringScanner 0/21 @ "Fri D...">' s.scan_until /12/ # -> "Fri Dec
294
+ # 12" s.inspect # -> '#<StringScanner 10/21 "...ec 12" @ "
295
+ # 1975...">'
296
+ #
297
+ def inspect: () -> String
298
+
299
+ # Tests whether the given `pattern` is matched from the current scan pointer.
300
+ # Returns the length of the match, or `nil`. The scan pointer is not advanced.
301
+ #
302
+ # s = StringScanner.new('test string')
303
+ # p s.match?(/\w+/) # -> 4
304
+ # p s.match?(/\w+/) # -> 4
305
+ # p s.match?("test") # -> 4
306
+ # p s.match?(/\s+/) # -> nil
307
+ #
308
+ def match?: (Regexp) -> Integer?
309
+
310
+ # Returns the last matched string.
311
+ #
312
+ # s = StringScanner.new('test string')
313
+ # s.match?(/\w+/) # -> 4
314
+ # s.matched # -> "test"
315
+ #
316
+ def matched: () -> String?
317
+
318
+ # Returns `true` iff the last match was successful.
319
+ #
320
+ # s = StringScanner.new('test string')
321
+ # s.match?(/\w+/) # => 4
322
+ # s.matched? # => true
323
+ # s.match?(/\d+/) # => nil
324
+ # s.matched? # => false
325
+ #
326
+ def matched?: () -> bool
327
+
328
+ # Returns the size of the most recent match in bytes, or `nil` if there was no
329
+ # recent match. This is different than `matched.size`, which will return the
330
+ # size in characters.
331
+ #
332
+ # s = StringScanner.new('test string')
333
+ # s.check /\w+/ # -> "test"
334
+ # s.matched_size # -> 4
335
+ # s.check /\d+/ # -> nil
336
+ # s.matched_size # -> nil
337
+ #
338
+ def matched_size: () -> Integer?
339
+
340
+ # Extracts a string corresponding to `string[pos,len]`, without advancing the
341
+ # scan pointer.
342
+ #
343
+ # s = StringScanner.new('test string')
344
+ # s.peek(7) # => "test st"
345
+ # s.peek(7) # => "test st"
346
+ #
347
+ def peek: (Integer) -> String
348
+
349
+ # Equivalent to #peek. This method is obsolete; use #peek instead.
350
+ #
351
+ def peep: (Integer) -> String
352
+
353
+ # Returns the byte position of the scan pointer. In the 'reset' position, this
354
+ # value is zero. In the 'terminated' position (i.e. the string is exhausted),
355
+ # this value is the bytesize of the string.
356
+ #
357
+ # In short, it's a 0-based index into bytes of the string.
358
+ #
359
+ # s = StringScanner.new('test string')
360
+ # s.pos # -> 0
361
+ # s.scan_until /str/ # -> "test str"
362
+ # s.pos # -> 8
363
+ # s.terminate # -> #<StringScanner fin>
364
+ # s.pos # -> 11
365
+ #
366
+ def pointer: () -> Integer
367
+
368
+ # Sets the byte position of the scan pointer.
369
+ #
370
+ # s = StringScanner.new('test string')
371
+ # s.pos = 7 # -> 7
372
+ # s.rest # -> "ring"
373
+ #
374
+ def pointer=: (Integer) -> Integer
375
+
376
+ # Returns the byte position of the scan pointer. In the 'reset' position, this
377
+ # value is zero. In the 'terminated' position (i.e. the string is exhausted),
378
+ # this value is the bytesize of the string.
379
+ #
380
+ # In short, it's a 0-based index into bytes of the string.
381
+ #
382
+ # s = StringScanner.new('test string')
383
+ # s.pos # -> 0
384
+ # s.scan_until /str/ # -> "test str"
385
+ # s.pos # -> 8
386
+ # s.terminate # -> #<StringScanner fin>
387
+ # s.pos # -> 11
388
+ #
389
+ def pos: () -> Integer
390
+
391
+ # Sets the byte position of the scan pointer.
392
+ #
393
+ # s = StringScanner.new('test string')
394
+ # s.pos = 7 # -> 7
395
+ # s.rest # -> "ring"
396
+ #
397
+ def pos=: (Integer) -> Integer
398
+
399
+ # Returns the ***post**-match* (in the regular expression sense) of the last
400
+ # scan.
401
+ #
402
+ # s = StringScanner.new('test string')
403
+ # s.scan(/\w+/) # -> "test"
404
+ # s.scan(/\s+/) # -> " "
405
+ # s.pre_match # -> "test"
406
+ # s.post_match # -> "string"
407
+ #
408
+ def post_match: () -> String
409
+
410
+ # Returns the ***pre**-match* (in the regular expression sense) of the last
411
+ # scan.
412
+ #
413
+ # s = StringScanner.new('test string')
414
+ # s.scan(/\w+/) # -> "test"
415
+ # s.scan(/\s+/) # -> " "
416
+ # s.pre_match # -> "test"
417
+ # s.post_match # -> "string"
418
+ #
419
+ def pre_match: () -> String
420
+
421
+ # Reset the scan pointer (index 0) and clear matching data.
422
+ #
423
+ def reset: () -> void
424
+
425
+ # Returns the "rest" of the string (i.e. everything after the scan pointer). If
426
+ # there is no more data (eos? = true), it returns `""`.
427
+ #
428
+ def rest: () -> String
429
+
430
+ # Returns true iff there is more data in the string. See #eos?. This method is
431
+ # obsolete; use #eos? instead.
432
+ #
433
+ # s = StringScanner.new('test string')
434
+ # s.eos? # These two
435
+ # s.rest? # are opposites.
436
+ #
437
+ def rest?: () -> bool
438
+
439
+ # `s.rest_size` is equivalent to `s.rest.size`.
440
+ #
441
+ def rest_size: () -> Integer
442
+
443
+ # `s.restsize` is equivalent to `s.rest_size`. This method is obsolete; use
444
+ # #rest_size instead.
445
+ #
446
+ def restsize: () -> Integer
447
+
448
+ # Tries to match with `pattern` at the current position. If there's a match, the
449
+ # scanner advances the "scan pointer" and returns the matched string. Otherwise,
450
+ # the scanner returns `nil`.
451
+ #
452
+ # s = StringScanner.new('test string')
453
+ # p s.scan(/\w+/) # -> "test"
454
+ # p s.scan(/\w+/) # -> nil
455
+ # p s.scan(/\s+/) # -> " "
456
+ # p s.scan("str") # -> "str"
457
+ # p s.scan(/\w+/) # -> "ing"
458
+ # p s.scan(/./) # -> nil
459
+ #
460
+ def scan: (Regexp) -> String?
461
+
462
+ # Tests whether the given `pattern` is matched from the current scan pointer.
463
+ # Advances the scan pointer if `advance_pointer_p` is true. Returns the matched
464
+ # string if `return_string_p` is true. The match register is affected.
465
+ #
466
+ # "full" means "#scan with full parameters".
467
+ #
468
+ def scan_full: (Regexp pattern, bool advance_pointer_p, bool return_string_p) -> untyped
469
+
470
+ # Scans the string *until* the `pattern` is matched. Returns the substring up
471
+ # to and including the end of the match, advancing the scan pointer to that
472
+ # location. If there is no match, `nil` is returned.
473
+ #
474
+ # s = StringScanner.new("Fri Dec 12 1975 14:39")
475
+ # s.scan_until(/1/) # -> "Fri Dec 1"
476
+ # s.pre_match # -> "Fri Dec "
477
+ # s.scan_until(/XYZ/) # -> nil
478
+ #
479
+ def scan_until: (Regexp) -> String?
480
+
481
+ # Scans the string *until* the `pattern` is matched. Advances the scan pointer
482
+ # if `advance_pointer_p`, otherwise not. Returns the matched string if
483
+ # `return_string_p` is true, otherwise returns the number of bytes advanced.
484
+ # This method does affect the match register.
485
+ #
486
+ def search_full: (Regexp pattern, bool advance_pointer_p, bool return_string_p) -> untyped
487
+
488
+ # Returns the amount of subgroups in the most recent match. The full match
489
+ # counts as a subgroup.
490
+ #
491
+ # s = StringScanner.new("Fri Dec 12 1975 14:39")
492
+ # s.scan(/(\w+) (\w+) (\d+) /) # -> "Fri Dec 12 "
493
+ # s.size # -> 4
494
+ #
495
+ def size: () -> Integer
496
+
497
+ # Attempts to skip over the given `pattern` beginning with the scan pointer. If
498
+ # it matches, the scan pointer is advanced to the end of the match, and the
499
+ # length of the match is returned. Otherwise, `nil` is returned.
500
+ #
501
+ # It's similar to #scan, but without returning the matched string.
502
+ #
503
+ # s = StringScanner.new('test string')
504
+ # p s.skip(/\w+/) # -> 4
505
+ # p s.skip(/\w+/) # -> nil
506
+ # p s.skip(/\s+/) # -> 1
507
+ # p s.skip("st") # -> 2
508
+ # p s.skip(/\w+/) # -> 4
509
+ # p s.skip(/./) # -> nil
510
+ #
511
+ def skip: (Regexp) -> Integer?
512
+
513
+ # Advances the scan pointer until `pattern` is matched and consumed. Returns
514
+ # the number of bytes advanced, or `nil` if no match was found.
515
+ #
516
+ # Look ahead to match `pattern`, and advance the scan pointer to the *end* of
517
+ # the match. Return the number of characters advanced, or `nil` if the match
518
+ # was unsuccessful.
519
+ #
520
+ # It's similar to #scan_until, but without returning the intervening string.
521
+ #
522
+ # s = StringScanner.new("Fri Dec 12 1975 14:39")
523
+ # s.skip_until /12/ # -> 10
524
+ # s #
525
+ #
526
+ def skip_until: (Regexp) -> Integer?
527
+
528
+ # Returns the string being scanned.
529
+ #
530
+ def string: () -> String
531
+
532
+ # Changes the string being scanned to `str` and resets the scanner. Returns
533
+ # `str`.
534
+ #
535
+ def string=: (String) -> String
536
+
537
+ # Sets the scan pointer to the end of the string and clear matching data.
538
+ #
539
+ def terminate: () -> void
540
+
541
+ # Sets the scan pointer to the previous position. Only one previous position is
542
+ # remembered, and it changes with each scanning operation.
543
+ #
544
+ # s = StringScanner.new('test string')
545
+ # s.scan(/\w+/) # => "test"
546
+ # s.unscan
547
+ # s.scan(/../) # => "te"
548
+ # s.scan(/\d/) # => nil
549
+ # s.unscan # ScanError: unscan failed: previous match record not exist
550
+ #
551
+ def unscan: () -> void
552
+
553
+ # Returns the subgroups in the most recent match at the given indices. If
554
+ # nothing was priorly matched, it returns nil.
555
+ #
556
+ # s = StringScanner.new("Fri Dec 12 1975 14:39")
557
+ # s.scan(/(\w+) (\w+) (\d+) /) # -> "Fri Dec 12 "
558
+ # s.values_at 0, -1, 5, 2 # -> ["Fri Dec 12 ", "12", nil, "Dec"]
559
+ # s.scan(/(\w+) (\w+) (\d+) /) # -> nil
560
+ # s.values_at 0, -1, 5, 2 # -> nil
561
+ #
562
+ def values_at: (*Integer) -> Array[String]?
563
+
564
+ private
565
+
566
+ # Creates a new StringScanner object to scan over the given `string`.
567
+ #
568
+ # If `fixed_anchor` is `true`, `\A` always matches the beginning of the string.
569
+ # Otherwise, `\A` always matches the current position.
570
+ #
571
+ # `dup` argument is obsolete and not used now.
572
+ #
573
+ def initialize: (String, ?bool dup, ?fixed_anchor: bool) -> untyped
574
+
575
+ # Duplicates a StringScanner object.
576
+ #
577
+ def initialize_copy: (StringScanner) -> void
578
+ end
579
+
580
+ StringScanner::Id: String
581
+
582
+ StringScanner::Version: String