rbs_protobuf 0.3.0 → 1.1.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.
@@ -1,3 +1,3 @@
1
1
  module RBSProtobuf
2
- VERSION = "0.3.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/rbs_protobuf.rb CHANGED
@@ -3,7 +3,7 @@ require "rbs_protobuf/version"
3
3
  require "logger"
4
4
 
5
5
  require "protobuf/descriptors"
6
- require "active_support/inflector"
6
+ require "active_support"
7
7
  require "rbs"
8
8
 
9
9
  module RBSProtobuf
@@ -14,6 +14,7 @@ module RBSProtobuf
14
14
  @logger = Logger.new(STDERR)
15
15
  end
16
16
 
17
+ require "rbs_protobuf/name"
17
18
  require "rbs_protobuf/rbs_factory"
18
19
  require "rbs_protobuf/translator/base"
19
20
  require "rbs_protobuf/translator/protobuf_gem"
@@ -1,84 +1,61 @@
1
1
  ---
2
2
  sources:
3
- - name: ruby/gem_rbs_collection
3
+ - type: git
4
+ name: ruby/gem_rbs_collection
5
+ revision: 8a678b2ec20e9d594055f53745399814e3a887dc
4
6
  remote: https://github.com/ruby/gem_rbs_collection.git
5
- revision: main
6
7
  repo_dir: gems
7
8
  path: ".gem_rbs_collection"
8
9
  gems:
9
- - name: rbs
10
- version: 2.3.1
10
+ - name: abbrev
11
+ version: '0'
11
12
  source:
12
- type: rubygems
13
+ type: stdlib
13
14
  - name: activesupport
14
- version: '6.0'
15
+ version: '7.0'
15
16
  source:
16
17
  type: git
17
18
  name: ruby/gem_rbs_collection
18
- revision: f43bb5ffee382df94113f44c7555027d7089912a
19
+ revision: 8a678b2ec20e9d594055f53745399814e3a887dc
19
20
  remote: https://github.com/ruby/gem_rbs_collection.git
20
21
  repo_dir: gems
21
- - name: protobuf
22
- version: 3.10.3
22
+ - name: concurrent-ruby
23
+ version: '1.1'
23
24
  source:
24
25
  type: git
25
26
  name: ruby/gem_rbs_collection
26
- revision: f43bb5ffee382df94113f44c7555027d7089912a
27
+ revision: 8a678b2ec20e9d594055f53745399814e3a887dc
27
28
  remote: https://github.com/ruby/gem_rbs_collection.git
28
29
  repo_dir: gems
29
- - name: ast
30
- version: '2.4'
30
+ - name: date
31
+ version: '0'
31
32
  source:
32
- type: git
33
- name: ruby/gem_rbs_collection
34
- revision: f43bb5ffee382df94113f44c7555027d7089912a
35
- remote: https://github.com/ruby/gem_rbs_collection.git
36
- repo_dir: gems
33
+ type: stdlib
37
34
  - name: i18n
38
35
  version: '1.10'
39
36
  source:
40
37
  type: git
41
38
  name: ruby/gem_rbs_collection
42
- revision: f43bb5ffee382df94113f44c7555027d7089912a
39
+ revision: 8a678b2ec20e9d594055f53745399814e3a887dc
43
40
  remote: https://github.com/ruby/gem_rbs_collection.git
44
41
  repo_dir: gems
45
- - name: listen
46
- version: '3.2'
47
- source:
48
- type: git
49
- name: ruby/gem_rbs_collection
50
- revision: f43bb5ffee382df94113f44c7555027d7089912a
51
- remote: https://github.com/ruby/gem_rbs_collection.git
52
- repo_dir: gems
53
- - name: parallel
54
- version: '1.20'
55
- source:
56
- type: git
57
- name: ruby/gem_rbs_collection
58
- revision: f43bb5ffee382df94113f44c7555027d7089912a
59
- remote: https://github.com/ruby/gem_rbs_collection.git
60
- repo_dir: gems
61
- - name: rainbow
62
- version: '3.0'
42
+ - name: json
43
+ version: '0'
63
44
  source:
