rbs 4.0.0.dev.5 → 4.0.1.dev.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 (194) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +1 -0
  3. data/.github/workflows/c-check.yml +8 -4
  4. data/.github/workflows/comments.yml +3 -1
  5. data/.github/workflows/dependabot.yml +1 -1
  6. data/.github/workflows/ruby.yml +10 -0
  7. data/.github/workflows/rust.yml +95 -0
  8. data/CHANGELOG.md +323 -0
  9. data/Rakefile +12 -29
  10. data/Steepfile +1 -0
  11. data/config.yml +393 -37
  12. data/core/array.rbs +218 -188
  13. data/core/basic_object.rbs +9 -8
  14. data/core/class.rbs +6 -5
  15. data/core/comparable.rbs +45 -31
  16. data/core/complex.rbs +52 -40
  17. data/core/dir.rbs +57 -45
  18. data/core/encoding.rbs +5 -5
  19. data/core/enumerable.rbs +96 -91
  20. data/core/enumerator.rbs +4 -3
  21. data/core/errno.rbs +3 -2
  22. data/core/errors.rbs +31 -29
  23. data/core/exception.rbs +12 -12
  24. data/core/fiber.rbs +36 -36
  25. data/core/file.rbs +186 -113
  26. data/core/file_test.rbs +2 -2
  27. data/core/float.rbs +41 -32
  28. data/core/gc.rbs +78 -70
  29. data/core/hash.rbs +70 -60
  30. data/core/integer.rbs +32 -28
  31. data/core/io/buffer.rbs +36 -36
  32. data/core/io/wait.rbs +7 -7
  33. data/core/io.rbs +120 -135
  34. data/core/kernel.rbs +189 -139
  35. data/core/marshal.rbs +3 -3
  36. data/core/match_data.rbs +14 -12
  37. data/core/math.rbs +69 -67
  38. data/core/method.rbs +6 -6
  39. data/core/module.rbs +146 -85
  40. data/core/nil_class.rbs +4 -3
  41. data/core/numeric.rbs +35 -32
  42. data/core/object.rbs +6 -8
  43. data/core/object_space.rbs +11 -10
  44. data/core/pathname.rbs +131 -81
  45. data/core/proc.rbs +65 -33
  46. data/core/process.rbs +219 -201
  47. data/core/ractor.rbs +15 -11
  48. data/core/random.rbs +4 -3
  49. data/core/range.rbs +52 -47
  50. data/core/rational.rbs +5 -5
  51. data/core/rbs/unnamed/argf.rbs +58 -51
  52. data/core/rbs/unnamed/env_class.rbs +18 -13
  53. data/core/rbs/unnamed/main_class.rbs +123 -0
  54. data/core/rbs/unnamed/random.rbs +7 -5
  55. data/core/regexp.rbs +236 -197
  56. data/core/ruby.rbs +1 -1
  57. data/core/ruby_vm.rbs +32 -30
  58. data/core/rubygems/config_file.rbs +5 -5
  59. data/core/rubygems/errors.rbs +1 -1
  60. data/core/rubygems/requirement.rbs +5 -5
  61. data/core/rubygems/rubygems.rbs +5 -3
  62. data/core/set.rbs +17 -16
  63. data/core/signal.rbs +2 -2
  64. data/core/string.rbs +311 -292
  65. data/core/struct.rbs +26 -25
  66. data/core/symbol.rbs +25 -24
  67. data/core/thread.rbs +40 -34
  68. data/core/time.rbs +47 -42
  69. data/core/trace_point.rbs +34 -31
  70. data/core/true_class.rbs +2 -2
  71. data/core/unbound_method.rbs +10 -10
  72. data/core/warning.rbs +7 -7
  73. data/docs/collection.md +1 -1
  74. data/docs/config.md +171 -0
  75. data/docs/inline.md +110 -4
  76. data/docs/syntax.md +13 -12
  77. data/ext/rbs_extension/ast_translation.c +489 -135
  78. data/ext/rbs_extension/class_constants.c +8 -0
  79. data/ext/rbs_extension/class_constants.h +4 -0
  80. data/ext/rbs_extension/legacy_location.c +28 -51
  81. data/ext/rbs_extension/legacy_location.h +37 -0
  82. data/ext/rbs_extension/main.c +12 -20
  83. data/include/rbs/ast.h +423 -195
  84. data/include/rbs/lexer.h +2 -2
  85. data/include/rbs/location.h +25 -44
  86. data/include/rbs/parser.h +2 -2
  87. data/include/rbs/util/rbs_constant_pool.h +0 -3
  88. data/include/rbs.h +8 -0
  89. data/lib/rbs/ast/ruby/annotations.rb +157 -4
  90. data/lib/rbs/ast/ruby/members.rb +374 -22
  91. data/lib/rbs/cli/validate.rb +5 -60
  92. data/lib/rbs/collection/config/lockfile_generator.rb +6 -2
  93. data/lib/rbs/definition_builder.rb +60 -27
  94. data/lib/rbs/errors.rb +0 -11
  95. data/lib/rbs/inline_parser.rb +1 -1
  96. data/lib/rbs/parser_aux.rb +20 -7
  97. data/lib/rbs/prototype/helpers.rb +57 -0
  98. data/lib/rbs/prototype/rb.rb +1 -26
  99. data/lib/rbs/prototype/rbi.rb +1 -20
  100. data/lib/rbs/test/type_check.rb +3 -0
  101. data/lib/rbs/types.rb +62 -52
  102. data/lib/rbs/unit_test/type_assertions.rb +35 -8
  103. data/lib/rbs/version.rb +1 -1
  104. data/lib/rbs.rb +0 -1
  105. data/rbs.gemspec +1 -1
  106. data/rust/.gitignore +1 -0
  107. data/rust/Cargo.lock +378 -0
  108. data/rust/Cargo.toml +7 -0
  109. data/rust/ruby-rbs/Cargo.toml +22 -0
  110. data/rust/ruby-rbs/build.rs +764 -0
  111. data/rust/ruby-rbs/examples/locations.rs +60 -0
  112. data/rust/ruby-rbs/src/lib.rs +1 -0
  113. data/rust/ruby-rbs/src/node/mod.rs +742 -0
  114. data/rust/ruby-rbs/tests/sanity.rs +47 -0
  115. data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
  116. data/rust/ruby-rbs-sys/Cargo.toml +23 -0
  117. data/rust/ruby-rbs-sys/build.rs +204 -0
  118. data/rust/ruby-rbs-sys/src/lib.rs +50 -0
  119. data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
  120. data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
  121. data/rust/ruby-rbs-sys/wrapper.h +1 -0
  122. data/sig/ast/ruby/annotations.rbs +191 -4
  123. data/sig/ast/ruby/members.rbs +21 -1
  124. data/sig/cli/validate.rbs +1 -6
  125. data/sig/definition_builder.rbs +2 -0
  126. data/sig/errors.rbs +0 -8
  127. data/sig/method_types.rbs +1 -1
  128. data/sig/parser.rbs +17 -13
  129. data/sig/prototype/helpers.rbs +2 -0
  130. data/sig/types.rbs +10 -11
  131. data/sig/unit_test/spy.rbs +0 -8
  132. data/sig/unit_test/type_assertions.rbs +11 -0
  133. data/src/ast.c +339 -161
  134. data/src/lexstate.c +1 -1
  135. data/src/location.c +7 -47
  136. data/src/parser.c +674 -480
  137. data/src/util/rbs_constant_pool.c +0 -4
  138. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
  139. data/stdlib/cgi-escape/0/escape.rbs +4 -4
  140. data/stdlib/coverage/0/coverage.rbs +4 -3
  141. data/stdlib/date/0/date.rbs +33 -28
  142. data/stdlib/date/0/date_time.rbs +24 -23
  143. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  144. data/stdlib/erb/0/erb.rbs +64 -53
  145. data/stdlib/etc/0/etc.rbs +55 -50
  146. data/stdlib/fileutils/0/fileutils.rbs +138 -125
  147. data/stdlib/forwardable/0/forwardable.rbs +10 -10
  148. data/stdlib/io-console/0/io-console.rbs +2 -2
  149. data/stdlib/json/0/json.rbs +135 -108
  150. data/stdlib/monitor/0/monitor.rbs +3 -3
  151. data/stdlib/net-http/0/net-http.rbs +159 -134
  152. data/stdlib/objspace/0/objspace.rbs +8 -7
  153. data/stdlib/open-uri/0/open-uri.rbs +8 -8
  154. data/stdlib/open3/0/open3.rbs +36 -35
  155. data/stdlib/openssl/0/openssl.rbs +144 -129
  156. data/stdlib/optparse/0/optparse.rbs +18 -14
  157. data/stdlib/pathname/0/pathname.rbs +2 -2
  158. data/stdlib/pp/0/pp.rbs +9 -8
  159. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  160. data/stdlib/pstore/0/pstore.rbs +35 -30
  161. data/stdlib/psych/0/psych.rbs +61 -8
  162. data/stdlib/psych/0/store.rbs +2 -4
  163. data/stdlib/pty/0/pty.rbs +9 -6
  164. data/stdlib/random-formatter/0/random-formatter.rbs +2 -2
  165. data/stdlib/ripper/0/ripper.rbs +20 -17
  166. data/stdlib/securerandom/0/securerandom.rbs +1 -1
  167. data/stdlib/shellwords/0/shellwords.rbs +2 -2
  168. data/stdlib/socket/0/addrinfo.rbs +7 -7
  169. data/stdlib/socket/0/basic_socket.rbs +3 -3
  170. data/stdlib/socket/0/ip_socket.rbs +10 -8
  171. data/stdlib/socket/0/socket.rbs +10 -9
  172. data/stdlib/socket/0/tcp_server.rbs +1 -1
  173. data/stdlib/socket/0/tcp_socket.rbs +1 -1
  174. data/stdlib/socket/0/udp_socket.rbs +1 -1
  175. data/stdlib/socket/0/unix_server.rbs +1 -1
  176. data/stdlib/stringio/0/stringio.rbs +55 -54
  177. data/stdlib/strscan/0/string_scanner.rbs +46 -44
  178. data/stdlib/tempfile/0/tempfile.rbs +24 -20
  179. data/stdlib/time/0/time.rbs +7 -5
  180. data/stdlib/tsort/0/tsort.rbs +7 -6
  181. data/stdlib/uri/0/common.rbs +26 -18
  182. data/stdlib/uri/0/file.rbs +2 -2
  183. data/stdlib/uri/0/generic.rbs +2 -2
  184. data/stdlib/uri/0/http.rbs +2 -2
  185. data/stdlib/uri/0/ldap.rbs +2 -2
  186. data/stdlib/uri/0/mailto.rbs +3 -3
  187. data/stdlib/uri/0/rfc2396_parser.rbs +6 -5
  188. data/stdlib/zlib/0/deflate.rbs +4 -3
  189. data/stdlib/zlib/0/gzip_reader.rbs +4 -4
  190. data/stdlib/zlib/0/gzip_writer.rbs +14 -12
  191. data/stdlib/zlib/0/inflate.rbs +1 -1
  192. data/stdlib/zlib/0/need_dict.rbs +1 -1
  193. metadata +23 -5
  194. data/.github/workflows/valgrind.yml +0 -42
