rbs 2.0.0 → 2.2.2
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.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +34 -0
- data/.github/workflows/ruby.yml +5 -0
- data/CHANGELOG.md +82 -0
- data/README.md +6 -1
- data/Rakefile +56 -21
- data/core/array.rbs +2866 -1086
- data/core/basic_object.rbs +150 -30
- data/core/binding.rbs +33 -0
- data/core/builtin.rbs +4 -4
- data/core/class.rbs +43 -5
- data/core/comparable.rbs +57 -0
- data/core/complex.rbs +170 -4
- data/core/constants.rbs +51 -0
- data/core/deprecated.rbs +7 -0
- data/core/dir.rbs +305 -20
- data/core/encoding.rbs +1214 -77
- data/core/enumerable.rbs +2173 -234
- data/core/enumerator.rbs +448 -182
- data/core/env.rbs +448 -1
- data/core/errno.rbs +1 -10
- data/core/errors.rbs +152 -2
- data/core/exception.rbs +201 -127
- data/core/false_class.rbs +27 -0
- data/core/fiber.rbs +118 -37
- data/core/fiber_error.rbs +8 -9
- data/core/file.rbs +1060 -142
- data/core/file_test.rbs +287 -32
- data/core/float.rbs +776 -300
- data/core/gc.rbs +185 -34
- data/core/global_variables.rbs +5 -1
- data/core/hash.rbs +1582 -649
- data/core/integer.rbs +974 -204
- data/core/io/buffer.rbs +710 -0
- data/core/io/wait.rbs +29 -8
- data/core/io.rbs +2438 -417
- data/core/kernel.rbs +2319 -318
- data/core/marshal.rbs +37 -2
- data/core/match_data.rbs +123 -6
- data/core/math.rbs +126 -6
- data/core/method.rbs +226 -102
- data/core/module.rbs +421 -45
- data/core/nil_class.rbs +64 -0
- data/core/numeric.rbs +620 -142
- data/core/object.rbs +453 -81
- data/core/object_space.rbs +92 -2
- data/core/proc.rbs +482 -285
- data/core/process.rbs +443 -34
- data/core/ractor.rbs +232 -9
- data/core/random.rbs +151 -52
- data/core/range.rbs +885 -160
- data/core/rational.rbs +122 -6
- data/core/rb_config.rbs +14 -4
- data/core/refinement.rbs +44 -0
- data/core/regexp.rbs +156 -14
- data/core/ruby_vm.rbs +42 -3
- data/core/signal.rbs +78 -39
- data/core/string.rbs +2123 -567
- data/core/string_io.rbs +204 -0
- data/core/struct.rbs +283 -28
- data/core/symbol.rbs +304 -30
- data/core/thread.rbs +1288 -688
- data/core/thread_group.rbs +66 -10
- data/core/time.rbs +643 -217
- data/core/trace_point.rbs +100 -12
- data/core/true_class.rbs +24 -0
- data/core/unbound_method.rbs +73 -7
- data/core/warning.rbs +37 -12
- data/docs/CONTRIBUTING.md +40 -34
- data/docs/stdlib.md +3 -102
- data/docs/syntax.md +54 -11
- data/ext/rbs_extension/extconf.rb +1 -0
- data/ext/rbs_extension/lexer.h +5 -0
- data/ext/rbs_extension/lexstate.c +6 -0
- data/ext/rbs_extension/parser.c +85 -10
- data/ext/rbs_extension/ruby_objs.c +4 -2
- data/ext/rbs_extension/ruby_objs.h +2 -2
- data/goodcheck.yml +0 -11
- data/lib/rbs/annotate/annotations.rb +197 -0
- data/lib/rbs/annotate/formatter.rb +80 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
- data/lib/rbs/annotate/rdoc_source.rb +120 -0
- data/lib/rbs/annotate.rb +6 -0
- data/lib/rbs/ast/members.rb +21 -13
- data/lib/rbs/buffer.rb +17 -11
- data/lib/rbs/cli.rb +48 -1
- data/lib/rbs/definition_builder/method_builder.rb +28 -16
- data/lib/rbs/definition_builder.rb +6 -2
- data/lib/rbs/environment.rb +8 -4
- data/lib/rbs/location_aux.rb +12 -0
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/prototype/rb.rb +12 -0
- data/lib/rbs/type_alias_regularity.rb +6 -4
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +1 -1
- data/lib/rbs/validator.rb +6 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +54 -4
- data/lib/rbs.rb +0 -2
- data/schema/typeParam.json +3 -3
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/buffer.rbs +6 -2
- data/sig/cli.rbs +2 -0
- data/sig/collection/{collections.rbs → sources.rbs} +0 -0
- data/sig/location.rbs +6 -0
- data/sig/members.rbs +24 -18
- data/sig/method_builder.rbs +5 -4
- data/sig/method_types.rbs +5 -1
- data/sig/polyfill.rbs +78 -0
- data/sig/validator.rbs +3 -1
- data/sig/writer.rbs +79 -2
- data/stdlib/abbrev/0/abbrev.rbs +6 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +31 -0
- data/stdlib/benchmark/0/benchmark.rbs +74 -3
- data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
- data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
- data/stdlib/cgi/0/core.rbs +649 -21
- data/stdlib/coverage/0/coverage.rbs +164 -2
- data/stdlib/csv/0/csv.rbs +2862 -398
- data/stdlib/date/0/date.rbs +483 -25
- data/stdlib/date/0/date_time.rbs +187 -12
- data/stdlib/dbm/0/dbm.rbs +152 -17
- data/stdlib/digest/0/digest.rbs +146 -0
- data/stdlib/erb/0/erb.rbs +65 -245
- data/stdlib/fiber/0/fiber.rbs +73 -91
- data/stdlib/fileutils/0/fileutils.rbs +301 -1
- data/stdlib/find/0/find.rbs +9 -0
- data/stdlib/forwardable/0/forwardable.rbs +65 -1
- data/stdlib/io-console/0/io-console.rbs +227 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
- data/stdlib/json/0/json.rbs +1147 -145
- data/stdlib/logger/0/formatter.rbs +24 -0
- data/stdlib/logger/0/log_device.rbs +64 -0
- data/stdlib/logger/0/logger.rbs +165 -13
- data/stdlib/logger/0/period.rbs +10 -0
- data/stdlib/logger/0/severity.rbs +26 -0
- data/stdlib/monitor/0/monitor.rbs +163 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
- data/stdlib/net-http/0/manifest.yaml +1 -0
- data/stdlib/net-http/0/net-http.rbs +1513 -683
- data/stdlib/nkf/0/nkf.rbs +372 -0
- data/stdlib/objspace/0/objspace.rbs +149 -90
- data/stdlib/openssl/0/openssl.rbs +8108 -71
- data/stdlib/optparse/0/optparse.rbs +487 -19
- data/stdlib/pathname/0/pathname.rbs +425 -124
- data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
- data/stdlib/prime/0/integer-extension.rbs +20 -2
- data/stdlib/prime/0/prime.rbs +88 -21
- data/stdlib/pstore/0/pstore.rbs +102 -0
- data/stdlib/pty/0/pty.rbs +64 -14
- data/stdlib/resolv/0/resolv.rbs +420 -31
- data/stdlib/rubygems/0/basic_specification.rbs +4 -1
- data/stdlib/rubygems/0/config_file.rbs +33 -1
- data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
- data/stdlib/rubygems/0/installer.rbs +13 -1
- data/stdlib/rubygems/0/path_support.rbs +4 -1
- data/stdlib/rubygems/0/platform.rbs +5 -1
- data/stdlib/rubygems/0/request_set.rbs +44 -2
- data/stdlib/rubygems/0/requirement.rbs +65 -2
- data/stdlib/rubygems/0/rubygems.rbs +407 -0
- data/stdlib/rubygems/0/source_list.rbs +13 -0
- data/stdlib/rubygems/0/specification.rbs +21 -1
- data/stdlib/rubygems/0/stream_ui.rbs +3 -1
- data/stdlib/rubygems/0/uninstaller.rbs +8 -1
- data/stdlib/rubygems/0/version.rbs +60 -157
- data/stdlib/securerandom/0/securerandom.rbs +44 -0
- data/stdlib/set/0/set.rbs +423 -109
- data/stdlib/shellwords/0/shellwords.rbs +55 -77
- data/stdlib/singleton/0/singleton.rbs +20 -0
- data/stdlib/socket/0/addrinfo.rbs +210 -9
- data/stdlib/socket/0/basic_socket.rbs +103 -11
- data/stdlib/socket/0/ip_socket.rbs +31 -9
- data/stdlib/socket/0/socket.rbs +586 -38
- data/stdlib/socket/0/tcp_server.rbs +22 -2
- data/stdlib/socket/0/tcp_socket.rbs +12 -1
- data/stdlib/socket/0/udp_socket.rbs +25 -2
- data/stdlib/socket/0/unix_server.rbs +22 -2
- data/stdlib/socket/0/unix_socket.rbs +45 -5
- data/stdlib/strscan/0/string_scanner.rbs +210 -9
- data/stdlib/tempfile/0/tempfile.rbs +58 -10
- data/stdlib/time/0/time.rbs +208 -116
- data/stdlib/timeout/0/timeout.rbs +10 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
- data/stdlib/tsort/0/cyclic.rbs +1 -0
- data/stdlib/tsort/0/interfaces.rbs +1 -0
- data/stdlib/tsort/0/tsort.rbs +42 -0
- data/stdlib/uri/0/common.rbs +57 -8
- data/stdlib/uri/0/file.rbs +55 -109
- data/stdlib/uri/0/ftp.rbs +6 -3
- data/stdlib/uri/0/generic.rbs +558 -329
- data/stdlib/uri/0/http.rbs +60 -114
- data/stdlib/uri/0/https.rbs +8 -102
- data/stdlib/uri/0/ldap.rbs +143 -137
- data/stdlib/uri/0/ldaps.rbs +8 -102
- data/stdlib/uri/0/mailto.rbs +3 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
- data/stdlib/uri/0/ws.rbs +6 -3
- data/stdlib/uri/0/wss.rbs +5 -3
- data/stdlib/yaml/0/dbm.rbs +151 -87
- data/stdlib/yaml/0/store.rbs +6 -0
- data/stdlib/zlib/0/zlib.rbs +90 -31
- metadata +18 -6
- data/lib/rbs/location.rb +0 -221
- data/sig/char_scanner.rbs +0 -9
data/docs/stdlib.md
CHANGED
|
@@ -1,109 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Testing Core API and Standard Library Types
|
|
2
2
|
|
|
3
|
-
This is a guide for
|
|
4
|
-
|
|
5
|
-
The typical steps of writing signatures will be like the following:
|
|
6
|
-
|
|
7
|
-
1. Generate a prototype
|
|
8
|
-
2. Import RDoc document
|
|
9
|
-
3. Give correct types to the prototype
|
|
10
|
-
4. Add tests
|
|
11
|
-
|
|
12
|
-
## Signatures
|
|
13
|
-
|
|
14
|
-
Signatures for builtin libraries are located in `core` directory. Also, signatures for standard libraries are located in `stdlib` directory.
|
|
15
|
-
|
|
16
|
-
To write signatures see [syntax guide](syntax.md).
|
|
17
|
-
|
|
18
|
-
## Generating prototypes
|
|
19
|
-
|
|
20
|
-
`rbs` provides a tool to generate a prototype of signatures, `rbs prototype`.
|
|
21
|
-
It provides several options, `rbi` from Sorbet RBI files, `rb` from Ruby code, and `runtime` from runtime API.
|
|
22
|
-
`runtime` should be the best option for standard libraries because they may be implemented in C, no Ruby source code.
|
|
23
|
-
|
|
24
|
-
The tool `require`s all of the libraries specified with `-r` option, and then use introspection APIs like `instance_methods` to know the structure of the class.
|
|
25
|
-
The commandline receives the name of classes you want to prototype, exact class name (like `Pathname`) or pattern with `*` (like `IO::*`).
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
$ bundle exec rbs prototype runtime --require pathname Pathname
|
|
29
|
-
class Pathname
|
|
30
|
-
def self.getwd: () -> untyped
|
|
31
|
-
|
|
32
|
-
def self.glob: (*untyped) -> untyped
|
|
33
|
-
|
|
34
|
-
def self.pwd: () -> untyped
|
|
35
|
-
|
|
36
|
-
def +: (untyped other) -> untyped
|
|
37
|
-
|
|
38
|
-
alias / +
|
|
39
|
-
|
|
40
|
-
def <=>: (untyped) -> untyped
|
|
41
|
-
|
|
42
|
-
# snip
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# snip
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
The prototype includes:
|
|
49
|
-
|
|
50
|
-
* Instance method definitions,
|
|
51
|
-
* Singleton method definitions,
|
|
52
|
-
* Includes, and
|
|
53
|
-
* Constants
|
|
54
|
-
|
|
55
|
-
It generate a simple prototype in the sense that all of the types included are `untyped`.
|
|
56
|
-
But it will help you to have an overview of the signatures you are trying to write.
|
|
57
|
-
|
|
58
|
-
### What to do with existing RBS files
|
|
59
|
-
|
|
60
|
-
Generating prototypes will overwrite existing RBS files, which might be undesirable.
|
|
61
|
-
You can try to find missing parts, or you can start from the scratch.
|
|
62
|
-
|
|
63
|
-
One non-trivial but absolutely better solution is to make a tool:
|
|
64
|
-
|
|
65
|
-
1. To load type definitions from existing RBS file, and
|
|
66
|
-
2. Generate prototypes only for missing methods.
|
|
67
|
-
|
|
68
|
-
## Import RDoc document
|
|
69
|
-
|
|
70
|
-
The next step should be importing RDoc documents.
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
$ bin/annotate-with-rdoc stdlib/pathname/0/pathname.rbs
|
|
74
|
-
Loading store from /Users/soutaro/.rbenv/versions/2.7.0-dev/share/ri/2.7.0/system...
|
|
75
|
-
Loading store from /Users/soutaro/.rbenv/versions/2.7.0-dev/share/ri/2.7.0/site...
|
|
76
|
-
Opening stdlib/pathname/pathname.rbs...
|
|
77
|
-
Importing documentation for Pathname...
|
|
78
|
-
Processing glob...
|
|
79
|
-
Processing +...
|
|
80
|
-
# snip
|
|
81
|
-
Writing stdlib/pathname/pathname.rbs...
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
The `annotate-with-rdoc` command adds annotations to RBS files.
|
|
85
|
-
|
|
86
|
-
1. Query RDoc documents to annotate classes, modules, methods, and constants,
|
|
87
|
-
2. Put annotations on RBS AST, and
|
|
88
|
-
3. Update the given .RBS files
|
|
89
|
-
|
|
90
|
-
We recommend using the command to annotate the RBS files.
|
|
91
|
-
|
|
92
|
-
## Writing types
|
|
93
|
-
|
|
94
|
-
The next step is to replace `untyped` types in the prototype.
|
|
95
|
-
See [syntax guide](syntax.md) for the detail of the syntax.
|
|
96
|
-
|
|
97
|
-
We can show some of the guides for writing types.
|
|
98
|
-
|
|
99
|
-
1. Use `bool` for truth values, truthy or falsey. More specific types like `TrueClass | FalseClass` may be too strict.
|
|
100
|
-
2. Use `void` if the return value is useless.
|
|
101
|
-
3. Use `nil` instead of `NilClass`.
|
|
102
|
-
4. The most strict types may not be the best types. Use `untyped` if you cannot find the best one.
|
|
3
|
+
This is a guide for testing core/stdlib types.
|
|
103
4
|
|
|
104
5
|
## Add Tests
|
|
105
6
|
|
|
106
|
-
We support writing tests for stdlib signatures.
|
|
7
|
+
We support writing tests for core/stdlib signatures.
|
|
107
8
|
|
|
108
9
|
### Writing tests
|
|
109
10
|
|
data/docs/syntax.md
CHANGED
|
@@ -279,13 +279,12 @@ _member_ ::= _ivar-member_ # Ivar definition
|
|
|
279
279
|
| _extend-member_ # Mixin (extend)
|
|
280
280
|
| _prepend-member_ # Mixin (prepend)
|
|
281
281
|
| _alias-member_ # Alias
|
|
282
|
-
|
|
|
283
|
-
| `private` # Private
|
|
282
|
+
| _visibility-member_ # Visibility member
|
|
284
283
|
|
|
285
284
|
_ivar-member_ ::= _ivar-name_ `:` _type_
|
|
286
285
|
|
|
287
|
-
_method-member_ ::= `def` _method-name_ `:` _method-types_ # Instance method
|
|
288
|
-
| `def self.` _method-name_ `:` _method-types_ # Singleton method
|
|
286
|
+
_method-member_ ::= _visibility_ `def` _method-name_ `:` _method-types_ # Instance method
|
|
287
|
+
| _visibility_ `def self.` _method-name_ `:` _method-types_ # Singleton method
|
|
289
288
|
| `def self?.` _method-name_ `:` _method-types_ # Singleton and instance method
|
|
290
289
|
|
|
291
290
|
_method-types_ ::= _method-type-parameters_ _method-type_ # Single method type
|
|
@@ -295,9 +294,11 @@ _method-types_ ::= _method-type-parameters_ _method-type_
|
|
|
295
294
|
_method-type-parameters_ ::= # Empty
|
|
296
295
|
| `[` _type-variable_ `,` ... `]`
|
|
297
296
|
|
|
298
|
-
_attribute-member_ ::= _attribute-type_ _method-name_ `:` _type_ # Attribute
|
|
299
|
-
| _attribute-type_ _method-name_ `(` _ivar-name_ `) :` _type_ # Attribute with variable name specification
|
|
300
|
-
| _attribute-type_ _method-name_ `() :` _type_ # Attribute without variable
|
|
297
|
+
_attribute-member_ ::= _visibility_ _attribute-type_ _method-name_ `:` _type_ # Attribute
|
|
298
|
+
| _visibility_ _attribute-type_ _method-name_ `(` _ivar-name_ `) :` _type_ # Attribute with variable name specification
|
|
299
|
+
| _visibility_ _attribute-type_ _method-name_ `() :` _type_ # Attribute without variable
|
|
300
|
+
|
|
301
|
+
_visibility_ ::= `public` | `private`
|
|
301
302
|
|
|
302
303
|
_attribute-type_ ::= `attr_reader` | `attr_writer` | `attr_accessor`
|
|
303
304
|
|
|
@@ -310,6 +311,8 @@ _prepend-member_ ::= `prepend` _class-name_ _type-arguments_
|
|
|
310
311
|
_alias-member_ ::= `alias` _method-name_ _method-name_
|
|
311
312
|
| `alias self.` _method-name_ `self.` _method-name_
|
|
312
313
|
|
|
314
|
+
_visibility-member_ ::= _visibility_
|
|
315
|
+
|
|
313
316
|
_ivar-name_ ::= /@\w+/
|
|
314
317
|
_method-name_ ::= ...
|
|
315
318
|
| /`[^`]+`/
|
|
@@ -328,7 +331,7 @@ An instance variable definition consists of the name of an instance variable and
|
|
|
328
331
|
|
|
329
332
|
Method definition has several syntax variations.
|
|
330
333
|
|
|
331
|
-
You can write `self.` or `self?.` before the name of the method to specify the kind of method: instance, singleton, or
|
|
334
|
+
You can write `self.` or `self?.` before the name of the method to specify the kind of method: instance, singleton, or module function.
|
|
332
335
|
|
|
333
336
|
```
|
|
334
337
|
def to_s: () -> String # Defines a instance method
|
|
@@ -336,6 +339,8 @@ def self.new: () -> AnObject # Defines singleton method
|
|
|
336
339
|
def self?.sqrt: (Numeric) -> Numeric # self? is for `module_function`s
|
|
337
340
|
```
|
|
338
341
|
|
|
342
|
+
`self?` method definition adds two methods: a public singleton method and a private instance method, which is equivalent to `module_function` in Ruby.
|
|
343
|
+
|
|
339
344
|
The method type can be connected with `|`s to define an overloaded method.
|
|
340
345
|
|
|
341
346
|
```
|
|
@@ -351,6 +356,16 @@ def +: (Float | Integer) -> (Float | Integer)
|
|
|
351
356
|
| (Numeric) -> Numeric
|
|
352
357
|
```
|
|
353
358
|
|
|
359
|
+
Adding `public` and `private` modifier changes the visibility of the method.
|
|
360
|
+
|
|
361
|
+
```
|
|
362
|
+
private def puts: (*untyped) -> void # Defines private instance method
|
|
363
|
+
|
|
364
|
+
public def self.puts: (*untyped) -> void # Defines public singleton method
|
|
365
|
+
|
|
366
|
+
public def self?.puts: (*untyped) -> void # 🚨🚨🚨 Error: `?.` has own visibility semantics (== `module_function`) 🚨🚨🚨
|
|
367
|
+
```
|
|
368
|
+
|
|
354
369
|
### Attribute definition
|
|
355
370
|
|
|
356
371
|
Attribute definitions help to define methods and instance variables based on the convention of `attr_reader`, `attr_writer` and `attr_accessor` methods in Ruby.
|
|
@@ -374,6 +389,14 @@ attr_accessor people (): Array[Person]
|
|
|
374
389
|
# def people=: (Array[Person]) -> Array[Person]
|
|
375
390
|
```
|
|
376
391
|
|
|
392
|
+
Attribute definitions can have the `public` and `private` modifiers like method definitions:
|
|
393
|
+
|
|
394
|
+
```
|
|
395
|
+
private attr_accessor id: Integer
|
|
396
|
+
|
|
397
|
+
private attr_reader self.name: String
|
|
398
|
+
```
|
|
399
|
+
|
|
377
400
|
### Mixin (include), Mixin (extend), Mixin (prepend)
|
|
378
401
|
|
|
379
402
|
You can define mixins between class and modules.
|
|
@@ -402,11 +425,31 @@ def map: [X] () { (String) -> X } -> Array[X]
|
|
|
402
425
|
alias collect map # `#collect` has the same type with `map`
|
|
403
426
|
```
|
|
404
427
|
|
|
405
|
-
###
|
|
428
|
+
### Visibility member
|
|
429
|
+
|
|
430
|
+
Visibility member allows specifying the default visibility of instance methods and instance attributes.
|
|
431
|
+
|
|
432
|
+
```rbs
|
|
433
|
+
public
|
|
434
|
+
|
|
435
|
+
def foo: () -> void # public instance method
|
|
436
|
+
|
|
437
|
+
attr_reader name: String # public instance attribute
|
|
438
|
+
|
|
439
|
+
private
|
|
406
440
|
|
|
407
|
-
|
|
441
|
+
def bar: () -> void # private instance method
|
|
408
442
|
|
|
409
|
-
|
|
443
|
+
attr_reader email: String # private instance attribute
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
The visibility _modifiers_ overwrite the default visibility per member bases.
|
|
447
|
+
|
|
448
|
+
The visibility member requires a new line `\n` after the token.
|
|
449
|
+
|
|
450
|
+
```rbs
|
|
451
|
+
private alias foo bar # Syntax error
|
|
452
|
+
```
|
|
410
453
|
|
|
411
454
|
## Declarations
|
|
412
455
|
|
data/ext/rbs_extension/lexer.h
CHANGED
|
@@ -134,6 +134,12 @@ void skip(lexstate *state) {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
void skipn(lexstate *state, size_t size) {
|
|
138
|
+
for (size_t i = 0; i < size; i ++) {
|
|
139
|
+
skip(state);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
137
143
|
char *peek_token(lexstate *state, token tok) {
|
|
138
144
|
return RSTRING_PTR(state->string) + tok.range.start.byte_pos;
|
|
139
145
|
}
|
data/ext/rbs_extension/parser.c
CHANGED
|
@@ -1430,6 +1430,8 @@ InstanceSingletonKind parse_instance_singleton_kind(parserstate *state, bool all
|
|
|
1430
1430
|
|
|
1431
1431
|
/**
|
|
1432
1432
|
* def_member ::= {kDEF} method_name `:` <method_types>
|
|
1433
|
+
* | {kPRIVATE2} kDEF method_name `:` <method_types>
|
|
1434
|
+
* | {kPUBLIC2} kDEF method_name `:` <method_types>
|
|
1433
1435
|
*
|
|
1434
1436
|
* method_types ::= {} <method_type>
|
|
1435
1437
|
* | {} <`...`>
|
|
@@ -1440,30 +1442,61 @@ InstanceSingletonKind parse_instance_singleton_kind(parserstate *state, bool all
|
|
|
1440
1442
|
* */
|
|
1441
1443
|
VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overload, position comment_pos, VALUE annotations) {
|
|
1442
1444
|
range member_range;
|
|
1445
|
+
range visibility_range;
|
|
1443
1446
|
range keyword_range;
|
|
1444
1447
|
range name_range;
|
|
1445
1448
|
range kind_range;
|
|
1446
1449
|
range overload_range = NULL_RANGE;
|
|
1447
1450
|
|
|
1448
|
-
|
|
1449
|
-
member_range.start = keyword_range.start;
|
|
1451
|
+
VALUE visibility;
|
|
1450
1452
|
|
|
1451
|
-
|
|
1453
|
+
member_range.start = state->current_token.range.start;
|
|
1454
|
+
comment_pos = nonnull_pos_or(comment_pos, member_range.start);
|
|
1452
1455
|
VALUE comment = get_comment(state, comment_pos.line);
|
|
1453
1456
|
|
|
1457
|
+
switch (state->current_token.type)
|
|
1458
|
+
{
|
|
1459
|
+
case kPRIVATE:
|
|
1460
|
+
visibility_range = state->current_token.range;
|
|
1461
|
+
visibility = ID2SYM(rb_intern("private"));
|
|
1462
|
+
member_range.start = visibility_range.start;
|
|
1463
|
+
parser_advance(state);
|
|
1464
|
+
break;
|
|
1465
|
+
case kPUBLIC:
|
|
1466
|
+
visibility_range = state->current_token.range;
|
|
1467
|
+
visibility = ID2SYM(rb_intern("public"));
|
|
1468
|
+
member_range.start = visibility_range.start;
|
|
1469
|
+
parser_advance(state);
|
|
1470
|
+
break;
|
|
1471
|
+
default:
|
|
1472
|
+
visibility_range = NULL_RANGE;
|
|
1473
|
+
visibility = Qnil;
|
|
1474
|
+
break;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
keyword_range = state->current_token.range;
|
|
1478
|
+
|
|
1454
1479
|
InstanceSingletonKind kind;
|
|
1455
1480
|
if (instance_only) {
|
|
1456
1481
|
kind_range = NULL_RANGE;
|
|
1457
1482
|
kind = INSTANCE_KIND;
|
|
1458
1483
|
} else {
|
|
1459
|
-
kind = parse_instance_singleton_kind(state,
|
|
1484
|
+
kind = parse_instance_singleton_kind(state, NIL_P(visibility), &kind_range);
|
|
1460
1485
|
}
|
|
1461
1486
|
|
|
1462
1487
|
VALUE name = parse_method_name(state, &name_range);
|
|
1463
1488
|
VALUE method_types = rb_ary_new();
|
|
1464
1489
|
VALUE overload = Qfalse;
|
|
1465
1490
|
|
|
1466
|
-
|
|
1491
|
+
if (state->next_token.type == pDOT && RB_SYM2ID(name) == rb_intern("self?")) {
|
|
1492
|
+
raise_syntax_error(
|
|
1493
|
+
state,
|
|
1494
|
+
state->next_token,
|
|
1495
|
+
"`self?` method cannot have visibility"
|
|
1496
|
+
);
|
|
1497
|
+
} else {
|
|
1498
|
+
parser_advance_assert(state, pCOLON);
|
|
1499
|
+
}
|
|
1467
1500
|
|
|
1468
1501
|
parser_push_typevar_table(state, kind != INSTANCE_KIND);
|
|
1469
1502
|
|
|
@@ -1533,6 +1566,7 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
|
|
|
1533
1566
|
rbs_loc_add_required_child(loc, rb_intern("name"), name_range);
|
|
1534
1567
|
rbs_loc_add_optional_child(loc, rb_intern("kind"), kind_range);
|
|
1535
1568
|
rbs_loc_add_optional_child(loc, rb_intern("overload"), overload_range);
|
|
1569
|
+
rbs_loc_add_optional_child(loc, rb_intern("visibility"), visibility_range);
|
|
1536
1570
|
|
|
1537
1571
|
return rbs_ast_members_method_definition(
|
|
1538
1572
|
name,
|
|
@@ -1541,7 +1575,8 @@ VALUE parse_member_def(parserstate *state, bool instance_only, bool accept_overl
|
|
|
1541
1575
|
annotations,
|
|
1542
1576
|
location,
|
|
1543
1577
|
comment,
|
|
1544
|
-
overload
|
|
1578
|
+
overload,
|
|
1579
|
+
visibility
|
|
1545
1580
|
);
|
|
1546
1581
|
}
|
|
1547
1582
|
|
|
@@ -1839,10 +1874,14 @@ VALUE parse_visibility_member(parserstate *state, VALUE annotations) {
|
|
|
1839
1874
|
|
|
1840
1875
|
/*
|
|
1841
1876
|
attribute_member ::= {attr_keyword} attr_name attr_var `:` <type>
|
|
1877
|
+
| {visibility} attr_keyword attr_name attr_var `:` <type>
|
|
1842
1878
|
| {attr_keyword} `self` `.` attr_name attr_var `:` <type>
|
|
1879
|
+
| {visibility} attr_keyword `self` `.` attr_name attr_var `:` <type>
|
|
1843
1880
|
|
|
1844
1881
|
attr_keyword ::= `attr_reader` | `attr_writer` | `attr_accessor`
|
|
1845
1882
|
|
|
1883
|
+
visibility ::= `public` | `private`
|
|
1884
|
+
|
|
1846
1885
|
attr_var ::= # empty
|
|
1847
1886
|
| `(` tAIDENT `)` # Ivar name
|
|
1848
1887
|
| `(` `)` # No variable
|
|
@@ -1850,7 +1889,7 @@ VALUE parse_visibility_member(parserstate *state, VALUE annotations) {
|
|
|
1850
1889
|
VALUE parse_attribute_member(parserstate *state, position comment_pos, VALUE annotations) {
|
|
1851
1890
|
range member_range;
|
|
1852
1891
|
range keyword_range, name_range, colon_range;
|
|
1853
|
-
range kind_range = NULL_RANGE, ivar_range = NULL_RANGE, ivar_name_range = NULL_RANGE;
|
|
1892
|
+
range kind_range = NULL_RANGE, ivar_range = NULL_RANGE, ivar_name_range = NULL_RANGE, visibility_range = NULL_RANGE;
|
|
1854
1893
|
|
|
1855
1894
|
InstanceSingletonKind is_kind;
|
|
1856
1895
|
VALUE klass;
|
|
@@ -1860,12 +1899,31 @@ VALUE parse_attribute_member(parserstate *state, position comment_pos, VALUE ann
|
|
|
1860
1899
|
VALUE type;
|
|
1861
1900
|
VALUE comment;
|
|
1862
1901
|
VALUE location;
|
|
1902
|
+
VALUE visibility;
|
|
1863
1903
|
rbs_loc *loc;
|
|
1864
1904
|
|
|
1865
1905
|
member_range.start = state->current_token.range.start;
|
|
1866
1906
|
comment_pos = nonnull_pos_or(comment_pos, member_range.start);
|
|
1867
1907
|
comment = get_comment(state, comment_pos.line);
|
|
1868
1908
|
|
|
1909
|
+
switch (state->current_token.type)
|
|
1910
|
+
{
|
|
1911
|
+
case kPRIVATE:
|
|
1912
|
+
visibility = ID2SYM(rb_intern("private"));
|
|
1913
|
+
visibility_range = state->current_token.range;
|
|
1914
|
+
parser_advance(state);
|
|
1915
|
+
break;
|
|
1916
|
+
case kPUBLIC:
|
|
1917
|
+
visibility = ID2SYM(rb_intern("public"));
|
|
1918
|
+
visibility_range = state->current_token.range;
|
|
1919
|
+
parser_advance(state);
|
|
1920
|
+
break;
|
|
1921
|
+
default:
|
|
1922
|
+
visibility = Qnil;
|
|
1923
|
+
visibility_range = NULL_RANGE;
|
|
1924
|
+
break;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1869
1927
|
keyword_range = state->current_token.range;
|
|
1870
1928
|
switch (state->current_token.type)
|
|
1871
1929
|
{
|
|
@@ -1924,6 +1982,7 @@ VALUE parse_attribute_member(parserstate *state, position comment_pos, VALUE ann
|
|
|
1924
1982
|
rbs_loc_add_optional_child(loc, rb_intern("kind"), kind_range);
|
|
1925
1983
|
rbs_loc_add_optional_child(loc, rb_intern("ivar"), ivar_range);
|
|
1926
1984
|
rbs_loc_add_optional_child(loc, rb_intern("ivar_name"), ivar_name_range);
|
|
1985
|
+
rbs_loc_add_optional_child(loc, rb_intern("visibility"), visibility_range);
|
|
1927
1986
|
|
|
1928
1987
|
return rbs_ast_members_attribute(
|
|
1929
1988
|
klass,
|
|
@@ -1933,7 +1992,8 @@ VALUE parse_attribute_member(parserstate *state, position comment_pos, VALUE ann
|
|
|
1933
1992
|
kind,
|
|
1934
1993
|
annotations,
|
|
1935
1994
|
location,
|
|
1936
|
-
comment
|
|
1995
|
+
comment,
|
|
1996
|
+
visibility
|
|
1937
1997
|
);
|
|
1938
1998
|
}
|
|
1939
1999
|
|
|
@@ -2113,7 +2173,6 @@ VALUE parse_module_members(parserstate *state) {
|
|
|
2113
2173
|
member = parse_alias_member(state, false, annot_pos, annotations);
|
|
2114
2174
|
break;
|
|
2115
2175
|
|
|
2116
|
-
|
|
2117
2176
|
case tAIDENT:
|
|
2118
2177
|
case tA2IDENT:
|
|
2119
2178
|
case kSELF:
|
|
@@ -2128,7 +2187,23 @@ VALUE parse_module_members(parserstate *state) {
|
|
|
2128
2187
|
|
|
2129
2188
|
case kPUBLIC:
|
|
2130
2189
|
case kPRIVATE:
|
|
2131
|
-
|
|
2190
|
+
if (state->next_token.range.start.line == state->current_token.range.start.line) {
|
|
2191
|
+
switch (state->next_token.type)
|
|
2192
|
+
{
|
|
2193
|
+
case kDEF:
|
|
2194
|
+
member = parse_member_def(state, false, true, annot_pos, annotations);
|
|
2195
|
+
break;
|
|
2196
|
+
case kATTRREADER:
|
|
2197
|
+
case kATTRWRITER:
|
|
2198
|
+
case kATTRACCESSOR:
|
|
2199
|
+
member = parse_attribute_member(state, annot_pos, annotations);
|
|
2200
|
+
break;
|
|
2201
|
+
default:
|
|
2202
|
+
raise_syntax_error(state, state->next_token, "method or attribute definition is expected after visibility modifier");
|
|
2203
|
+
}
|
|
2204
|
+
} else {
|
|
2205
|
+
member = parse_visibility_member(state, annotations);
|
|
2206
|
+
}
|
|
2132
2207
|
break;
|
|
2133
2208
|
|
|
2134
2209
|
default:
|
|
@@ -400,7 +400,7 @@ VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE
|
|
|
400
400
|
);
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE types, VALUE annotations, VALUE location, VALUE comment, VALUE overload) {
|
|
403
|
+
VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE types, VALUE annotations, VALUE location, VALUE comment, VALUE overload, VALUE visibility) {
|
|
404
404
|
VALUE args = rb_hash_new();
|
|
405
405
|
rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
|
|
406
406
|
rb_hash_aset(args, ID2SYM(rb_intern("kind")), kind);
|
|
@@ -409,6 +409,7 @@ VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE types, VAL
|
|
|
409
409
|
rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
|
|
410
410
|
rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
|
|
411
411
|
rb_hash_aset(args, ID2SYM(rb_intern("overload")), overload);
|
|
412
|
+
rb_hash_aset(args, ID2SYM(rb_intern("visibility")), visibility);
|
|
412
413
|
|
|
413
414
|
return CLASS_NEW_INSTANCE(
|
|
414
415
|
RBS_AST_Members_MethodDefinition,
|
|
@@ -446,7 +447,7 @@ VALUE rbs_ast_members_mixin(VALUE klass, VALUE name, VALUE module_args, VALUE an
|
|
|
446
447
|
);
|
|
447
448
|
}
|
|
448
449
|
|
|
449
|
-
VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment) {
|
|
450
|
+
VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment, VALUE visibility) {
|
|
450
451
|
VALUE args = rb_hash_new();
|
|
451
452
|
rb_hash_aset(args, ID2SYM(rb_intern("name")), name);
|
|
452
453
|
rb_hash_aset(args, ID2SYM(rb_intern("type")), type);
|
|
@@ -455,6 +456,7 @@ VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_
|
|
|
455
456
|
rb_hash_aset(args, ID2SYM(rb_intern("annotations")), annotations);
|
|
456
457
|
rb_hash_aset(args, ID2SYM(rb_intern("location")), location);
|
|
457
458
|
rb_hash_aset(args, ID2SYM(rb_intern("comment")), comment);
|
|
459
|
+
rb_hash_aset(args, ID2SYM(rb_intern("visibility")), visibility);
|
|
458
460
|
|
|
459
461
|
return CLASS_NEW_INSTANCE(
|
|
460
462
|
klass,
|
|
@@ -16,8 +16,8 @@ VALUE rbs_ast_decl_interface(VALUE name, VALUE type_params, VALUE members, VALUE
|
|
|
16
16
|
VALUE rbs_ast_decl_module_self(VALUE name, VALUE args, VALUE location);
|
|
17
17
|
VALUE rbs_ast_decl_module(VALUE name, VALUE type_params, VALUE self_types, VALUE members, VALUE annotations, VALUE location, VALUE comment);
|
|
18
18
|
VALUE rbs_ast_members_alias(VALUE new_name, VALUE old_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment);
|
|
19
|
-
VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment);
|
|
20
|
-
VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE types, VALUE annotations, VALUE location, VALUE comment, VALUE overload);
|
|
19
|
+
VALUE rbs_ast_members_attribute(VALUE klass, VALUE name, VALUE type, VALUE ivar_name, VALUE kind, VALUE annotations, VALUE location, VALUE comment, VALUE visibility);
|
|
20
|
+
VALUE rbs_ast_members_method_definition(VALUE name, VALUE kind, VALUE types, VALUE annotations, VALUE location, VALUE comment, VALUE overload, VALUE visibility);
|
|
21
21
|
VALUE rbs_ast_members_mixin(VALUE klass, VALUE name, VALUE args, VALUE annotations, VALUE location, VALUE comment);
|
|
22
22
|
VALUE rbs_ast_members_variable(VALUE klass, VALUE name, VALUE type, VALUE location, VALUE comment);
|
|
23
23
|
VALUE rbs_ast_members_visibility(VALUE klass, VALUE location);
|
data/goodcheck.yml
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
rules:
|
|
2
|
-
- id: rbs.no_mark
|
|
3
|
-
pattern: 💪👽🚨
|
|
4
|
-
message: Do you forget to delete `arglists` section?
|
|
5
|
-
glob:
|
|
6
|
-
- "{core,stdlib}/**/*.rbs"
|
|
7
|
-
fail:
|
|
8
|
-
- |
|
|
9
|
-
# arglists 💪👽🚨 << Delete this section
|
|
10
|
-
# File.absolute_path?(file_name) -> true or false
|
|
11
|
-
#
|
|
12
|
-
|
|
13
2
|
- id: rbs.no_arg
|
|
14
3
|
pattern:
|
|
15
4
|
regexp: arg\d+
|