protobug-compiler 0.1.0 → 0.2.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/lib/protobug/compiler/builder.rb +18 -7
- data/lib/protobug/compiler.rb +47 -4
- metadata +10 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d59816ef3310c5e4d917cc05e3145bc90f503511df19781974193e85b6a10505
|
|
4
|
+
data.tar.gz: 00c54e975e24584e05828e72207298713be358c2931d840176c5a0a3e8f21cde
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2753c9f2e3d14c8721359b45ad02346c6ae919e3fb5a52608579c6de051a7fe8782eccd9a6124a354a19a2330ef4b9e11afb784795bc0fe923099e58438de9f
|
|
7
|
+
data.tar.gz: c01ecd703e6f5ff0bf19d60f6bb68561e6cb6a7e5f91f38f79e4911a863088b0e25ccdbaf7c447fa6aa89a06c1b5191f15997d76866056fe72eae6f80a4aaf36
|
|
@@ -86,7 +86,9 @@ module Protobug
|
|
|
86
86
|
items.none? { |item| !item.empty? }
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
def compact?
|
|
89
|
+
def compact?
|
|
90
|
+
false
|
|
91
|
+
end
|
|
90
92
|
end
|
|
91
93
|
|
|
92
94
|
Group = Struct.new(:name, :items, :open, :close, :separator, :multi, :indent,
|
|
@@ -146,7 +148,9 @@ module Protobug
|
|
|
146
148
|
items.none? { |item| !item.empty? }
|
|
147
149
|
end
|
|
148
150
|
|
|
149
|
-
def compact?
|
|
151
|
+
def compact?
|
|
152
|
+
false
|
|
153
|
+
end
|
|
150
154
|
|
|
151
155
|
private
|
|
152
156
|
|
|
@@ -182,7 +186,7 @@ module Protobug
|
|
|
182
186
|
def render
|
|
183
187
|
q = PrettierPrint.new(+"")
|
|
184
188
|
@headers.each_with_index do |header, idx|
|
|
185
|
-
q.breakable_force if idx
|
|
189
|
+
q.breakable_force if idx > 0
|
|
186
190
|
Comment.new(header).render(q)
|
|
187
191
|
q.breakable_force
|
|
188
192
|
end
|
|
@@ -215,8 +219,13 @@ module Protobug
|
|
|
215
219
|
end
|
|
216
220
|
end
|
|
217
221
|
|
|
218
|
-
def empty?
|
|
219
|
-
|
|
222
|
+
def empty?
|
|
223
|
+
false
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def compact?
|
|
227
|
+
false
|
|
228
|
+
end
|
|
220
229
|
end
|
|
221
230
|
|
|
222
231
|
Token = Struct.new(:type, :content,
|
|
@@ -230,7 +239,7 @@ module Protobug
|
|
|
230
239
|
when Integer
|
|
231
240
|
int_part = Integer(content)
|
|
232
241
|
formatted_int = int_part.abs.to_s.reverse.gsub(/...(?=.)/, '\&_').reverse
|
|
233
|
-
formatted_int.insert(0, "-") if int_part
|
|
242
|
+
formatted_int.insert(0, "-") if int_part < 0
|
|
234
243
|
q.text formatted_int
|
|
235
244
|
else
|
|
236
245
|
q.text content.inspect
|
|
@@ -240,7 +249,9 @@ module Protobug
|
|
|
240
249
|
end
|
|
241
250
|
end
|
|
242
251
|
|
|
243
|
-
def empty?
|
|
252
|
+
def empty?
|
|
253
|
+
false
|
|
254
|
+
end
|
|
244
255
|
|
|
245
256
|
COMPACT_OPERATORS = %w[** .. ...].freeze # rubocop:disable Lint/ConstantDefinitionInBlock
|
|
246
257
|
|
data/lib/protobug/compiler.rb
CHANGED
|
@@ -125,7 +125,9 @@ module Protobug
|
|
|
125
125
|
|
|
126
126
|
define_method(name) do
|
|
127
127
|
field_type = Compiler.const_get(message_name)
|
|
128
|
-
|
|
128
|
+
__getobj__.send(name).map.with_index do |d, idx|
|
|
129
|
+
field_type.new(d, self, path: @path + [field.number, idx])
|
|
130
|
+
end
|
|
129
131
|
end
|
|
130
132
|
end
|
|
131
133
|
|
|
@@ -145,8 +147,13 @@ module Protobug
|
|
|
145
147
|
Google::Protobuf.const_get(name.split("::").last)
|
|
146
148
|
end
|
|
147
149
|
|
|
148
|
-
def fields_by_number
|
|
149
|
-
|
|
150
|
+
def fields_by_number
|
|
151
|
+
descriptor_class.fields_by_number
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def fields_by_name
|
|
155
|
+
descriptor_class.fields_by_name
|
|
156
|
+
end
|
|
150
157
|
end
|
|
151
158
|
end
|
|
152
159
|
|
|
@@ -194,6 +201,23 @@ module Protobug
|
|
|
194
201
|
include Descriptor
|
|
195
202
|
end
|
|
196
203
|
|
|
204
|
+
class MethodDescriptorProto < DelegateClass(Google::Protobuf::MethodDescriptorProto)
|
|
205
|
+
include Descriptor
|
|
206
|
+
|
|
207
|
+
def ruby_method_name
|
|
208
|
+
return name unless /[A-Z-]|::/.match?(name)
|
|
209
|
+
|
|
210
|
+
word = name.gsub("::", "/")
|
|
211
|
+
# word.gsub!(inflections.acronyms_underscore_regex) do
|
|
212
|
+
# "#{::Regexp.last_match(1) && "_"}#{::Regexp.last_match(2).downcase}"
|
|
213
|
+
# end
|
|
214
|
+
word.gsub!(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, "_")
|
|
215
|
+
word.tr!("-", "_")
|
|
216
|
+
word.downcase!
|
|
217
|
+
word
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
197
221
|
def compile!
|
|
198
222
|
response.supported_features |=
|
|
199
223
|
Google::Protobuf::Compiler::CodeGeneratorResponse::Feature::FEATURE_PROTO3_OPTIONAL.value
|
|
@@ -376,6 +400,24 @@ module Protobug
|
|
|
376
400
|
when OneofDescriptorProto
|
|
377
401
|
group.empty if source_loc.leading_comments?
|
|
378
402
|
# no-op
|
|
403
|
+
when ServiceDescriptorProto
|
|
404
|
+
group._class.identifier(descriptor.name).block do |g|
|
|
405
|
+
requires_empty = false
|
|
406
|
+
descriptor.each_declaration do |decl|
|
|
407
|
+
g.empty if requires_empty
|
|
408
|
+
requires_empty = true
|
|
409
|
+
requires_empty = emit_decls(decl, g)
|
|
410
|
+
end
|
|
411
|
+
end
|
|
412
|
+
when MethodDescriptorProto
|
|
413
|
+
group._def.identifier(descriptor.ruby_method_name)
|
|
414
|
+
.call do |c|
|
|
415
|
+
c.identifier("...")
|
|
416
|
+
end.block do |defn|
|
|
417
|
+
defn.identifier("raise").call do |c|
|
|
418
|
+
c.identifier("NotImplementedError")
|
|
419
|
+
end
|
|
420
|
+
end
|
|
379
421
|
else
|
|
380
422
|
raise "Unknown descriptor type: #{descriptor.class}"
|
|
381
423
|
end.tap do |s|
|
|
@@ -487,7 +529,8 @@ module Protobug
|
|
|
487
529
|
end
|
|
488
530
|
)
|
|
489
531
|
defn.comment("extension: #{containing_type.full_name}\n #{descriptor.type} #{descriptor.number}")
|
|
490
|
-
when FileDescriptorProto, EnumValueDescriptorProto, ServiceDescriptorProto, OneofDescriptorProto
|
|
532
|
+
when FileDescriptorProto, EnumValueDescriptorProto, ServiceDescriptorProto, OneofDescriptorProto,
|
|
533
|
+
MethodDescriptorProto
|
|
491
534
|
# no-op
|
|
492
535
|
else
|
|
493
536
|
raise "Unknown descriptor type: #{descriptor.class}"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: protobug-compiler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Giddins
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-06-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: delegate
|
|
@@ -64,29 +64,29 @@ dependencies:
|
|
|
64
64
|
requirements:
|
|
65
65
|
- - '='
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: 0.
|
|
67
|
+
version: 0.2.0
|
|
68
68
|
type: :runtime
|
|
69
69
|
prerelease: false
|
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
71
71
|
requirements:
|
|
72
72
|
- - '='
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: 0.
|
|
74
|
+
version: 0.2.0
|
|
75
75
|
- !ruby/object:Gem::Dependency
|
|
76
76
|
name: protobug_compiler_protos
|
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
|
78
78
|
requirements:
|
|
79
79
|
- - '='
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: 0.
|
|
81
|
+
version: 0.2.0
|
|
82
82
|
type: :runtime
|
|
83
83
|
prerelease: false
|
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
|
86
86
|
- - '='
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: 0.
|
|
89
|
-
description:
|
|
88
|
+
version: 0.2.0
|
|
89
|
+
description:
|
|
90
90
|
email:
|
|
91
91
|
- segiddins@segiddins.me
|
|
92
92
|
executables:
|
|
@@ -108,7 +108,7 @@ metadata:
|
|
|
108
108
|
rubygems_mfa_required: 'true'
|
|
109
109
|
homepage_uri: https://github.com/segiddins/protobug
|
|
110
110
|
source_code_uri: https://github.com/segiddins/protobug
|
|
111
|
-
post_install_message:
|
|
111
|
+
post_install_message:
|
|
112
112
|
rdoc_options: []
|
|
113
113
|
require_paths:
|
|
114
114
|
- lib
|
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
124
124
|
version: '0'
|
|
125
125
|
requirements: []
|
|
126
126
|
rubygems_version: 3.5.9
|
|
127
|
-
signing_key:
|
|
127
|
+
signing_key:
|
|
128
128
|
specification_version: 4
|
|
129
129
|
summary: An protobuf compiler for protobug
|
|
130
130
|
test_files: []
|