@@ -0,0 +1,47 @@
1
+ use std::path::Path;
2
+
3
+ use ruby_rbs::node::parse;
4
+
5
+ fn collect_rbs_files(dir: &Path) -> Vec<std::path::PathBuf> {
6
+ let mut files = Vec::new();
7
+
8
+ for entry in std::fs::read_dir(dir).unwrap() {
9
+ let entry = entry.unwrap();
10
+ let path = entry.path();
11
+
12
+ if path.is_dir() {
13
+ files.extend(collect_rbs_files(&path));
14
+ } else if path.extension().is_some_and(|ext| ext == "rbs") {
15
+ files.push(path);
16
+ }
17
+ }
18
+
19
+ files
20
+ }
21
+
22
+ #[test]
23
+ fn all_included_rbs_can_be_parsed() {
24
+ let repo_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
25
+ let dirs = [repo_root.join("core"), repo_root.join("stdlib")];
26
+
27
+ let mut files: Vec<_> = dirs.iter().flat_map(|d| collect_rbs_files(d)).collect();
28
+ files.sort();
29
+ assert!(!files.is_empty());
30
+
31
+ let mut failures = Vec::new();
32
+
33
+ for file in &files {
34
+ let content = std::fs::read_to_string(file).unwrap();
35
+
36
+ if let Err(e) = parse(content.as_bytes()) {
37
+ failures.push(format!("{}: {}", file.display(), e));
38
+ }
39
+ }
40
+
41
+ assert!(
42
+ failures.is_empty(),
43
+ "Failed to parse {} RBS file(s):\n{}",
44
+ failures.len(),
45
+ failures.join("\n")
46
+ );
47
+ }
@@ -0,0 +1 @@
1
+ ../../../../config.yml
@@ -0,0 +1,23 @@
1
+ [package]
2
+ name = "ruby-rbs-sys"
3
+ version = "0.2.0"
4
+ edition = "2024"
5
+ license = "BSD-2-Clause"
6
+ description = "Low-level FFI bindings for RBS -- the type signature language for Ruby programs"
7
+ homepage = "https://github.com/ruby/rbs"
8
+ repository = "https://github.com/ruby/rbs.git"
9
+ readme = "../../README.md"
10
+ include = [
11
+ "src/**/*",
12
+ "vendor/**/*",
13
+ "build.rs",
14
+ "wrapper.h",
15
+ "Cargo.toml",
16
+ ]
17
+
18
+ [lib]
19
+ doctest = false
20
+
21
+ [build-dependencies]
22
+ bindgen = "0.72.0"
23
+ cc = "1.2.29"
@@ -0,0 +1,204 @@
1
+ use std::{
2
+ env,
3
+ error::Error,
4
+ fs,
5
+ path::{Path, PathBuf},
6
+ };
7
+
8
+ fn main() -> Result<(), Box<dyn Error>> {
9
+ let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
10
+ let vendor_rbs = manifest_dir.join("vendor/rbs");
11
+ let include = vendor_rbs.join("include");
12
+ let c_src = vendor_rbs.join("src");
13
+
14
+ build(&include, &c_src)?;
15
+
16
+ let bindings = generate_bindings(&include)?;
17
+ write_bindings(&bindings)?;
18
+
19
+ Ok(())
20
+ }
21
+
22
+ fn build(include_dir: &Path, src_dir: &Path) -> Result<(), Box<dyn Error>> {
23
+ let mut build = cc::Build::new();
24
+
25
+ build.include(include_dir);
26
+
27
+ // Suppress unused parameter warnings from C code
28
+ build.flag_if_supported("-Wno-unused-parameter");
29
+
30
+ build.files(source_files(src_dir)?);
31
+ build.try_compile("rbs")?;
32
+
33
+ Ok(())
34
+ }
35
+
36
+ fn source_files<P: AsRef<Path>>(root_dir: P) -> Result<Vec<String>, Box<dyn Error>> {
37
+ let mut files = Vec::new();
38
+
39
+ for entry in fs::read_dir(root_dir.as_ref()).map_err(|e| {
40
+ format!(
41
+ "Failed to read source directory {:?}: {e}",
42
+ root_dir.as_ref()
43
+ )
44
+ })? {
45
+ let entry = entry.map_err(|e| format!("Failed to read directory entry: {e}"))?;
46
+ let path = entry.path();
47
+
48
+ if path.is_file() {
49
+ let path_str = path
50
+ .to_str()
51
+ .ok_or_else(|| format!("Invalid UTF-8 in filename: {path:?}"))?;
52
+
53
+ if Path::new(path_str)
54
+ .extension()
55
+ .is_some_and(|ext| ext.eq_ignore_ascii_case("c"))
56
+ {
57
+ files.push(path_str.to_string());
58
+ }
59
+ } else if path.is_dir() {
60
+ files.extend(source_files(path)?);
61
+ }
62
+ }
63
+
64
+ Ok(files)
65
+ }
66
+
67
+ fn generate_bindings(include_path: &Path) -> Result<bindgen::Bindings, Box<dyn Error>> {
68
+ let bindings = bindgen::Builder::default()
69
+ .header("wrapper.h")
70
+ .clang_arg(format!("-I{}", include_path.display()))
71
+ .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
72
+ .generate_comments(true)
73
+ // Core types
74
+ .allowlist_type("rbs_ast_annotation_t")
75
+ .allowlist_type("rbs_ast_bool_t")
76
+ .allowlist_type("rbs_ast_comment_t")
77
+ .allowlist_type("rbs_ast_declarations_class_alias_t")
78
+ .allowlist_type("rbs_ast_declarations_class_super_t")
79
+ .allowlist_type("rbs_ast_declarations_class_t")
80
+ .allowlist_type("rbs_ast_declarations_constant_t")
81
+ .allowlist_type("rbs_ast_declarations_global_t")
82
+ .allowlist_type("rbs_ast_declarations_interface_t")
83
+ .allowlist_type("rbs_ast_declarations_module_alias_t")
84
+ .allowlist_type("rbs_ast_declarations_module_self_t")
85
+ .allowlist_type("rbs_ast_declarations_module_t")
86
+ .allowlist_type("rbs_ast_declarations_type_alias_t")
87
+ .allowlist_type("rbs_ast_directives_use_single_clause_t")
88
+ .allowlist_type("rbs_ast_directives_use_t")
89
+ .allowlist_type("rbs_ast_directives_use_wildcard_clause_t")
90
+ .allowlist_type("rbs_ast_integer_t")
91
+ .allowlist_type("rbs_attr_ivar_name_t")
92
+ .allowlist_type("rbs_ast_members_alias_t")
93
+ .allowlist_type("rbs_ast_members_attr_accessor_t")
94
+ .allowlist_type("rbs_ast_members_attr_reader_t")
95
+ .allowlist_type("rbs_ast_members_attr_writer_t")
96
+ .allowlist_type("rbs_ast_members_class_instance_variable_t")
97
+ .allowlist_type("rbs_ast_members_class_variable_t")
98
+ .allowlist_type("rbs_ast_members_extend_t")
99
+ .allowlist_type("rbs_ast_members_include_t")
100
+ .allowlist_type("rbs_ast_members_instance_variable_t")
101
+ .allowlist_type("rbs_ast_members_method_definition_overload_t")
102
+ .allowlist_type("rbs_ast_members_method_definition_t")
103
+ .allowlist_type("rbs_ast_members_prepend_t")
104
+ .allowlist_type("rbs_ast_members_private_t")
105
+ .allowlist_type("rbs_ast_members_public_t")
106
+ .allowlist_type("rbs_ast_ruby_annotations_class_alias_annotation_t")
107
+ .allowlist_type("rbs_ast_ruby_annotations_colon_method_type_annotation_t")
108
+ .allowlist_type("rbs_ast_ruby_annotations_instance_variable_annotation_t")
109
+ .allowlist_type("rbs_ast_ruby_annotations_method_types_annotation_t")
110
+ .allowlist_type("rbs_ast_ruby_annotations_module_alias_annotation_t")
111
+ .allowlist_type("rbs_ast_ruby_annotations_node_type_assertion_t")
112
+ .allowlist_type("rbs_ast_ruby_annotations_return_type_annotation_t")
113
+ .allowlist_type("rbs_ast_ruby_annotations_skip_annotation_t")
114
+ .allowlist_type("rbs_ast_ruby_annotations_type_application_annotation_t")
115
+ .allowlist_type("rbs_ast_ruby_annotations_block_param_type_annotation_t")
116
+ .allowlist_type("rbs_ast_ruby_annotations_param_type_annotation_t")
117
+ .allowlist_type("rbs_ast_ruby_annotations_splat_param_type_annotation_t")
118
+ .allowlist_type("rbs_ast_ruby_annotations_double_splat_param_type_annotation_t")
119
+ .allowlist_type("rbs_ast_string_t")
120
+ .allowlist_type("rbs_ast_symbol_t")
121
+ .allowlist_type("rbs_ast_type_param_t")
122
+ .allowlist_type("rbs_encoding_t")
123
+ .allowlist_type("rbs_encoding_type_t")
124
+ .allowlist_type("rbs_location_range")
125
+ .allowlist_type("rbs_location_range_list_t")
126
+ .allowlist_type("rbs_location_range_list_node_t")
127
+ .allowlist_type("rbs_method_type_t")
128
+ .allowlist_type("rbs_namespace_t")
129
+ .allowlist_type("rbs_node_list_t")
130
+ .allowlist_type("rbs_signature_t")
131
+ .allowlist_type("rbs_string_t")
132
+ .allowlist_type("rbs_type_name_t")
133
+ .allowlist_type("rbs_types_alias_t")
134
+ .allowlist_type("rbs_types_bases_any_t")
135
+ .allowlist_type("rbs_types_bases_bool_t")
136
+ .allowlist_type("rbs_types_bases_bottom_t")
137
+ .allowlist_type("rbs_types_bases_class_t")
138
+ .allowlist_type("rbs_types_bases_instance_t")
139
+ .allowlist_type("rbs_types_bases_nil_t")
140
+ .allowlist_type("rbs_types_bases_self_t")
141
+ .allowlist_type("rbs_types_bases_top_t")
142
+ .allowlist_type("rbs_types_bases_void_t")
143
+ .allowlist_type("rbs_types_block_t")
144
+ .allowlist_type("rbs_types_class_instance_t")
145
+ .allowlist_type("rbs_types_class_singleton_t")
146
+ .allowlist_type("rbs_types_function_param_t")
147
+ .allowlist_type("rbs_types_function_t")
148
+ .allowlist_type("rbs_types_interface_t")
149
+ .allowlist_type("rbs_types_intersection_t")
150
+ .allowlist_type("rbs_types_literal_t")
151
+ .allowlist_type("rbs_types_optional_t")
152
+ .allowlist_type("rbs_types_proc_t")
153
+ .allowlist_type("rbs_types_record_field_type_t")
154
+ .allowlist_type("rbs_types_record_t")
155
+ .allowlist_type("rbs_types_tuple_t")
156
+ .allowlist_type("rbs_types_union_t")
157
+ .allowlist_type("rbs_types_untyped_function_t")
158
+ .allowlist_type("rbs_types_variable_t")
159
+ .constified_enum_module("rbs_alias_kind")
160
+ .constified_enum_module("rbs_attribute_kind")
161
+ .constified_enum_module("rbs_attribute_visibility")
162
+ .constified_enum_module("rbs_encoding_type_t")
163
+ .constified_enum_module("rbs_attr_ivar_name_tag")
164
+ .constified_enum_module("rbs_method_definition_kind")
165
+ .constified_enum_module("rbs_method_definition_visibility")
166
+ .constified_enum_module("rbs_node_type")
167
+ .constified_enum_module("rbs_type_param_variance")
168
+ // Encodings
169
+ .allowlist_var("rbs_encodings")
170
+ // Parser functions
171
+ .allowlist_function("rbs_parse_signature")
172
+ .allowlist_function("rbs_parser_free")
173
+ .allowlist_function("rbs_parser_new")
174
+ // String functions
175
+ .allowlist_function("rbs_string_new")
176
+ // Location functions
177
+ .allowlist_function("rbs_location_range_list_new")
178
+ .allowlist_function("rbs_location_range_list_append")
179
+ // Constant pool functions
180
+ .allowlist_function("rbs_constant_pool_free")
181
+ .allowlist_function("rbs_constant_pool_id_to_constant")
182
+ .allowlist_function("rbs_constant_pool_init")
183
+ .generate()
184
+ .map_err(|_| "Unable to generate rbs bindings")?;
185
+
186
+ Ok(bindings)
187
+ }
188
+
189
+ fn write_bindings(bindings: &bindgen::Bindings) -> Result<(), Box<dyn Error>> {
190
+ let out_path = PathBuf::from(
191
+ env::var("OUT_DIR").map_err(|e| format!("OUT_DIR environment variable not set: {e}"))?,
192
+ );
193
+
194
+ bindings
195
+ .write_to_file(out_path.join("bindings.rs"))
196
+ .map_err(|e| {
197
+ format!(
198
+ "Failed to write bindings to {:?}: {e}",
199
+ out_path.join("bindings.rs")
200
+ )
201
+ })?;
202
+
203
+ Ok(())
204
+ }
@@ -0,0 +1,50 @@
1
+ #![allow(
2
+ clippy::useless_transmute,
3
+ clippy::missing_safety_doc,
4
+ clippy::ptr_offset_with_cast,
5
+ dead_code,
6
+ non_camel_case_types,
7
+ non_upper_case_globals,
8
+ non_snake_case
9
+ )]
10
+ pub mod bindings {
11
+ include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
12
+ }
13
+
14
+ #[cfg(test)]
15
+ mod tests {
16
+ use super::bindings::*;
17
+
18
+ use rbs_encoding_type_t::RBS_ENCODING_UTF_8;
19
+
20
+ #[test]
21
+ fn test_rbs_parser_bindings() {
22
+ let rbs_code = r#"
23
+ class User
24
+ attr_reader name: String
25
+ def initialize: (String) -> void
26
+ end
27
+
28
+ module Authentication
29
+ def authenticate: (String, String) -> bool
30
+ end
31
+ "#;
32
+
33
+ let bytes = rbs_code.as_bytes();
34
+ let start_ptr = bytes.as_ptr() as *const std::os::raw::c_char;
35
+ let end_ptr = unsafe { start_ptr.add(bytes.len()) } as *const std::os::raw::c_char;
36
+
37
+ let rbs_string = unsafe { rbs_string_new(start_ptr, end_ptr) };
38
+ let encoding_ptr =
39
+ unsafe { &rbs_encodings[RBS_ENCODING_UTF_8 as usize] as *const rbs_encoding_t };
40
+ let parser = unsafe { rbs_parser_new(rbs_string, encoding_ptr, 0, bytes.len() as i32) };
41
+
42
+ let mut signature: *mut rbs_signature_t = std::ptr::null_mut();
43
+ let result = unsafe { rbs_parse_signature(parser, &mut signature) };
44
+
45
+ assert!(result, "Failed to parse RBS signature");
46
+ assert!(!signature.is_null(), "Signature should not be null");
47
+
48
+ unsafe { rbs_parser_free(parser) };
49
+ }
50
+ }
@@ -0,0 +1 @@
1
+ ../../../../include
@@ -0,0 +1 @@
1
+ ../../../../src
@@ -0,0 +1 @@
1
+ #include "rbs.h"
@@ -7,6 +7,10 @@ module RBS
7
7
  | SkipAnnotation
