rbs 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/Rakefile +2 -0
  4. data/core/array.rbs +1 -1
  5. data/core/enumerable.rbs +1 -1
  6. data/core/hash.rbs +13 -5
  7. data/core/io.rbs +3 -3
  8. data/core/module.rbs +1 -1
  9. data/core/numeric.rbs +10 -0
  10. data/core/proc.rbs +1 -1
  11. data/core/random.rbs +4 -2
  12. data/core/range.rbs +2 -2
  13. data/core/struct.rbs +3 -2
  14. data/core/thread.rbs +1 -1
  15. data/docs/CONTRIBUTING.md +5 -3
  16. data/docs/sigs.md +18 -1
  17. data/docs/syntax.md +11 -11
  18. data/lib/rbs.rb +1 -0
  19. data/lib/rbs/ast/annotation.rb +2 -2
  20. data/lib/rbs/ast/comment.rb +2 -2
  21. data/lib/rbs/ast/declarations.rb +37 -22
  22. data/lib/rbs/ast/members.rb +26 -26
  23. data/lib/rbs/cli.rb +3 -0
  24. data/lib/rbs/constant_table.rb +4 -1
  25. data/lib/rbs/definition.rb +1 -1
  26. data/lib/rbs/definition_builder.rb +14 -0
  27. data/lib/rbs/definition_builder/ancestor_builder.rb +1 -0
  28. data/lib/rbs/definition_builder/method_builder.rb +4 -2
  29. data/lib/rbs/location.rb +106 -2
  30. data/lib/rbs/locator.rb +205 -0
  31. data/lib/rbs/method_type.rb +2 -2
  32. data/lib/rbs/parser.rb +1050 -713
  33. data/lib/rbs/parser.y +403 -71
  34. data/lib/rbs/test/hook.rb +8 -2
  35. data/lib/rbs/type_name.rb +2 -3
  36. data/lib/rbs/type_name_resolver.rb +1 -1
  37. data/lib/rbs/types.rb +36 -34
  38. data/lib/rbs/version.rb +1 -1
  39. data/lib/rbs/writer.rb +4 -2
  40. data/sig/annotation.rbs +1 -1
  41. data/sig/cli.rbs +31 -21
  42. data/sig/comment.rbs +1 -1
  43. data/sig/declarations.rbs +106 -21
  44. data/sig/environment.rbs +2 -2
  45. data/sig/location.rbs +84 -3
  46. data/sig/locator.rbs +44 -0
  47. data/sig/members.rbs +76 -12
  48. data/sig/method_builder.rbs +1 -1
  49. data/sig/method_types.rbs +1 -1
  50. data/sig/polyfill.rbs +13 -8
  51. data/sig/rbs.rbs +8 -4
  52. data/sig/typename.rbs +1 -1
  53. data/sig/types.rbs +60 -19
  54. data/sig/util.rbs +0 -4
  55. data/sig/writer.rbs +8 -2
  56. data/stdlib/rubygems/0/requirement.rbs +84 -2
  57. data/stdlib/rubygems/0/version.rbs +2 -1
  58. data/stdlib/shellwords/0/shellwords.rbs +252 -0
  59. data/steep/Gemfile.lock +16 -13
  60. metadata +5 -2
data/sig/util.rbs CHANGED
@@ -6,8 +6,4 @@ module RBS
6
6
 
7
7
  def hash: () -> Integer
8
8
  end
9
-
10
- interface _ToJson
11
- def to_json: (*untyped) -> String
12
- end
13
9
  end
data/sig/writer.rbs CHANGED
@@ -1,9 +1,15 @@
1
1
  module RBS
2
2
  class Writer
3
- attr_reader out: IO
3
+ interface _IO
4
+ def puts: (*untyped) -> void
5
+
6
+ def flush: () -> void
7
+ end
8
+
9
+ attr_reader out: _IO
4
10
  attr_reader indentation: Array[String]
5
11
 
6
- def initialize: (out: IO) -> void
12
+ def initialize: (out: _IO) -> void
7
13
 
8
14
  def indent: (?Integer size) { () -> void } -> void
9
15
 