64
- type: git
65
- name: ruby/gem_rbs_collection
66
- revision: f43bb5ffee382df94113f44c7555027d7089912a
67
- remote: https://github.com/ruby/gem_rbs_collection.git
68
- repo_dir: gems
45
+ type: stdlib
69
46
  - name: logger
70
47
  version: '0'
71
48
  source:
72
49
  type: stdlib
73
- - name: set
50
+ - name: minitest
74
51
  version: '0'
75
52
  source:
76
53
  type: stdlib
77
- - name: pathname
54
+ - name: monitor
78
55
  version: '0'
79
56
  source:
80
57
  type: stdlib
81
- - name: json
58
+ - name: mutex_m
82
59
  version: '0'
83
60
  source:
84
61
  type: stdlib
@@ -86,19 +63,27 @@ gems:
86
63
  version: '0'
87
64
  source:
88
65
  type: stdlib
89
- - name: rubygems
66
+ - name: pathname
90
67
  version: '0'
91
68
  source:
92
69
  type: stdlib
93
- - name: tsort
94
- version: '0'
70
+ - name: protobuf
71
+ version: 3.10.3
95
72
  source:
96
- type: stdlib
97
- - name: monitor
73
+ type: git
74
+ name: ruby/gem_rbs_collection
75
+ revision: 8a678b2ec20e9d594055f53745399814e3a887dc
76
+ remote: https://github.com/ruby/gem_rbs_collection.git
77
+ repo_dir: gems
78
+ - name: rbs
79
+ version: 3.1.3
80
+ source:
81
+ type: rubygems
82
+ - name: rdoc
98
83
  version: '0'
99
84
  source:
100
85
  type: stdlib
101
- - name: date
86
+ - name: securerandom
102
87
  version: '0'
103
88
  source:
104
89
  type: stdlib
@@ -106,11 +91,12 @@ gems:
106
91
  version: '0'
107
92
  source:
108
93
  type: stdlib
109
- - name: mutex_m
94
+ - name: time
110
95
  version: '0'
111
96
  source:
112
97
  type: stdlib
113
- - name: time
98
+ - name: tsort
114
99
  version: '0'
115
100
  source:
116
101
  type: stdlib
102
+ gemfile_lock_path: Gemfile.lock
data/rbs_collection.yaml CHANGED
@@ -8,11 +8,4 @@ sources:
8
8
  # A directory to install the downloaded RBSs
9
9
  path: .gem_rbs_collection
10
10
 
11
- gems:
12
- # Skip loading rbs gem's RBS.
13
- # It's unnecessary if you don't use rbs as a library.
14
- - name: rbs
15
- - name: activesupport
16
- - name: protobuf
17
- - name: rbs_protobuf
18
- ignore: true
11
+ gems: []
@@ -0,0 +1,45 @@
1
+ module RBSProtobuf
2
+ module Name
3
+ class Class
4
+ attr_reader name: RBS::TypeName
5
+
6
+ def initialize: (RBS::TypeName) -> void
7
+
8
+ def instance_type: (*RBS::Types::t args) -> RBS::Types::ClassInstance
9
+
10
+ def singleton_type: () -> RBS::Types::ClassSingleton
11
+
12
+ def instance_type?: (RBS::Types::t) -> bool
13
+
14
+ def singleton_type?: (RBS::Types::t) -> bool
15
+
16
+ alias [] instance_type
17
+
18
+ def super_class: (*RBS::Types::t args) -> RBS::AST::Declarations::Class::Super
19
+ end
20
+
21
+ class Alias
22
+ attr_reader name: RBS::TypeName
23
+
24
+ def initialize: (RBS::TypeName) -> void
25
+
26
+ def []: (*RBS::Types::t args) -> RBS::Types::Alias
27
+
28
+ def type?: (RBS::Types::t) -> bool
29
+
30
+ alias === type?
31
+ end
32
+
33
+ class Interface
34
+ attr_reader name: RBS::TypeName
35
+
36
+ def initialize: (RBS::TypeName) -> void
37
+
38
+ def []: (*RBS::Types::t args) -> RBS::Types::Interface
39
+
40
+ def type?: (RBS::Types::t) -> bool
41
+
42
+ alias === type?
43
+ end
44
+ end
45
+ end
@@ -1,53 +1,122 @@
1
1
  module RBSProtobuf