8
8
  | ReturnTypeAnnotation
9
9
  | InstanceVariableAnnotation
10
+ | ParamTypeAnnotation
11
+ | SplatParamTypeAnnotation
12
+ | DoubleSplatParamTypeAnnotation
13
+ | BlockParamTypeAnnotation
10
14
 
11
15
  type trailing_annotation = NodeTypeAssertion
12
16
  | TypeApplicationAnnotation
@@ -104,9 +108,11 @@ module RBS
104
108
  # `@rbs METHOD-TYPEs` annotation in leading comments
105
109
  #
106
110
  # ```
107
- # @rbs () -> void | %a{foo} () -> String
108
- # ^^^^ -- prefix_location
109
- # ^ -- vertical_bar_locations[0]
111
+ # @rbs () -> void | %a{foo} () -> String | ...
112
+ # ^^^^ -- prefix_location
113
+ # ^ -- vertical_bar_locations[0]
114
+ # ^ -- vertical_bar_locations[1]
115
+ # ^^^ -- dot3_location
110
116
  # ```
111
117
  class MethodTypesAnnotation < Base
112
118
  class Overload = AST::Members::MethodDefinition::Overload
@@ -115,7 +121,9 @@ module RBS
115
121
 
116
122
  attr_reader vertical_bar_locations: Array[Location]
