ruby_protobuf 0.3.3 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -2
- data/Manifest.txt +26 -12
- data/README.txt +6 -1
- data/Rakefile +51 -14
- data/TODO +15 -0
- data/VERSION +1 -0
- data/bin/rprotoc +11 -6
- data/lib/protobuf/common/exceptions.rb +11 -0
- data/lib/protobuf/common/util.rb +9 -0
- data/lib/protobuf/common/wire_type.rb +6 -6
- data/lib/protobuf/compiler/compiler.rb +16 -16
- data/lib/protobuf/compiler/nodes.rb +67 -65
- data/lib/protobuf/compiler/proto.y +31 -38
- data/lib/protobuf/compiler/proto_parser.rb +315 -294
- data/lib/protobuf/compiler/template/rpc_bin.erb +1 -1
- data/lib/protobuf/compiler/template/rpc_client.erb +1 -1
- data/lib/protobuf/compiler/template/rpc_service.erb +2 -2
- data/lib/protobuf/compiler/visitors.rb +45 -39
- data/lib/protobuf/descriptor/descriptor.proto +0 -0
- data/lib/protobuf/descriptor/descriptor.rb +11 -10
- data/lib/protobuf/descriptor/descriptor_builder.rb +6 -7
- data/lib/protobuf/descriptor/descriptor_proto.rb +51 -31
- data/lib/protobuf/descriptor/enum_descriptor.rb +5 -5
- data/lib/protobuf/descriptor/field_descriptor.rb +8 -9
- data/lib/protobuf/descriptor/file_descriptor.rb +0 -1
- data/lib/protobuf/message/decoder.rb +33 -35
- data/lib/protobuf/message/encoder.rb +23 -19
- data/lib/protobuf/message/enum.rb +43 -9
- data/lib/protobuf/message/field.rb +281 -193
- data/lib/protobuf/message/message.rb +166 -110
- data/lib/protobuf/message/protoable.rb +4 -3
- data/lib/protobuf/message/service.rb +1 -1
- data/lib/protobuf/rpc/client.rb +3 -3
- data/lib/protobuf/rpc/handler.rb +1 -1
- data/lib/protobuf/rpc/server.rb +8 -8
- data/lib/ruby_protobuf.rb +1 -1
- data/test/check_unbuild.rb +7 -7
- data/test/proto/addressbook.pb.rb +67 -0
- data/test/proto/addressbook.proto +2 -0
- data/test/proto/addressbook_base.pb.rb +59 -0
- data/test/proto/addressbook_base.proto +1 -1
- data/test/proto/addressbook_ext.pb.rb +21 -0
- data/test/proto/addressbook_ext.proto +2 -2
- data/test/{collision.rb → proto/collision.pb.rb} +0 -0
- data/test/{ext_collision.rb → proto/ext_collision.pb.rb} +1 -1
- data/test/{ext_range.rb → proto/ext_range.pb.rb} +4 -4
- data/test/proto/ext_range.proto +2 -2
- data/test/proto/float_default.proto +10 -0
- data/test/proto/lowercase.pb.rb +31 -0
- data/test/proto/lowercase.proto +9 -0
- data/test/{merge.rb → proto/merge.pb.rb} +2 -2
- data/test/proto/nested.pb.rb +31 -0
- data/test/proto/nested.proto +2 -0
- data/test/proto/optional_field.pb.rb +36 -0
- data/test/proto/optional_field.proto +12 -0
- data/test/proto/packed.pb.rb +23 -0
- data/test/proto/packed.proto +6 -0
- data/test/{types.rb → proto/types.pb.rb} +43 -1
- data/test/test_addressbook.rb +30 -17
- data/test/test_compiler.rb +79 -78
- data/test/test_descriptor.rb +12 -12
- data/test/test_enum_value.rb +41 -0
- data/test/test_extension.rb +10 -14
- data/test/test_lowercase.rb +11 -0
- data/test/test_message.rb +44 -41
- data/test/test_optional_field.rb +61 -38
- data/test/test_packed_field.rb +40 -0
- data/test/test_parse.rb +8 -8
- data/test/test_repeated_types.rb +29 -3
- data/test/test_serialize.rb +12 -12
- data/test/test_standard_message.rb +30 -30
- data/test/test_types.rb +95 -95
- metadata +69 -39
- data/test/addressbook.rb +0 -98
- data/test/addressbook_base.rb +0 -62
- data/test/addressbook_ext.rb +0 -12
- data/test/nested.rb +0 -25
- data/test/test_ruby_protobuf.rb +0 -1
@@ -1,9 +1,9 @@
|
|
1
1
|
class Protobuf::ProtoParser
|
2
2
|
rule
|
3
3
|
proto : proto_item
|
4
|
-
{ result = Protobuf::Node::ProtoNode.new
|
4
|
+
{ result = Protobuf::Node::ProtoNode.new(val) }
|
5
5
|
| proto proto_item
|
6
|
-
{ result.children << val[1] }
|
6
|
+
{ result.children << val[1] if val[1]}
|
7
7
|
|
8
8
|
proto_item : message
|
9
9
|
| extend
|
@@ -12,14 +12,13 @@ rule
|
|
12
12
|
| package
|
13
13
|
| option
|
14
14
|
| service
|
15
|
-
| ';'
|
16
|
-
{ }
|
15
|
+
| ';' { result = nil }
|
17
16
|
|
18
17
|
import : 'import' STRING_LITERAL ';'
|
19
|
-
{ result = Protobuf::Node::ImportNode.new
|
18
|
+
{ result = Protobuf::Node::ImportNode.new(val[1]) }
|
20
19
|
|
21
20
|
package : 'package' IDENT dot_ident_list ';'
|
22
|
-
{ result = Protobuf::Node::PackageNode.new
|
21
|
+
{ result = Protobuf::Node::PackageNode.new(val[2].unshift(val[1])) }
|
23
22
|
|
24
23
|
dot_ident_list :
|
25
24
|
{ result = [] }
|
@@ -33,52 +32,49 @@ rule
|
|
33
32
|
{ result = [val[1].unshift(val[0]), val[3]] }
|
34
33
|
|
35
34
|
message : 'message' IDENT message_body
|
36
|
-
{ result = Protobuf::Node::MessageNode.new
|
35
|
+
{ result = Protobuf::Node::MessageNode.new(val[1], val[2]) }
|
37
36
|
|
38
37
|
extend : 'extend' user_type '{' extend_body_list '}'
|
39
|
-
{ result = Protobuf::Node::ExtendNode.new
|
38
|
+
{ result = Protobuf::Node::ExtendNode.new(val[1], val[3]) }
|
40
39
|
|
41
|
-
extend_body_list :
|
40
|
+
extend_body_list :
|
42
41
|
{ result = [] }
|
43
42
|
| extend_body_list extend_body
|
44
|
-
{ result << val[1] }
|
43
|
+
{ result << val[1] if val[1] }
|
45
44
|
|
46
45
|
extend_body : field
|
47
46
|
| group
|
48
|
-
| ';'
|
49
|
-
{ }
|
47
|
+
| ';' { result = nil }
|
50
48
|
|
51
49
|
enum : 'enum' IDENT '{' enum_body_list '}'
|
52
|
-
{ result = Protobuf::Node::EnumNode.new
|
50
|
+
{ result = Protobuf::Node::EnumNode.new(val[1], val[3]) }
|
53
51
|
|
54
52
|
enum_body_list :
|
55
53
|
{ result = [] }
|
56
54
|
| enum_body_list enum_body
|
57
|
-
{ result << val[1] }
|
55
|
+
{ result << val[1] if val[1] }
|
58
56
|
|
59
57
|
enum_body : option
|
60
58
|
| enum_field
|
61
|
-
| ';'
|
62
|
-
{ }
|
59
|
+
| ';' { result = nil }
|
63
60
|
|
64
61
|
enum_field : IDENT '=' integer_literal ';'
|
65
|
-
{ result = Protobuf::Node::EnumFieldNode.new
|
62
|
+
{ result = Protobuf::Node::EnumFieldNode.new(val[0], val[2]) }
|
66
63
|
|
67
64
|
service : 'service' IDENT '{' service_body_list '}'
|
68
|
-
{ result = Protobuf::Node::ServiceNode.new
|
65
|
+
{ result = Protobuf::Node::ServiceNode.new(val[1], val[3]) }
|
69
66
|
|
70
67
|
service_body_list :
|
71
68
|
{ result = [] }
|
72
69
|
| service_body_list service_body
|
73
|
-
{ result << val[1] }
|
70
|
+
{ result << val[1] if val[1] }
|
74
71
|
|
75
72
|
service_body : option
|
76
73
|
| rpc
|
77
|
-
| ';'
|
78
|
-
{ }
|
74
|
+
| ';' { result = nil}
|
79
75
|
|
80
76
|
rpc : 'rpc' IDENT '(' rpc_arg ')' 'returns' '(' rpc_arg ')' ';'
|
81
|
-
{ result = Protobuf::Node::RpcNode.new
|
77
|
+
{ result = Protobuf::Node::RpcNode.new(val[1], val[3], val[7]) }
|
82
78
|
|
83
79
|
rpc_arg :
|
84
80
|
| user_type
|
@@ -89,7 +85,7 @@ rule
|
|
89
85
|
message_body_body_list :
|
90
86
|
{ result = [] }
|
91
87
|
| message_body_body_list message_body_body
|
92
|
-
{ result << val[1] }
|
88
|
+
{ result << val[1] if val[1] }
|
93
89
|
|
94
90
|
message_body_body : field
|
95
91
|
| enum
|
@@ -98,16 +94,15 @@ rule
|
|
98
94
|
| extensions
|
99
95
|
| group
|
100
96
|
| option
|
101
|
-
| ';'
|
102
|
-
{ }
|
97
|
+
| ';' { result = nil }
|
103
98
|
|
104
|
-
group : label 'group'
|
105
|
-
{ result = Protobuf::Node::GroupNode.new
|
99
|
+
group : label 'group' IDENT '=' integer_literal message_body
|
100
|
+
{ result = Protobuf::Node::GroupNode.new(val[0], val[2], val[4], val[5]) }
|
106
101
|
|
107
102
|
field : label type field_name '=' integer_literal ';'
|
108
|
-
{ result = Protobuf::Node::FieldNode.new
|
103
|
+
{ result = Protobuf::Node::FieldNode.new(val[0], val[1], val[2], val[4]) }
|
109
104
|
| label type field_name '=' integer_literal '[' field_option_list ']' ';'
|
110
|
-
{ result = Protobuf::Node::FieldNode.new
|
105
|
+
{ result = Protobuf::Node::FieldNode.new(val[0], val[1], val[2], val[4], val[6]) }
|
111
106
|
|
112
107
|
field_name : IDENT | "required" | "optional" | "repeated" | "import" | "package" | "option" | "message" | "extend" | "enum" | "service" | "rpc" | "returns" | "group" | "default" | "extensions" | "to" | "max" | "double" | "float" | "int32" | "int64" | "uint32" | "uint64" | "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | "bytes"
|
113
108
|
|
@@ -121,19 +116,19 @@ rule
|
|
121
116
|
{ result = [:default, val[2]] }
|
122
117
|
|
123
118
|
extensions : 'extensions' extension comma_extension_list ';'
|
124
|
-
{ result = Protobuf::Node::ExtensionsNode.new
|
119
|
+
{ result = Protobuf::Node::ExtensionsNode.new(val[2].unshift(val[1])) }
|
125
120
|
|
126
|
-
comma_extension_list :
|
121
|
+
comma_extension_list :
|
127
122
|
{ result = [] }
|
128
123
|
| ',' extension
|
129
124
|
{ result << val[1] }
|
130
125
|
|
131
126
|
extension : integer_literal
|
132
|
-
{ result = Protobuf::Node::ExtensionRangeNode.new
|
127
|
+
{ result = Protobuf::Node::ExtensionRangeNode.new(val[0]) }
|
133
128
|
| integer_literal 'to' integer_literal
|
134
|
-
{ result = Protobuf::Node::ExtensionRangeNode.new
|
129
|
+
{ result = Protobuf::Node::ExtensionRangeNode.new(val[0], val[2]) }
|
135
130
|
| integer_literal 'to' 'max'
|
136
|
-
{ result = Protobuf::Node::ExtensionRangeNode.new
|
131
|
+
{ result = Protobuf::Node::ExtensionRangeNode.new(val[0], :max) }
|
137
132
|
|
138
133
|
label : 'required'
|
139
134
|
| 'optional'
|
@@ -153,7 +148,7 @@ rule
|
|
153
148
|
| FLOAT_LITERAL
|
154
149
|
| STRING_LITERAL
|
155
150
|
| BOOLEAN_LITERAL
|
156
|
-
|
151
|
+
|
157
152
|
integer_literal : DEC_INTEGER
|
158
153
|
| HEX_INTEGER
|
159
154
|
| OCT_INTEGER
|
@@ -197,10 +192,8 @@ end
|
|
197
192
|
yield [:BOOLEAN_LITERAL, @token == 'true']
|
198
193
|
when match(/"(?:[^"\\]+|\\.)*"/, /'(?:[^'\\]+|\\.)*'/)
|
199
194
|
yield [:STRING_LITERAL, eval(@token)]
|
200
|
-
when match(/[a-zA-Z_]
|
195
|
+
when match(/[a-zA-Z_]\w*/)
|
201
196
|
yield [:IDENT, @token.to_sym]
|
202
|
-
when match(/[A-Z][\w_]*/)
|
203
|
-
yield [:CAMEL_IDENT, @token.to_sym]
|
204
197
|
when match(/./)
|
205
198
|
yield [@token, @token]
|
206
199
|
else
|