@@ -1,3 +1,85 @@
1
- class Gem::Requirement
2
- # TODO: Add sinatures...
1
+ module Gem
2
+ # A Requirement is a set of one or more version restrictions. It supports a few
3
+ # (`=, !=, >, <, >=, <=, ~>`) different restriction operators.
4
+ #
5
+ # See Gem::Version for a description on how versions and requirements work
6
+ # together in RubyGems.
7
+ #
8
+ class Requirement
9
+ type operator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "~>"
10
+
11
+ # Raised when a bad requirement is encountered
12
+ #
13
+ class BadRequirementError < ArgumentError
14
+ end
15
+
16
+ # The default requirement matches any version
17
+ #
18
+ DefaultPrereleaseRequirement: [ operator, Gem::Version ]
19
+
20
+ # The default requirement matches any non-prerelease version
21
+ #
22
+ DefaultRequirement: [ operator, Gem::Version ]
23
+
24
+ # A regular expression that matches a requirement
25
+ #
26
+ PATTERN: Regexp
27
+
28
+ # Factory method to create a Gem::Requirement object. Input may be a Version, a
29
+ # String, or nil. Intended to simplify client code.
30
+ #
31
+ # If the input is "weird", the default version requirement is returned.
32
+ #
33
+ def self.create: (*(String | Gem::Version | Gem::Requirement | nil) inputs) -> instance
34
+
35
+ def self.default: () -> instance
36
+
37
+ def self.default_prerelease: () -> instance
38
+
39
+ # Parse `obj`, returning an `[op, version]` pair. `obj` can be a String or a
40
+ # Gem::Version.
41
+ #
42
+ # If `obj` is a String, it can be either a full requirement specification, like
43
+ # `">= 1.2"`, or a simple version number, like `"1.2"`.
44
+ #
45
+ # parse("> 1.0") # => [">", Gem::Version.new("1.0")]
46
+ # parse("1.0") # => ["=", Gem::Version.new("1.0")]
47
+ # parse(Gem::Version.new("1.0")) # => ["=, Gem::Version.new("1.0")]
48
+ #
49
+ def self.parse: (String | Gem::Version obj) -> [ operator, Gem::Version ]
50
+
51
+ # Constructs a requirement from `requirements`. Requirements can be Strings,
52
+ # Gem::Versions, or Arrays of those. `nil` and duplicate requirements are
53
+ # ignored. An empty set of `requirements` is the same as `">= 0"`.
54
+ #
55
+ def initialize: (*(String | Gem::Version) requirements) -> void
56
+
57
+ # Concatenates the `new` requirements onto this requirement.
58
+ #
59
+ def concat: (Array[String | Gem::Version] new) -> void
60
+
61
+ # true if the requirement is for only an exact version
62
+ #
63
+ def exact?: () -> bool
64
+
65
+ # true if this gem has no requirements.
66
+ #
67
+ def none?: () -> bool
68
+
69
+ # A requirement is a prerelease if any of the versions inside of it are
70
+ # prereleases
71
+ #
72
+ def prerelease?: () -> bool
73
+
74
+ # True if `version` satisfies this Requirement.
75
+ #
76
+ def satisfied_by?: (Gem::Version version) -> bool
77
+
78
+ alias === satisfied_by?
79
+ alias =~ satisfied_by?
80
+
81
+ # True if the requirement will not always match the latest version.
82
+ #
83
+ def specific?: () -> bool
84
+ end
3
85
  end
@@ -170,7 +170,8 @@ module Gem
170
170
  # ver2 = Version.create(ver1) # -> (ver1)
171
171
  # ver3 = Version.create(nil) # -> nil
172
172
  #
173
- def self.create: (_ToS | Version | nil input) -> instance?
173
+ def self.create: (_ToS | Version input) -> instance
174
+ | (nil input) -> nil
174
175
 
175
176
  # Constructs a Version from the `version` string. A version string is a series
176
177
  # of digits or ASCII letters separated by dots.