117
123
 
118
- def initialize: (location: Location, prefix_location: Location, overloads: Array[Overload], vertical_bar_locations: Array[Location]) -> void
124
+ attr_reader dot3_location: Location?
125
+
126
+ def initialize: (location: Location, prefix_location: Location, overloads: Array[Overload], vertical_bar_locations: Array[Location], dot3_location: Location?) -> void
119
127
 
120
128
  def map_type_name: () { (TypeName) -> TypeName } -> self
121
129
 
@@ -228,6 +236,185 @@ module RBS
228
236
 
229
237
  def type_fingerprint: () -> untyped
230
238
  end
239
+
240
+ class ParamTypeAnnotation < Base
241
+ attr_reader name_location: Location
242
+
243
+ attr_reader colon_location: Location
244
+
245
+ attr_reader param_type: Types::t
246
+
247
+ attr_reader comment_location: Location?
248
+
249
+ def initialize: (
250
+ location: Location,
251
+ prefix_location: Location,
252
+ name_location: Location,
253
+ colon_location: Location,
254
+ param_type: Types::t,
255
+ comment_location: Location?,
256
+ ) -> void
257
+
258
+ def map_type_name: () { (TypeName) -> TypeName } -> self
259
+
260
+ def type_fingerprint: () -> untyped
261
+
262
+ %a{pure}
263
+ def name: () -> Symbol
264
+ end
265
+
266
+ # `@rbs *name: Type -- comment` annotation in leading comments
267
+ #
268
+ # ```
269
+ # @rbs *a: String -- comment
270
+ # ^^^^ -- prefix_location
271
+ # ^ -- star_location
272
+ # ^ -- name_location
273
+ # ^ -- colon_location
274
+ # ^^^^^^^^^^ -- comment_location
275
+ # ```
276
+ #
277
+ # ```
278
+ # @rbs *: String
279
+ # ^^^^ -- prefix_location
280
+ # ^ -- star_location
281
+ # ^ -- colon_location
282
+ # ```
283
+ #
284
+ class SplatParamTypeAnnotation < Base
285
+ attr_reader star_location: Location
286
+
287
+ attr_reader name_location: Location?
288
+
289
+ attr_reader colon_location: Location
290
+
291
+ attr_reader param_type: Types::t
292
+
293
+ attr_reader comment_location: Location?
294
+
295
+ def initialize: (
296
+ location: Location,
297
+ prefix_location: Location,
298
+ star_location: Location,
299
+ name_location: Location?,
300
+ colon_location: Location,
301
+ param_type: Types::t,
302
+ comment_location: Location?,
303
+ ) -> void
304
+
305
+ def map_type_name: () { (TypeName) -> TypeName } -> self
306
+
307
+ def type_fingerprint: () -> untyped
308
+
309
+ %a{pure}
310
+ def name: () -> Symbol?
311
+ end
312
+
313
+ # `@rbs **name: Type -- comment` annotation in leading comments
314
+ #
315
+ # ```
316
+ # @rbs **b: bool -- comment
317
+ # ^^^^ -- prefix_location
318
+ # ^^ -- star2_location
319
+ # ^ -- name_location
320
+ # ^ -- colon_location
321
+ # ^^^^^^^^^^ -- comment_location
322
+ # ```
323
+ #
324
+ # ```
325
+ # @rbs **: bool
326
+ # ^^^^ -- prefix_location
327
+ # ^^ -- star2_location
328
+ # ^ -- colon_location
329
+ # ```
330
+ #
331
+ class DoubleSplatParamTypeAnnotation < Base
332
+ attr_reader star2_location: Location
333
+
334
+ attr_reader name_location: Location?
335
+
336
+ attr_reader colon_location: Location
337
+
338
+ attr_reader param_type: Types::t
339
+
340
+ attr_reader comment_location: Location?
341
+
342
+ def initialize: (
343
+ location: Location,
344
+ prefix_location: Location,
345
+ star2_location: Location,
346
+ name_location: Location?,
347
+ colon_location: Location,
348
+ param_type: Types::t,
349
+ comment_location: Location?,
350
+ ) -> void
351
+
352
+ def map_type_name: () { (TypeName) -> TypeName } -> self
353
+
354
+ def type_fingerprint: () -> untyped
355
+
356
+ %a{pure}
357
+ def name: () -> Symbol?
358
+ end
359
+
360
+ # `@rbs &name: TYPE -- comment` annotation in leading comments
361
+ #
362
+ # ```
363
+ # @rbs &block: () -> void -- comment
364
+ # ^^^^ -- prefix_location
365
+ # ^ -- ampersand_location
366
+ # ^^^^^ -- name_location
367
+ # ^ -- colon_location
368
+ # ^^^^^^^^^^ -- type_location
369
+ # ^^^^^^^^^^ -- comment_location
370
+ # ```
371
+ #
372
+ # ```
373
+ # @rbs &: ? () -> void
374
+ # ^^^^ -- prefix_location
375
+ # ^ -- ampersand_location
376
+ # ^ -- colon_location
377
+ # ^ -- question_location
378
+ # ^^^^^^^^^^ -- type_location
379
+ # ```
380
+ #
381
+ class BlockParamTypeAnnotation < Base
382
+ attr_reader ampersand_location: Location
383
+
384
+ attr_reader name_location: Location?
385
+
386
+ attr_reader colon_location: Location
387
+
388
+ attr_reader type_location: Location
389
+
390
+ attr_reader type: Types::function
391
+
392
+ attr_reader question_location: Location?
393
+
394
+ attr_reader comment_location: Location?
395
+
396
+ def initialize: (
397
+ location: Location,
398
+ prefix_location: Location,
399
+ ampersand_location: Location,
400
+ name_location: Location?,
401
+ colon_location: Location,
402
+ question_location: Location?,
403
+ type_location: Location,
404
+ type: Types::function,
405
+ comment_location: Location?,
406
+ ) -> void
407
+
408
+ def map_type_name: () { (TypeName) -> TypeName } -> self
409
+
410
+ def type_fingerprint: () -> untyped
411
+
412
+ %a{pure} def name: () -> Symbol?
413
+
414
+ def optional?: () -> bool
415
+
416
+ def required?: () -> bool
417
+ end
231
418
  end