2
2
  module Translator
3
3
  class ProtobufGem < Base
4
+ # Protobuf::Field::FieldArray[R, W]
5
+ FIELD_ARRAY: Name::Class
6
+
7
+ # Protobuf::Field::FieldHash[K, RV, WV]
8
+ FIELD_HASH: Name::Class
9
+
10
+ # Protobuf::Enum
11
+ ENUM: Name::Class
12
+
13
+ # Protobuf::Message
14
+ MESSAGE: Name::Class
15
+
16
+ # _ToProto
17
+ TO_PROTO: Name::Interface
18
+
19
+ # Protobuf::field_array[T]
20
+ FIELD_ARRAY_a: Name::Alias
21
+
22
+ # Protobuf::field_hash[K, V]
23
+ FIELD_HASH_a: Name::Alias
24
+
4
25
  attr_reader stderr: IO
5
26
 
27
+ attr_reader accept_nil_writer: bool
28
+
6
29
  def initialize: (
7
30
  untyped input,
8
31
  upcase_enum: bool,
9
32
  nested_namespace: bool,
10
33
  extension: bool | :print | nil,
11
- ?stderr: IO
34
+ accept_nil_writer: bool,
35
+ ?stderr: IO,
12
36
  ) -> void
13
37
 
14
38
  @upcase_enum: bool
15
39
 
16
- @pnested_namespace: bool
40
+ @nested_namespace: bool
17
41
 
18
42
  @extension: bool | :print | nil
19
43
 
44
+ # Returns true if extension should be ignored.
45
+ #
20
46
  def ignore_extension?: () -> bool
21
47
 
48
+ # Returns true if documentation message about extension is requested.
22
49
  def print_extension_message?: () -> bool
23
50
 
51
+ # Returns true if extension should be printed to stderr.
52
+ #
24
53
  def print_extension?: () -> bool
25
54
 
55
+ # Returns true if enum names should be `upcase`.
56
+ #
26
57
  def upcase_enum?: () -> bool
27
58
 
59
+ # Returns true if printing nested namespace is preferred.
60
+ #
28
61
  def nested_namespace?: () -> bool
29
62
 
63
+ # The entry point.
64
+ # Generate RBS declarations from the `file` and returns the string representation of the declarations.
65
+ #
30
66
  def rbs_content: (untyped file) -> String
31
67
 
