rbs_macros 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +49 -0
- data/.rubocop_new.yml +269 -0
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +123 -0
- data/Rakefile +41 -0
- data/Steepfile +22 -0
- data/lib/rbs_macros/config.rb +19 -0
- data/lib/rbs_macros/environment.rb +50 -0
- data/lib/rbs_macros/exec_ctx.rb +66 -0
- data/lib/rbs_macros/library_registry.rb +52 -0
- data/lib/rbs_macros/macro.rb +12 -0
- data/lib/rbs_macros/macros/forwardable.rb +197 -0
- data/lib/rbs_macros/meta_module.rb +65 -0
- data/lib/rbs_macros/project.rb +110 -0
- data/lib/rbs_macros/version.rb +5 -0
- data/lib/rbs_macros.rb +137 -0
- data/rbs_collection.lock.yaml +60 -0
- data/rbs_collection.yaml +24 -0
- data/sig/generated/rbs_macros/library_registry.rbs +5 -0
- data/sig/rbs_macros/config.rbs +13 -0
- data/sig/rbs_macros/environment.rbs +42 -0
- data/sig/rbs_macros/exec_ctx.rbs +14 -0
- data/sig/rbs_macros/library_registry.rbs +16 -0
- data/sig/rbs_macros/macro.rbs +5 -0
- data/sig/rbs_macros/macros/forwardable.rbs +29 -0
- data/sig/rbs_macros/meta_module.rbs +29 -0
- data/sig/rbs_macros/project.rbs +22 -0
- data/sig/rbs_macros/version.rbs +3 -0
- data/sig/rbs_macros.rbs +7 -0
- data/sig-private/test/environment_test.rbs +3 -0
- data/sig-private/test/library_registry_test.rbs +11 -0
- data/sig-private/test/macros/forwardable_test.rbs +7 -0
- data/sig-private/test/rbs_macros_test.rbs +13 -0
- metadata +147 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
path: ".gem_rbs_collection"
|
3
|
+
gems:
|
4
|
+
- name: abbrev
|
5
|
+
version: '0'
|
6
|
+
source:
|
7
|
+
type: stdlib
|
8
|
+
- name: fileutils
|
9
|
+
version: '0'
|
10
|
+
source:
|
11
|
+
type: stdlib
|
12
|
+
- name: forwardable
|
13
|
+
version: '0'
|
14
|
+
source:
|
15
|
+
type: stdlib
|
16
|
+
- name: json
|
17
|
+
version: '0'
|
18
|
+
source:
|
19
|
+
type: stdlib
|
20
|
+
- name: logger
|
21
|
+
version: '0'
|
22
|
+
source:
|
23
|
+
type: stdlib
|
24
|
+
- name: minitest
|
25
|
+
version: '0'
|
26
|
+
source:
|
27
|
+
type: stdlib
|
28
|
+
- name: monitor
|
29
|
+
version: '0'
|
30
|
+
source:
|
31
|
+
type: stdlib
|
32
|
+
- name: mutex_m
|
33
|
+
version: '0'
|
34
|
+
source:
|
35
|
+
type: stdlib
|
36
|
+
- name: optparse
|
37
|
+
version: '0'
|
38
|
+
source:
|
39
|
+
type: stdlib
|
40
|
+
- name: pathname
|
41
|
+
version: '0'
|
42
|
+
source:
|
43
|
+
type: stdlib
|
44
|
+
- name: prism
|
45
|
+
version: 0.24.0
|
46
|
+
source:
|
47
|
+
type: rubygems
|
48
|
+
- name: rbs
|
49
|
+
version: 3.4.4
|
50
|
+
source:
|
51
|
+
type: rubygems
|
52
|
+
- name: rdoc
|
53
|
+
version: '0'
|
54
|
+
source:
|
55
|
+
type: stdlib
|
56
|
+
- name: tsort
|
57
|
+
version: '0'
|
58
|
+
source:
|
59
|
+
type: stdlib
|
60
|
+
gemfile_lock_path: Gemfile.lock
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
6
|
+
revision: main
|
7
|
+
repo_dir: gems
|
8
|
+
|
9
|
+
# You can specify local directories as sources also.
|
10
|
+
# - type: local
|
11
|
+
# path: path/to/your/local/repository
|
12
|
+
|
13
|
+
# A directory to install the downloaded RBSs
|
14
|
+
path: .gem_rbs_collection
|
15
|
+
|
16
|
+
gems:
|
17
|
+
- name: rake
|
18
|
+
ignore: true
|
19
|
+
- name: rubocop
|
20
|
+
ignore: true
|
21
|
+
- name: rubocop-minitest
|
22
|
+
ignore: true
|
23
|
+
- name: steep
|
24
|
+
ignore: true
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RbsMacros
|
2
|
+
class Config
|
3
|
+
attr_reader macros: Array[Macro]
|
4
|
+
attr_reader load_dirs: Array[String]
|
5
|
+
attr_reader sigs: Array[String]
|
6
|
+
attr_accessor loader: RBS::EnvironmentLoader
|
7
|
+
attr_accessor use_loader: bool
|
8
|
+
attr_accessor project: AbstractProject
|
9
|
+
attr_accessor output_dir: String
|
10
|
+
|
11
|
+
def initialize: () -> void
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RbsMacros
|
2
|
+
class Environment
|
3
|
+
attr_reader rbs: RBS::Environment
|
4
|
+
attr_reader object_class: MetaModule
|
5
|
+
attr_reader decls: Array[DeclarationEntry]
|
6
|
+
|
7
|
+
@exact_handlers: Hash[Symbol, Array[^(HandlerParams) -> void]]
|
8
|
+
|
9
|
+
def initialize: () -> void
|
10
|
+
|
11
|
+
def register_handler: (Symbol | String name, ^(HandlerParams) -> void handler) -> void
|
12
|
+
|
13
|
+
def invoke: (HandlerParams params) -> void
|
14
|
+
|
15
|
+
def meta_eval_ruby: (String, filename: String) -> void
|
16
|
+
|
17
|
+
def add_decl: (RBS::AST::Declarations::t | RBS::AST::Members::t decl, mod: MetaModule, file: String) -> void
|
18
|
+
|
19
|
+
def out_files: () -> Array[String]
|
20
|
+
|
21
|
+
class HandlerParams < Data
|
22
|
+
attr_reader env(): Environment
|
23
|
+
attr_reader filename(): String
|
24
|
+
attr_reader receiver(): Object
|
25
|
+
attr_reader name(): Symbol
|
26
|
+
attr_reader positional(): Array[Object]
|
27
|
+
attr_reader keyword(): Hash[Object, Object]
|
28
|
+
attr_reader block(): untyped
|
29
|
+
|
30
|
+
def self.new: (env: Environment, filename: String, receiver: Object, name: Symbol, positional: Array[Object], keyword: Hash[Object, Object], block: untyped) -> instance
|
31
|
+
def initialize: (env: Environment, filename: String, receiver: Object, name: Symbol, positional: Array[Object], keyword: Hash[Object, Object], block: untyped) -> void
|
32
|
+
end
|
33
|
+
|
34
|
+
class DeclarationEntry < Data
|
35
|
+
attr_reader declaration(): RBS::AST::Declarations::t | RBS::AST::Members::t
|
36
|
+
attr_reader mod(): MetaModule
|
37
|
+
attr_reader file(): String
|
38
|
+
def self.new: (declaration: RBS::AST::Declarations::t | RBS::AST::Members::t, mod: MetaModule, file: String) -> instance
|
39
|
+
def initialize: (declaration: RBS::AST::Declarations::t | RBS::AST::Members::t, mod: MetaModule, file: String) -> void
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RbsMacros
|
2
|
+
class ExecCtx < Data
|
3
|
+
attr_reader env: Environment
|
4
|
+
attr_reader filename: String
|
5
|
+
attr_reader self: untyped
|
6
|
+
attr_reader cref: MetaModule
|
7
|
+
attr_reader cref_dynamic: MetaModule
|
8
|
+
attr_reader locals: untyped
|
9
|
+
def self.new: (env: Environment, filename: String, self: untyped, cref: MetaModule, cref_dynamic: MetaModule, locals: untyped) -> instance
|
10
|
+
def initialize: (env: Environment, filename: String, self: untyped, cref: MetaModule, cref_dynamic: MetaModule, locals: untyped) -> void
|
11
|
+
|
12
|
+
def eval_node: (Prism::Node? node) -> untyped
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RbsMacros
|
2
|
+
class LibraryRegistry
|
3
|
+
extend SingleForwardable
|
4
|
+
self.@global: LibraryRegistry
|
5
|
+
|
6
|
+
@libraries: Hash[String, Array[untyped]]
|
7
|
+
|
8
|
+
def initialize: () -> void
|
9
|
+
|
10
|
+
def register_macros: (String name, ?Array[untyped] macros) ?{ (Array[untyped] macros) -> void } -> void
|
11
|
+
|
12
|
+
def lookup_macros: (String name, ?soft_fail: bool) -> Array[untyped]
|
13
|
+
|
14
|
+
def require_library: (String name, ?soft_fail: bool) -> void
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RbsMacros
|
2
|
+
module Macros
|
3
|
+
class ForwardableMacros < Macro
|
4
|
+
def meta_def_delegator: (Environment::HandlerParams params) -> void
|
5
|
+
def meta_def_delegators: (Environment::HandlerParams params) -> void
|
6
|
+
|
7
|
+
def method: (:meta_def_delegator) -> ^(Environment::HandlerParams params) -> void
|
8
|
+
| (:meta_def_delegators) -> ^(Environment::HandlerParams params) -> void
|
9
|
+
| ...
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def widened_instance: (RBS::Types::t type, builder: RBS::DefinitionBuilder) -> [RBS::Definition, RBS::Substitution]?
|
14
|
+
end
|
15
|
+
|
16
|
+
class SingleForwardableMacros < Macro
|
17
|
+
def meta_def_delegator: (Environment::HandlerParams params) -> void
|
18
|
+
def meta_def_delegators: (Environment::HandlerParams params) -> void
|
19
|
+
|
20
|
+
def method: (:meta_def_delegator) -> ^(Environment::HandlerParams params) -> void
|
21
|
+
| (:meta_def_delegators) -> ^(Environment::HandlerParams params) -> void
|
22
|
+
| ...
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def widened_instance: (RBS::Types::t type, builder: RBS::DefinitionBuilder) -> [RBS::Definition, RBS::Substitution]?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RbsMacros
|
2
|
+
class MetaModule
|
3
|
+
attr_reader env: Environment
|
4
|
+
attr_reader name: String?
|
5
|
+
attr_reader is_class: bool?
|
6
|
+
attr_reader superclass: MetaModule?
|
7
|
+
|
8
|
+
@constants: Hash[Symbol, untyped]
|
9
|
+
@rbs_type: RBS::TypeName
|
10
|
+
|
11
|
+
def initialize: (Environment env, String? name, ?is_class: bool?, ?superclass: MetaModule?) -> void
|
12
|
+
|
13
|
+
def rbs_type: () -> RBS::TypeName
|
14
|
+
|
15
|
+
def class!: () -> void
|
16
|
+
def module!: () -> void
|
17
|
+
def define_module: (Symbol name) -> MetaModule
|
18
|
+
|
19
|
+
def meta_const_set: (Symbol name, untyped value) -> void
|
20
|
+
def meta_const_get: (Symbol name) -> untyped
|
21
|
+
def meta_constants: () -> Array[Symbol]
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def child_module_name: (String? child_name) -> String?
|
26
|
+
end
|
27
|
+
|
28
|
+
class MetaClass = MetaModule
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RbsMacros
|
2
|
+
class AbstractProject
|
3
|
+
def glob: (ext: String, include: Array[String], exclude: Array[String]) { (String) -> void } -> void
|
4
|
+
| (ext: String, include: Array[String], exclude: Array[String]) -> Enumerator[String, void]
|
5
|
+
|
6
|
+
def write: (String path, String content) -> void
|
7
|
+
|
8
|
+
def read: (String path) -> String
|
9
|
+
end
|
10
|
+
|
11
|
+
class Project < AbstractProject
|
12
|
+
attr_reader base_dir: Pathname
|
13
|
+
|
14
|
+
def initialize: (?base_dir: Pathname) -> void
|
15
|
+
end
|
16
|
+
|
17
|
+
class FakeProject < AbstractProject
|
18
|
+
@files: Hash[String, String]
|
19
|
+
|
20
|
+
def initialize: () -> void
|
21
|
+
end
|
22
|
+
end
|
data/sig/rbs_macros.rbs
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
class LibraryRegistryTest < Minitest::Test
|
2
|
+
def test_register_array: () -> void
|
3
|
+
def test_register_block: () -> void
|
4
|
+
def test_register_empty: () -> void
|
5
|
+
def test_register_multiple: () -> void
|
6
|
+
def test_lookup_missing: () -> void
|
7
|
+
def test_lookup_require: () -> void
|
8
|
+
def test_lookup_require_fail: () -> void
|
9
|
+
def test_lookup_require_no_registration: () -> void
|
10
|
+
def test_lookup_require_soft: () -> void
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbs_macros
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wantedly, Inc.
|
8
|
+
- Masaki Hara
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2024-02-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fileutils
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: forwardable
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.3'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.3'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: prism
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.24.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.24.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rbs
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.4'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.4'
|
70
|
+
description: |
|
71
|
+
Rubyists love metaprogramming.
|
72
|
+
This tool bridges between RBS and metaprogramming,
|
73
|
+
by allowing you to define a macro,
|
74
|
+
which is then used to generate RBS definitions
|
75
|
+
based on macro invocations."
|
76
|
+
email:
|
77
|
+
- dev@wantedly.com
|
78
|
+
- ackie.h.gmai@gmail.com
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- ".rspec"
|
84
|
+
- ".rubocop.yml"
|
85
|
+
- ".rubocop_new.yml"
|
86
|
+
- CHANGELOG.md
|
87
|
+
- CODE_OF_CONDUCT.md
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- Steepfile
|
92
|
+
- lib/rbs_macros.rb
|
93
|
+
- lib/rbs_macros/config.rb
|
94
|
+
- lib/rbs_macros/environment.rb
|
95
|
+
- lib/rbs_macros/exec_ctx.rb
|
96
|
+
- lib/rbs_macros/library_registry.rb
|
97
|
+
- lib/rbs_macros/macro.rb
|
98
|
+
- lib/rbs_macros/macros/forwardable.rb
|
99
|
+
- lib/rbs_macros/meta_module.rb
|
100
|
+
- lib/rbs_macros/project.rb
|
101
|
+
- lib/rbs_macros/version.rb
|
102
|
+
- rbs_collection.lock.yaml
|
103
|
+
- rbs_collection.yaml
|
104
|
+
- sig-private/test/environment_test.rbs
|
105
|
+
- sig-private/test/library_registry_test.rbs
|
106
|
+
- sig-private/test/macros/forwardable_test.rbs
|
107
|
+
- sig-private/test/rbs_macros_test.rbs
|
108
|
+
- sig/generated/rbs_macros/library_registry.rbs
|
109
|
+
- sig/rbs_macros.rbs
|
110
|
+
- sig/rbs_macros/config.rbs
|
111
|
+
- sig/rbs_macros/environment.rbs
|
112
|
+
- sig/rbs_macros/exec_ctx.rbs
|
113
|
+
- sig/rbs_macros/library_registry.rbs
|
114
|
+
- sig/rbs_macros/macro.rbs
|
115
|
+
- sig/rbs_macros/macros/forwardable.rbs
|
116
|
+
- sig/rbs_macros/meta_module.rbs
|
117
|
+
- sig/rbs_macros/project.rbs
|
118
|
+
- sig/rbs_macros/version.rbs
|
119
|
+
homepage: https://github.com/wantedly/rbs_macros
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata:
|
123
|
+
allowed_push_host: https://rubygems.org
|
124
|
+
rubygems_mfa_required: 'true'
|
125
|
+
homepage_uri: https://github.com/wantedly/rbs_macros
|
126
|
+
source_code_uri: https://github.com/wantedly/rbs_macros
|
127
|
+
changelog_uri: https://github.com/wantedly/rbs_macros/tree/master/CHANGELOG.md
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 3.2.0
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubygems_version: 3.5.3
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: RBS meets metaprogramming
|
147
|
+
test_files: []
|