@@ -0,0 +1,252 @@
1
+ # ## Manipulates strings like the UNIX Bourne shell
2
+ #
3
+ # This module manipulates strings according to the word parsing rules of the
4
+ # UNIX Bourne shell.
5
+ #
6
+ # The shellwords() function was originally a port of shellwords.pl, but modified
7
+ # to conform to the Shell & Utilities volume of the IEEE Std 1003.1-2008, 2016
8
+ # Edition [1].
9
+ #
10
+ # ### Usage
11
+ #
12
+ # You can use Shellwords to parse a string into a Bourne shell friendly Array.
13
+ #
14
+ # require 'shellwords'
15
+ #
16
+ # argv = Shellwords.split('three blind "mice"')
17
+ # argv #=> ["three", "blind", "mice"]
18
+ #
19
+ # Once you've required Shellwords, you can use the #split alias
20
+ # String#shellsplit.
21
+ #
22
+ # argv = "see how they run".shellsplit
23
+ # argv #=> ["see", "how", "they", "run"]
24
+ #
25
+ # They treat quotes as special characters, so an unmatched quote will cause an
26
+ # ArgumentError.
27
+ #
28
+ # argv = "they all ran after the farmer's wife".shellsplit
29
+ # #=> ArgumentError: Unmatched quote: ...
30
+ #
31
+ # Shellwords also provides methods that do the opposite. Shellwords.escape, or
32
+ # its alias, String#shellescape, escapes shell metacharacters in a string for
33
+ # use in a command line.
34
+ #
35
+ # filename = "special's.txt"
36
+ #
37
+ # system("cat -- #{filename.shellescape}")
38
+ # # runs "cat -- special\\'s.txt"
39
+ #
40
+ # Note the '--'. Without it, cat(1) will treat the following argument as a
41
+ # command line option if it starts with '-'. It is guaranteed that
42
+ # Shellwords.escape converts a string to a form that a Bourne shell will parse
43
+ # back to the original string, but it is the programmer's responsibility to make
44
+ # sure that passing an arbitrary argument to a command does no harm.
45
+ #
46
+ # Shellwords also comes with a core extension for Array, Array#shelljoin.
47
+ #
48
+ # dir = "Funny GIFs"
49
+ # argv = %W[ls -lta -- #{dir}]
50
+ # system(argv.shelljoin + " | less")
51
+ # # runs "ls -lta -- Funny\\ GIFs | less"
52
+ #
53
+ # You can use this method to build a complete command line out of an array of
54
+ # arguments.
55
+ #
56
+ # ### Authors
57
+ # * Wakou Aoyama
58
+ # * Akinori MUSHA <knu@iDaemons.org>
59
+ #
60
+ #
61
+ # ### Contact
62
+ # * Akinori MUSHA <knu@iDaemons.org> (current maintainer)
63
+ #
64
+ #
65
+ # ### Resources
66
+ #
67
+ # 1: [IEEE Std 1003.1-2008, 2016 Edition, the Shell & Utilities
68
+ # volume](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.htm
69
+ # l)
70
+ module Shellwords
71
+ # Escapes a string so that it can be safely used in a Bourne shell command line.
72
+ # `str` can be a non-string object that responds to `to_s`.
73
+ #
74
+ # Note that a resulted string should be used unquoted and is not intended for
75
+ # use in double quotes nor in single quotes.
76
+ #
77
+ # argv = Shellwords.escape("It's better to give than to receive")
78
+ # argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
79
+ #
80
+ # String#shellescape is a shorthand for this function.
81
+ #
82
+ # argv = "It's better to give than to receive".shellescape
83
+ # argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
84
+ #
85
+ # # Search files in lib for method definitions
86
+ # pattern = "^[ \t]*def "
87
+ # open("| grep -Ern -e #{pattern.shellescape} lib") { |grep|
88
+ # grep.each_line { |line|
89
+ # file, lineno, matched_line = line.split(':', 3)
90
+ # # ...
91
+ # }
92
+ # }
93
+ #
94
+ # It is the caller's responsibility to encode the string in the right encoding
95
+ # for the shell environment where this string is used.
96
+ #
97
+ # Multibyte characters are treated as multibyte characters, not as bytes.
98
+ #
99
+ # Returns an empty quoted String if `str` has a length of zero.
100
+ #
101
+ def self.shellescape: (String str) -> String
102
+
103
+ # Builds a command line string from an argument list, `array`.
104
+ #
105
+ # All elements are joined into a single string with fields separated by a space,
106
+ # where each element is escaped for the Bourne shell and stringified using
107
+ # `to_s`.
108
+ #
109
+ # ary = ["There's", "a", "time", "and", "place", "for", "everything"]
110
+ # argv = Shellwords.join(ary)
111
+ # argv #=> "There\\'s a time and place for everything"
112
+ #
113
+ # Array#shelljoin is a shortcut for this function.
114
+ #
115
+ # ary = ["Don't", "rock", "the", "boat"]
116
+ # argv = ary.shelljoin
117
+ # argv #=> "Don\\'t rock the boat"
118
+ #
119
+ # You can also mix non-string objects in the elements as allowed in Array#join.
120
+ #
121
+ # output = `#{['ps', '-p', $$].shelljoin}`
122
+ #
123
+ def self.shelljoin: (Array[String] array) -> String
124
+
125
+ # Splits a string into an array of tokens in the same way the UNIX Bourne shell
126
+ # does.
127
+ #
128
+ # argv = Shellwords.split('here are "two words"')
129
+ # argv #=> ["here", "are", "two words"]
130
+ #
131
+ # Note, however, that this is not a command line parser. Shell metacharacters
132
+ # except for the single and double quotes and backslash are not treated as such.
133
+ #
134
+ # argv = Shellwords.split('ruby my_prog.rb | less')
135
+ # argv #=> ["ruby", "my_prog.rb", "|", "less"]
136
+ #
137
+ # String#shellsplit is a shortcut for this function.
138
+ #
139
+ # argv = 'here are "two words"'.shellsplit
140
+ # argv #=> ["here", "are", "two words"]
141
+ #
142
+ def self.shellsplit: (String line) -> Array[String]
143
+
144
+ alias self.escape self.shellescape
145
+
146
+ alias self.join self.shelljoin
147
+
148
+ alias self.shellwords self.shellsplit
149
+
150
+ alias self.split self.shellsplit
151
+
152
+ private
153
+
154
+ # Escapes a string so that it can be safely used in a Bourne shell command line.
155
+ # `str` can be a non-string object that responds to `to_s`.
156
+ #
157
+ # Note that a resulted string should be used unquoted and is not intended for
158
+ # use in double quotes nor in single quotes.
159
+ #
160
+ # argv = Shellwords.escape("It's better to give than to receive")
161
+ # argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
162
+ #
163
+ # String#shellescape is a shorthand for this function.
164
+ #
165
+ # argv = "It's better to give than to receive".shellescape
166
+ # argv #=> "It\\'s\\ better\\ to\\ give\\ than\\ to\\ receive"
167
+ #
168
+ # # Search files in lib for method definitions
169
+ # pattern = "^[ \t]*def "
170
+ # open("| grep -Ern -e #{pattern.shellescape} lib") { |grep|
171
+ # grep.each_line { |line|
172
+ # file, lineno, matched_line = line.split(':', 3)
173
+ # # ...
174
+ # }
175
+ # }
176
+ #
177
+ # It is the caller's responsibility to encode the string in the right encoding
178
+ # for the shell environment where this string is used.
179
+ #
180
+ # Multibyte characters are treated as multibyte characters, not as bytes.
181
+ #
182
+ # Returns an empty quoted String if `str` has a length of zero.
183
+ #
184
+ def shellescape: (String str) -> String
185
+
186
+ # Builds a command line string from an argument list, `array`.
187
+ #
188
+ # All elements are joined into a single string with fields separated by a space,
189
+ # where each element is escaped for the Bourne shell and stringified using
190
+ # `to_s`.
191
+ #
192
+ # ary = ["There's", "a", "time", "and", "place", "for", "everything"]
193
+ # argv = Shellwords.join(ary)
194
+ # argv #=> "There\\'s a time and place for everything"
195
+ #
196
+ # Array#shelljoin is a shortcut for this function.
197
+ #
198
+ # ary = ["Don't", "rock", "the", "boat"]
199
+ # argv = ary.shelljoin
200
+ # argv #=> "Don\\'t rock the boat"
201
+ #
202
+ # You can also mix non-string objects in the elements as allowed in Array#join.
203
+ #
204
+ # output = `#{['ps', '-p', $$].shelljoin}`
205
+ #
206
+ def shelljoin: (Array[String] array) -> String
207
+
208
+ # Splits a string into an array of tokens in the same way the UNIX Bourne shell
209
+ # does.
210
+ #
211
+ # argv = Shellwords.split('here are "two words"')
212
+ # argv #=> ["here", "are", "two words"]
213
+ #
214
+ # Note, however, that this is not a command line parser. Shell metacharacters
215
+ # except for the single and double quotes and backslash are not treated as such.
216
+ #
217
+ # argv = Shellwords.split('ruby my_prog.rb | less')
218
+ # argv #=> ["ruby", "my_prog.rb", "|", "less"]
219
+ #
220
+ # String#shellsplit is a shortcut for this function.
221
+ #
222
+ # argv = 'here are "two words"'.shellsplit
223
+ # argv #=> ["here", "are", "two words"]
224
+ #
225
+ def shellsplit: (String line) -> Array[String]
226
+
227
+ alias shellwords shellsplit
228
+ end
229
+
230
+ class Array[unchecked out Elem]
231
+ # Builds a command line string from an argument list `array` joining all
232
+ # elements escaped for the Bourne shell and separated by a space.
233
+ #
234
+ # See Shellwords.shelljoin for details.
235
+ #
236
+ def shelljoin: () -> String
237
+ end
238
+
239
+ class String
240
+ # Escapes `str` so that it can be safely used in a Bourne shell command line.
241
+ #
242
+ # See Shellwords.shellescape for details.
243
+ #
244
+ def shellescape: () -> String
245
+
246
+ # Splits `str` into an array of tokens in the same way the UNIX Bourne shell
247
+ # does.
248
+ #
249
+ # See Shellwords.shellsplit for details.
250
+ #
251
+ def shellsplit: () -> Array[String]
252
+ end
data/steep/Gemfile.lock CHANGED
@@ -1,41 +1,44 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (6.1.2.1)
4
+ activesupport (6.1.3.1)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.2)
6
6
  i18n (>= 1.6, < 2)
