macks-ruby_protobuf 0.3.2.2 → 0.3.2.3
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.
- data/lib/protobuf/compiler/proto.y +52 -34
- data/lib/protobuf/compiler/proto_parser.rb +606 -601
- data/lib/protobuf/message/field.rb +12 -10
- data/lib/protobuf/message/message.rb +18 -11
- data/lib/ruby_protobuf.rb +1 -1
- metadata +1 -1
@@ -1,5 +1,4 @@
|
|
1
1
|
class Protobuf::ProtoParser
|
2
|
-
#options no_result_var
|
3
2
|
rule
|
4
3
|
proto : proto_item
|
5
4
|
{ result = Protobuf::Node::ProtoNode.new val }
|
@@ -162,42 +161,61 @@ end
|
|
162
161
|
|
163
162
|
---- inner
|
164
163
|
|
164
|
+
require 'strscan'
|
165
|
+
|
165
166
|
def parse(f)
|
166
|
-
@
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
167
|
+
@scanner = StringScanner.new(f.read)
|
168
|
+
yyparse(self, :scan)
|
169
|
+
end
|
170
|
+
|
171
|
+
def scan_debug
|
172
|
+
scan do |token, value|
|
173
|
+
p [token, value]
|
174
|
+
yield [token, value]
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def scan
|
179
|
+
until @scanner.eos?
|
180
|
+
case
|
181
|
+
when match(/\s+/, /\/\/.*/)
|
182
|
+
# skip
|
183
|
+
when match(/\/\*/)
|
184
|
+
# C-like comment
|
185
|
+
raise 'EOF inside block comment' until @scanner.scan_until(/\*\//)
|
186
|
+
when match(/(?: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)\b/)
|
187
|
+
yield [@token, @token.to_sym]
|
188
|
+
when match(/[1-9]\d*(?!\.)/, /0(?![.xX0-9])/)
|
189
|
+
yield [:DEC_INTEGER, @token.to_i]
|
190
|
+
when match(/0[xX]([A-Fa-f0-9])+/)
|
191
|
+
yield [:HEX_INTEGER, @token.to_i(0)]
|
192
|
+
when match(/0[0-7]+/)
|
193
|
+
yield [:OCT_INTEGER, @token.to_i(0)]
|
194
|
+
when match(/\d+(\.\d+)?([Ee][\+-]?\d+)?/)
|
195
|
+
yield [:FLOAT_LITERAL, @token.to_f]
|
196
|
+
when match(/(true|false)\b/)
|
197
|
+
yield [:BOOLEAN_LITERAL, @token == 'true']
|
198
|
+
when match(/"(?:[^"\\]+|\\.)*"/, /'(?:[^'\\]+|\\.)*'/)
|
199
|
+
yield [:STRING_LITERAL, eval(@token)]
|
200
|
+
when match(/[a-zA-Z_][\w_]*/)
|
201
|
+
yield [:IDENT, @token.to_sym]
|
202
|
+
when match(/[A-Z][\w_]*/)
|
203
|
+
yield [:CAMEL_IDENT, @token.to_sym]
|
204
|
+
when match(/./)
|
205
|
+
yield [@token, @token]
|
206
|
+
else
|
207
|
+
raise "parse error around #{@scanner.string[@scanner.pos, 32].inspect}"
|
196
208
|
end
|
197
209
|
end
|
198
|
-
|
210
|
+
yield [false, nil]
|
199
211
|
end
|
200
212
|
|
201
|
-
def
|
202
|
-
|
213
|
+
def match(*regular_expressions)
|
214
|
+
regular_expressions.each do |re|
|
215
|
+
if @scanner.scan(re)
|
216
|
+
@token = @scanner[0]
|
217
|
+
return true
|
218
|
+
end
|
219
|
+
end
|
220
|
+
false
|
203
221
|
end
|