rbs 4.0.0.dev.4 → 4.0.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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +18 -11
- data/.github/workflows/comments.yml +5 -3
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/ruby.yml +27 -34
- data/.github/workflows/rust.yml +95 -0
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +323 -0
- data/README.md +1 -1
- data/Rakefile +43 -33
- data/Steepfile +1 -0
- data/config.yml +426 -24
- data/core/array.rbs +307 -227
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +55 -34
- data/core/complex.rbs +104 -78
- data/core/dir.rbs +61 -49
- data/core/encoding.rbs +12 -15
- data/core/enumerable.rbs +179 -87
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +65 -2
- data/core/errno.rbs +11 -2
- data/core/errors.rbs +58 -29
- data/core/exception.rbs +13 -13
- data/core/fiber.rbs +74 -54
- data/core/file.rbs +280 -177
- data/core/file_test.rbs +3 -3
- data/core/float.rbs +257 -92
- data/core/gc.rbs +425 -281
- data/core/hash.rbs +1045 -739
- data/core/integer.rbs +135 -137
- data/core/io/buffer.rbs +53 -42
- data/core/io/wait.rbs +13 -35
- data/core/io.rbs +192 -144
- data/core/kernel.rbs +216 -155
- data/core/marshal.rbs +4 -4
- data/core/match_data.rbs +15 -13
- data/core/math.rbs +107 -66
- data/core/method.rbs +69 -33
- data/core/module.rbs +244 -106
- data/core/nil_class.rbs +7 -6
- data/core/numeric.rbs +74 -63
- data/core/object.rbs +9 -11
- data/core/object_space.rbs +30 -23
- data/core/pathname.rbs +1322 -0
- data/core/proc.rbs +95 -58
- data/core/process.rbs +222 -202
- data/core/ractor.rbs +371 -515
- data/core/random.rbs +21 -3
- data/core/range.rbs +159 -57
- data/core/rational.rbs +60 -89
- data/core/rbs/unnamed/argf.rbs +60 -53
- data/core/rbs/unnamed/env_class.rbs +19 -14
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +11 -118
- data/core/regexp.rbs +258 -214
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +38 -34
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +4 -71
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +16 -82
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +490 -360
- data/core/signal.rbs +26 -16
- data/core/string.rbs +3234 -1285
- data/core/struct.rbs +27 -26
- data/core/symbol.rbs +41 -34
- data/core/thread.rbs +135 -67
- data/core/time.rbs +81 -50
- data/core/trace_point.rbs +41 -35
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +24 -16
- data/core/warning.rbs +7 -7
- data/docs/aliases.md +79 -0
- data/docs/collection.md +3 -3
- data/docs/config.md +171 -0
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +576 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +46 -16
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +544 -116
- data/ext/rbs_extension/ast_translation.h +3 -0
- data/ext/rbs_extension/class_constants.c +16 -2
- data/ext/rbs_extension/class_constants.h +8 -0
- data/ext/rbs_extension/extconf.rb +5 -1
- data/ext/rbs_extension/legacy_location.c +33 -56
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +44 -35
- data/include/rbs/ast.h +448 -173
- data/include/rbs/defines.h +27 -0
- data/include/rbs/lexer.h +30 -11
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +6 -6
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/include/rbs.h +8 -0
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +293 -3
- data/lib/rbs/ast/ruby/comment_block.rb +24 -0
- data/lib/rbs/ast/ruby/declarations.rb +198 -3
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/members.rb +532 -22
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +20 -15
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -106
- data/lib/rbs/cli.rb +52 -19
- data/lib/rbs/collection/config/lockfile_generator.rb +14 -2
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +20 -0
- data/lib/rbs/definition_builder.rb +147 -25
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +227 -74
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -18
- data/lib/rbs/inline_parser.rb +342 -6
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/parser_aux.rb +20 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +3 -20
- data/lib/rbs/prototype/runtime.rb +8 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +116 -38
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +19 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +88 -78
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -2
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +4 -3
- data/rust/.gitignore +1 -0
- data/rust/Cargo.lock +378 -0
- data/rust/Cargo.toml +7 -0
- data/rust/ruby-rbs/Cargo.toml +22 -0
- data/rust/ruby-rbs/build.rs +764 -0
- data/rust/ruby-rbs/examples/locations.rs +60 -0
- data/rust/ruby-rbs/src/lib.rs +1 -0
- data/rust/ruby-rbs/src/node/mod.rs +742 -0
- data/rust/ruby-rbs/tests/sanity.rs +47 -0
- data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
- data/rust/ruby-rbs-sys/Cargo.toml +23 -0
- data/rust/ruby-rbs-sys/build.rs +204 -0
- data/rust/ruby-rbs-sys/src/lib.rs +50 -0
- data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
- data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
- data/rust/ruby-rbs-sys/wrapper.h +1 -0
- data/schema/typeParam.json +17 -1
- data/sig/ast/ruby/annotations.rbs +315 -4
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +108 -2
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -1
- data/sig/definition_builder.rbs +2 -0
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -14
- data/sig/inline_parser.rbs +39 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -1
- data/sig/method_builder.rbs +3 -1
- data/sig/parser.rbs +31 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +35 -7
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/types.rbs +6 -7
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +410 -153
- data/src/lexer.c +1392 -1313
- data/src/lexer.re +3 -0
- data/src/lexstate.c +58 -37
- data/src/location.c +8 -48
- data/src/parser.c +977 -516
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -71
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -14
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +7 -4
- data/stdlib/date/0/date.rbs +92 -79
- data/stdlib/date/0/date_time.rbs +25 -24
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +748 -347
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +158 -139
- data/stdlib/forwardable/0/forwardable.rbs +13 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +217 -136
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +162 -134
- data/stdlib/objspace/0/objspace.rbs +17 -34
- data/stdlib/open-uri/0/open-uri.rbs +48 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +475 -357
- data/stdlib/optparse/0/optparse.rbs +26 -17
- data/stdlib/pathname/0/pathname.rbs +11 -1381
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +65 -12
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +22 -19
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +23 -10
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +11 -3
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1177 -85
- data/stdlib/strscan/0/string_scanner.rbs +27 -25
- data/stdlib/tempfile/0/tempfile.rbs +25 -21
- data/stdlib/time/0/time.rbs +8 -6
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +42 -20
- data/stdlib/uri/0/file.rbs +3 -3
- data/stdlib/uri/0/generic.rbs +26 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +6 -6
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +50 -6
|
@@ -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"
|
data/schema/typeParam.json
CHANGED
|
@@ -28,9 +28,25 @@
|
|
|
28
28
|
}
|
|
29
29
|
]
|
|
30
30
|
},
|
|
31
|
+
"lower_bound": {
|
|
32
|
+
"oneOf": [
|
|
33
|
+
{
|
|
34
|
+
"$ref": "types.json#/definitions/classInstance"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"$ref": "types.json#/definitions/classSingleton"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"$ref": "types.json#/definitions/interface"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"type": "null"
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
},
|
|
31
47
|
"location": {
|
|
32
48
|
"$ref": "location.json"
|
|
33
49
|
}
|
|
34
50
|
},
|
|
35
|
-
"required": ["name", "variance", "unchecked", "upper_bound", "location"]
|
|
51
|
+
"required": ["name", "variance", "unchecked", "upper_bound", "lower_bound", "location"]
|
|
36
52
|
}
|