7
7
  minitest (>= 5.1)
8
8
  tzinfo (~> 2.0)
9
9
  zeitwerk (~> 2.3)
10
10
  ast (2.4.2)
11
- ast_utils (0.4.0)
12
- parser (>= 2.7.0)
13
11
  concurrent-ruby (1.1.8)
14
- ffi (1.14.2)
15
- i18n (1.8.8)
12
+ ffi (1.15.0)
13
+ i18n (1.8.10)
16
14
  concurrent-ruby (~> 1.0)
17
- language_server-protocol (3.15.0.1)
18
- listen (3.4.1)
15
+ language_server-protocol (3.16.0.0)
16
+ listen (3.5.1)
19
17
  rb-fsevent (~> 0.10, >= 0.10.3)
20
18
  rb-inotify (~> 0.9, >= 0.9.10)
21
- minitest (5.14.3)
19
+ minitest (5.14.4)
20
+ parallel (1.20.1)
22
21
  parser (3.0.0.0)
23
22
  ast (~> 2.4.1)
24
23
  rainbow (3.0.0)
25
24
  rb-fsevent (0.10.4)
26
25
  rb-inotify (0.10.1)
27
26
  ffi (~> 1.0)
28
- rbs (1.0.4)
29
- steep (0.41.0)
27
+ rbs (1.1.1)
28
+ steep (0.43.1)
30
29
  activesupport (>= 5.1)