32
- def message_base_class: () -> RBS::AST::Declarations::Class::Super
68
+ # Returns the class declaration for given message.
69
+ #
70
+ def message_to_decl: (untyped message, prefix: RBS::Namespace, message_path: untyped, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
33
71
 
34
- def repeated_field_type: (RBS::Types::t `type`, ?RBS::Types::t wtype) -> RBS::Types::ClassInstance
72
+ # Returns the class declaration for given enum.
73
+ #
74
+ def enum_type_to_decl: (untyped enum_type, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
35
75
 
36
- def message_to_decl: (untyped message, prefix: RBS::Namespace, message_path: untyped, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
76
+ # Returns the class declaration for given extension.
77
+ #
78
+ def extension_to_decl: (untyped extension, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
37
79
 
38
- def field_type: (untyped field, Hash[String, [RBS::Types::t, RBS::Types::t]] maps) -> [RBS::Types::t, RBS::Types::t]
80
+ # Returns service class stub.
81
+ #
82
+ def service_to_decl: (untyped service, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
83
+
84
+ # Returns a triple of types of a field.
85
+ #
86
+ # - The first one is the type of the attribute. (read and write)
87
+ # - The second one is the array of type of additional possibilities for write.
88
+ # - The last one is the type of `initialize` parameter.
89
+ #
90
+ def field_type: (untyped field, Hash[String, [untyped, untyped]] maps) -> [RBS::Types::t, Array[RBS::Types::t], RBS::Types::t]
91
+
92
+ def message_to_proto_type: (RBS::Types::ClassInstance) -> RBS::Types::Interface
93
+
94
+ def message_array_type: (RBS::Types::ClassInstance) -> RBS::Types::Alias
95
+
96
+ def message_field_array_type: (RBS::Types::ClassInstance) -> RBS::Types::Alias
39
97
 
40
- def enum_base_class: () -> RBS::AST::Declarations::Class::Super
98
+ def message_hash_type: (RBS::Types::ClassInstance, RBS::Types::t key) -> RBS::Types::Alias
41
99
 
100
+ def message_field_hash_type: (RBS::Types::ClassInstance, RBS::Types::t key) -> RBS::Types::Alias
101
+
102
+ def message_init_type: (RBS::Types::ClassInstance) -> RBS::Types::Alias
103
+
104
+ # Returns enum names with respect to `#upcase_enum?`.
105
+ #
42
106
  def enum_name: (String name) -> Symbol
43
107
 
44
- def enum_type_to_decl: (untyped enum_type, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
108
+ # Add field to `members`. It adds
109
+ #
110
+ # - `attr_accessor` of the field `name` with `read_type`
111
+ # - Overloads for attribute writer with `write_types`
112
+ #
113
+ def add_field: (Array[RBS::AST::Declarations::Class::member] members, name: Symbol, read_type: RBS::Types::t, write_types: Array[RBS::Types::t], comment: RBS::AST::Comment?) -> void
45
114
 
46
- def extension_to_decl: (String extendee_name, Array[untyped] extensions, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> Array[RBS::AST::Declarations::Class]
115
+ # Returns true if `write_type` is an _interface type_ or an optional type of _interface type_.
116
+ #
117
+ def interface_type?: (RBS::Types::t write_type) -> [RBS::AST::TypeParam, RBS::Types::t]?
47
118
 
48
119
  def service_base_class: () -> RBS::AST::Declarations::Class::Super
49
-
50
- def service_to_decl: (untyped service, prefix: RBS::Namespace, source_code_info: untyped, path: Array[Integer]) -> RBS::AST::Declarations::Class
51
120
  end
52
121
  end
53
122
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs_protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-05 00:00:00.000000000 Z
11
+ date: 2023-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -49,7 +49,6 @@ files:
49
49
  - ".github/workflows/test.yml"
50
50
  - ".gitignore"
51
51
  - ".gitmodules"
52
- - ".protoc-version"
53
52
  - ".rakeTasks"
54
53
  - ".travis.yml"
55
54
  - CHANGELOG.md
@@ -69,9 +68,11 @@ files:
69
68
  - example/a.proto
70
69
  - example/b.proto
71
70
  - example/c.proto
71
+ - example/d.proto
72
72
  - example/protobuf_gem_example.rb
73
73
  - exe/protoc-gen-rbs
74
74
  - lib/rbs_protobuf.rb
75
+ - lib/rbs_protobuf/name.rb
75
76
  - lib/rbs_protobuf/rbs_factory.rb
76
77
  - lib/rbs_protobuf/translator/base.rb
77
78
  - lib/rbs_protobuf/translator/protobuf_gem.rb
@@ -80,6 +81,7 @@ files:
80
81
  - rbs_collection.yaml
81
82
  - rbs_protobuf.gemspec
82
83
  - sig/rbs_protobuf.rbs
84
+ - sig/rbs_protobuf/name.rbs
83
85
  - sig/rbs_protobuf/rbs_factory.rbs
84
86
  - sig/rbs_protobuf/translator/base.rbs
85
87
  - sig/rbs_protobuf/translator/protobuf_gem.rbs
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
108
  - !ruby/object:Gem::Version
107
109
  version: '0'
108
110
  requirements: []
109
- rubygems_version: 3.3.7
111
+ rubygems_version: 3.4.10
110
112
  signing_key:
111
113
  specification_version: 4
112
114
  summary: Generate RBS files from .proto files
data/.protoc-version DELETED
@@ -1 +0,0 @@
1
- 3.9.0-square-1.0