232
419
  end
233
420
  end
@@ -19,10 +19,28 @@ module RBS
19
19
 
20
20
  class MethodTypeAnnotation
21
21
  class DocStyle
22
+ type param_type_annotation = Annotations::ParamTypeAnnotation
23
+ | Annotations::SplatParamTypeAnnotation
24
+ | Annotations::DoubleSplatParamTypeAnnotation
25
+ | Annotations::BlockParamTypeAnnotation
26
+
22
27
  attr_accessor return_type_annotation: Annotations::ReturnTypeAnnotation | Annotations::NodeTypeAssertion | nil
23
28
 
29
+ attr_reader required_positionals: Array[Annotations::ParamTypeAnnotation | Symbol]
30
+ attr_reader optional_positionals: Array[Annotations::ParamTypeAnnotation | Symbol]
31
+ attr_accessor rest_positionals: Annotations::SplatParamTypeAnnotation | Symbol | true | nil
32
+ attr_reader trailing_positionals: Array[Annotations::ParamTypeAnnotation | Symbol]
33
+ attr_reader required_keywords: Hash[Symbol, Annotations::ParamTypeAnnotation | Symbol]
34
+ attr_reader optional_keywords: Hash[Symbol, Annotations::ParamTypeAnnotation | Symbol]
35
+ attr_accessor rest_keywords: Annotations::DoubleSplatParamTypeAnnotation | Symbol | true | nil
36
+ attr_accessor block: Annotations::BlockParamTypeAnnotation | Symbol | true | nil
37
+
24
38
  def initialize: () -> void