31
- ast_utils (>= 0.4.0)
32
- language_server-protocol (~> 3.15.0.1)
30
+ language_server-protocol (>= 3.15, < 4.0)
33
31
  listen (~> 3.0)
32
+ parallel (>= 1.0.0)
34
33
  parser (>= 2.7)
35
34
  rainbow (>= 2.2.2, < 4.0)
36
- rbs (~> 1.0.3)
35
+ rbs (~> 1.1.0)
36
+ terminal-table (>= 2, < 4)
37
+ terminal-table (3.0.0)
38
+ unicode-display_width (~> 1.1, >= 1.1.1)
37
39
  tzinfo (2.0.4)
38
40
  concurrent-ruby (~> 1.0)
41
+ unicode-display_width (1.7.0)
39
42
  zeitwerk (2.4.2)
40
43
 
41
44
  PLATFORMS
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RBS is the language for type signatures for Ruby and standard library
14
14
  definitions.
@@ -123,6 +123,7 @@ files:
123
123
  - lib/rbs/errors.rb
124
124
  - lib/rbs/factory.rb
125
125
  - lib/rbs/location.rb
126
+ - lib/rbs/locator.rb
126
127
  - lib/rbs/method_type.rb
127
128
  - lib/rbs/namespace.rb
128
129
  - lib/rbs/parser.rb
@@ -177,6 +178,7 @@ files:
177
178
  - sig/environment_walker.rbs
178
179
  - sig/errors.rbs
179
180
  - sig/location.rbs
181
+ - sig/locator.rbs
180
182
  - sig/members.rbs
181
183
  - sig/method_builder.rbs
182
184
  - sig/method_types.rbs
@@ -242,6 +244,7 @@ files:
242
244
  - stdlib/rubygems/0/version.rbs
243
245
  - stdlib/securerandom/0/securerandom.rbs
244
246
  - stdlib/set/0/set.rbs
247
+ - stdlib/shellwords/0/shellwords.rbs
245
248
  - stdlib/singleton/0/singleton.rbs
246
249
  - stdlib/strscan/0/string_scanner.rbs
247
250
  - stdlib/time/0/time.rbs