25
39
 
40
+ def self.build: (Array[param_type_annotation], Annotations::ReturnTypeAnnotation | Annotations::NodeTypeAssertion | nil, Prism::DefNode) -> [DocStyle, Array[param_type_annotation]]
41
+
42
+ def all_param_annotations: () -> Array[param_type_annotation | Symbol | true | nil]
43
+
26
44
  def map_type_name: () { (TypeName) -> TypeName } -> self
27
45
 
28
46
  def method_type: () -> MethodType
@@ -42,7 +60,7 @@ module RBS
42
60
  #
43
61
  # Returns a tuple of `DefAnnotations` object, array of unused leading annotations, and unused trailing annotation.
44
62
  #
45
- def self.build: (CommentBlock? leading_block, CommentBlock? trailing_block, Array[Symbol]) -> [
63
+ def self.build: (CommentBlock? leading_block, CommentBlock? trailing_block, Array[Symbol], Prism::DefNode) -> [
46
64
  MethodTypeAnnotation,
47
65
  Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError],
48
66
  Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil
@@ -55,6 +73,8 @@ module RBS
55
73
  #
56
74
  def overloads: () -> Array[AST::Members::MethodDefinition::Overload]
57
75
 
76
+ def overloading?: () -> bool
77
+
58
78
  def type_fingerprint: () -> untyped
59
79
  end
60
80
 
data/sig/cli/validate.rbs CHANGED
@@ -3,14 +3,12 @@ module RBS
3
3
  class Validate
4
4
  class Errors
5
5
  @limit: Integer?
6
- @exit_error: boolish
7
- @has_syntax_error: bool
8
6
  @errors: Array[BaseError]
9
7
 
10
8
  # The tag that will be thrown in #finish method
11
9
  @tag: top
12
10
 
13
- def initialize: (limit: Integer?, exit_error: boolish) -> void
11
+ def initialize: (limit: Integer?) -> void
14
12
 
15
13
  def add: (BaseError) -> void
16
14
 
@@ -44,9 +42,6 @@ module RBS
44
42
  def validate_constant: () -> void
45
43
  def validate_global: () -> void
46
44
  def validate_type_alias: () -> void
47
- def no_classish_type_validator: (::RBS::Types::t | ::RBS::MethodType type) -> void
48
- def no_self_type_validator: (::RBS::Types::t | ::RBS::MethodType type) -> void
49
- %a{deprecated} def void_type_context_validator: (::RBS::Types::t | ::RBS::MethodType type, ?bool allowed_here) -> void
50
45
  end
51
46
  end
52
47
  end
@@ -97,6 +97,8 @@ module RBS
97
97
  #
98
98
  def interface_methods: (Array[Definition::Ancestor::Instance] interface_ancestors) -> interface_methods
99
99
 
100
+ def special_accessibility: (bool, Symbol) -> Definition::accessibility?
101
+
100
102
  def try_cache: (TypeName, cache: Hash[TypeName, Definition | false | nil]) { () -> Definition } -> Definition
101
103
 
102
104
  def validate_params_with: (Array[AST::TypeParam], result: VarianceCalculator::Result) { (AST::TypeParam) -> void } -> void
data/sig/errors.rbs CHANGED
@@ -394,14 +394,6 @@ module RBS
394
394
  def location: () -> AST::Declarations::AliasDecl::loc?
395
395
  end
396
396
 
397
- class WillSyntaxError < BaseError
398
- include RBS::DetailedMessageable
399
-
400
- def initialize: (String message, location: Location[untyped, untyped]?) -> void
401
-
402
- attr_reader location: Location[untyped, untyped]?
403
- end
404
-
405
397
  class TypeParamDefaultReferenceError < BaseError
406
398
  include DetailedMessageable
407
399
 
data/sig/method_types.rbs CHANGED
@@ -53,6 +53,6 @@ module RBS
53
53
 
54
54
  def has_classish_type?: () -> bool
55
55
 
56
- %a{deprecated} def with_nonreturn_void?: () -> bool
56
+ def with_nonreturn_void?: () -> bool
57
57
  end
58
58
  end