cbor-diag 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/bin/cbor2diag.rb +7 -0
- data/bin/cbor2json.rb +8 -0
- data/bin/cbor2pretty.rb +7 -0
- data/bin/cbor2yaml.rb +15 -0
- data/bin/diag2cbor.rb +20 -0
- data/bin/diag2pretty.rb +15 -0
- data/bin/json2cbor.rb +14 -0
- data/bin/json2pretty.rb +8 -0
- data/cbor-diag.gemspec +22 -0
- data/lib/cbor-diag-parser.rb +2127 -0
- data/lib/cbor-diagnostic.rb +74 -0
- data/lib/cbor-pretty.rb +88 -0
- data/lib/cbor-pure.rb +260 -0
- data/lib/half.rb +111 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d8b59a16fdc02930ae1aaaa5a00c3c2ac17b586a
|
4
|
+
data.tar.gz: d7c8dce2feb9d8a96b1499a9cac1e0ec8d81f6b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e38effbdce753d758d129faa22e849ee87bd9c01cf57c049d241b52d78fff7b26fcf30991309c76c9442284024528052ccc867ad360f72e3635d15a807822ed7
|
7
|
+
data.tar.gz: 1f2e45b854a2f20d10ad2d5b4e6e072c359ec642fd06a5cae62733801c97c4893c5c731149dd1b50b7f96790ab4508e45f59e4dbba38fb2ffdd88eaa0b58dd39
|
data/bin/cbor2diag.rb
ADDED
data/bin/cbor2json.rb
ADDED
data/bin/cbor2pretty.rb
ADDED
data/bin/cbor2yaml.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'psych.rb' # WTF
|
3
|
+
require 'yaml'
|
4
|
+
require 'cbor-pure'
|
5
|
+
|
6
|
+
class Array
|
7
|
+
def to_yaml_style()
|
8
|
+
all? {|x| Integer === x } && length < 20 ? :inline : super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ARGF.binmode
|
13
|
+
i = ARGF.read
|
14
|
+
o = CBOR.decode(i)
|
15
|
+
puts YAML.dump(o)
|
data/bin/diag2cbor.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'cbor-pure'
|
3
|
+
require 'treetop'
|
4
|
+
require 'cbor-diag-parser'
|
5
|
+
unless ''.respond_to? :b
|
6
|
+
require 'cbor-diagnostic' # for .b
|
7
|
+
end
|
8
|
+
require 'cbor-pretty'
|
9
|
+
|
10
|
+
parser = CBOR_DIAGParser.new
|
11
|
+
|
12
|
+
$stdout.binmode
|
13
|
+
|
14
|
+
i = ARGF.read
|
15
|
+
if result = parser.parse(i)
|
16
|
+
print(CBOR::encode(result.to_rb))
|
17
|
+
else
|
18
|
+
puts "*** can't parse #{i}"
|
19
|
+
puts "*** #{parser.failure_reason}"
|
20
|
+
end
|
data/bin/diag2pretty.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'cbor-pure'
|
3
|
+
require 'treetop'
|
4
|
+
require 'cbor-diag-parser'
|
5
|
+
require 'cbor-pretty'
|
6
|
+
|
7
|
+
parser = CBOR_DIAGParser.new
|
8
|
+
|
9
|
+
i = ARGF.read
|
10
|
+
if result = parser.parse(i)
|
11
|
+
puts(CBOR::pretty(CBOR::encode(result.to_rb)))
|
12
|
+
else
|
13
|
+
puts "*** can't parse #{i}"
|
14
|
+
puts "*** #{parser.failure_reason}"
|
15
|
+
end
|
data/bin/json2cbor.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'json'
|
3
|
+
require 'cbor-pure'
|
4
|
+
|
5
|
+
if ARGV[0] == "-v"
|
6
|
+
verbose = true
|
7
|
+
ARGV.shift
|
8
|
+
end
|
9
|
+
|
10
|
+
$stdout.binmode
|
11
|
+
i = ARGF.read
|
12
|
+
o = CBOR.encode(JSON.load(i))
|
13
|
+
print o
|
14
|
+
warn "JSON size: #{i.size} bytes, CBOR size: #{o.size} bytes." if verbose
|
data/bin/json2pretty.rb
ADDED
data/cbor-diag.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "cbor-diag"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.summary = "CBOR (Concise Binary Object Representation) diagnostic notation"
|
5
|
+
s.description = %q{cbor-diag implements diagnostic notation for CBOR, RFC 7049}
|
6
|
+
s.author = "Carsten Bormann"
|
7
|
+
s.email = "cabo@tzi.org"
|
8
|
+
s.license = "Apache 2.0"
|
9
|
+
s.homepage = "http://cbor.io/"
|
10
|
+
s.has_rdoc = false
|
11
|
+
# s.files = `git ls-files`.split("\n") << "lib/cbor-diag-parser.rb"
|
12
|
+
# s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
13
|
+
s.files = Dir['lib/**/*.rb'] + %w(cbor-diag.gemspec) + Dir['bin/**/*.rb']
|
14
|
+
s.executables = Dir['bin/**/*.rb'].map {|x| File.basename(x)}
|
15
|
+
s.required_ruby_version = '>= 1.9.2'
|
16
|
+
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_development_dependency 'bundler', '~>1'
|
20
|
+
s.add_dependency 'treetop', '~>1'
|
21
|
+
s.add_dependency 'json', '~>1'
|
22
|
+
end
|
@@ -0,0 +1,2127 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module CBOR_DIAG
|
5
|
+
include Treetop::Runtime
|
6
|
+
|
7
|
+
def root
|
8
|
+
@root ||= :text
|
9
|
+
end
|
10
|
+
|
11
|
+
module Text0
|
12
|
+
def ows1
|
13
|
+
elements[0]
|
14
|
+
end
|
15
|
+
|
16
|
+
def value
|
17
|
+
elements[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def ows2
|
21
|
+
elements[2]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Text1
|
26
|
+
def to_rb; value.to_rb end
|
27
|
+
end
|
28
|
+
|
29
|
+
def _nt_text
|
30
|
+
start_index = index
|
31
|
+
if node_cache[:text].has_key?(index)
|
32
|
+
cached = node_cache[:text][index]
|
33
|
+
if cached
|
34
|
+
node_cache[:text][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
35
|
+
@index = cached.interval.end
|
36
|
+
end
|
37
|
+
return cached
|
38
|
+
end
|
39
|
+
|
40
|
+
i0, s0 = index, []
|
41
|
+
r1 = _nt_ows
|
42
|
+
s0 << r1
|
43
|
+
if r1
|
44
|
+
r2 = _nt_value
|
45
|
+
s0 << r2
|
46
|
+
if r2
|
47
|
+
r3 = _nt_ows
|
48
|
+
s0 << r3
|
49
|
+
end
|
50
|
+
end
|
51
|
+
if s0.last
|
52
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
53
|
+
r0.extend(Text0)
|
54
|
+
r0.extend(Text1)
|
55
|
+
else
|
56
|
+
@index = i0
|
57
|
+
r0 = nil
|
58
|
+
end
|
59
|
+
|
60
|
+
node_cache[:text][start_index] = r0
|
61
|
+
|
62
|
+
r0
|
63
|
+
end
|
64
|
+
|
65
|
+
def _nt_value
|
66
|
+
start_index = index
|
67
|
+
if node_cache[:value].has_key?(index)
|
68
|
+
cached = node_cache[:value][index]
|
69
|
+
if cached
|
70
|
+
node_cache[:value][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
71
|
+
@index = cached.interval.end
|
72
|
+
end
|
73
|
+
return cached
|
74
|
+
end
|
75
|
+
|
76
|
+
i0 = index
|
77
|
+
r1 = _nt_tagged
|
78
|
+
if r1
|
79
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
80
|
+
r0 = r1
|
81
|
+
else
|
82
|
+
r2 = _nt_fnumber
|
83
|
+
if r2
|
84
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
85
|
+
r0 = r2
|
86
|
+
else
|
87
|
+
r3 = _nt_infin
|
88
|
+
if r3
|
89
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
90
|
+
r0 = r3
|
91
|
+
else
|
92
|
+
r4 = _nt_simple
|
93
|
+
if r4
|
94
|
+
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
95
|
+
r0 = r4
|
96
|
+
else
|
97
|
+
r5 = _nt_string
|
98
|
+
if r5
|
99
|
+
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
100
|
+
r0 = r5
|
101
|
+
else
|
102
|
+
r6 = _nt_hstring
|
103
|
+
if r6
|
104
|
+
r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
|
105
|
+
r0 = r6
|
106
|
+
else
|
107
|
+
r7 = _nt_array
|
108
|
+
if r7
|
109
|
+
r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
|
110
|
+
r0 = r7
|
111
|
+
else
|
112
|
+
r8 = _nt_map
|
113
|
+
if r8
|
114
|
+
r8 = SyntaxNode.new(input, (index-1)...index) if r8 == true
|
115
|
+
r0 = r8
|
116
|
+
else
|
117
|
+
r9 = _nt_streamstring
|
118
|
+
if r9
|
119
|
+
r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
|
120
|
+
r0 = r9
|
121
|
+
else
|
122
|
+
@index = i0
|
123
|
+
r0 = nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
node_cache[:value][start_index] = r0
|
135
|
+
|
136
|
+
r0
|
137
|
+
end
|
138
|
+
|
139
|
+
module Fnumber0
|
140
|
+
end
|
141
|
+
|
142
|
+
module Fnumber1
|
143
|
+
end
|
144
|
+
|
145
|
+
module Fnumber2
|
146
|
+
end
|
147
|
+
|
148
|
+
module Fnumber3
|
149
|
+
def ip
|
150
|
+
elements[0]
|
151
|
+
end
|
152
|
+
|
153
|
+
def dp
|
154
|
+
elements[1]
|
155
|
+
end
|
156
|
+
|
157
|
+
def ep
|
158
|
+
elements[2]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
module Fnumber4
|
163
|
+
def to_rb
|
164
|
+
if dp.empty? && ep.empty?
|
165
|
+
ip.text_value.to_i
|
166
|
+
else
|
167
|
+
(ip.text_value + dp.text_value + ep.text_value).to_f
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def _nt_fnumber
|
173
|
+
start_index = index
|
174
|
+
if node_cache[:fnumber].has_key?(index)
|
175
|
+
cached = node_cache[:fnumber][index]
|
176
|
+
if cached
|
177
|
+
node_cache[:fnumber][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
178
|
+
@index = cached.interval.end
|
179
|
+
end
|
180
|
+
return cached
|
181
|
+
end
|
182
|
+
|
183
|
+
i0, s0 = index, []
|
184
|
+
i1, s1 = index, []
|
185
|
+
if has_terminal?(@regexps[gr = '\A[-+]'] ||= Regexp.new(gr), :regexp, index)
|
186
|
+
r3 = true
|
187
|
+
@index += 1
|
188
|
+
else
|
189
|
+
terminal_parse_failure('[-+]')
|
190
|
+
r3 = nil
|
191
|
+
end
|
192
|
+
if r3
|
193
|
+
r2 = r3
|
194
|
+
else
|
195
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
196
|
+
end
|
197
|
+
s1 << r2
|
198
|
+
if r2
|
199
|
+
s4, i4 = [], index
|
200
|
+
loop do
|
201
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
202
|
+
r5 = true
|
203
|
+
@index += 1
|
204
|
+
else
|
205
|
+
terminal_parse_failure('[0-9]')
|
206
|
+
r5 = nil
|
207
|
+
end
|
208
|
+
if r5
|
209
|
+
s4 << r5
|
210
|
+
else
|
211
|
+
break
|
212
|
+
end
|
213
|
+
end
|
214
|
+
if s4.empty?
|
215
|
+
@index = i4
|
216
|
+
r4 = nil
|
217
|
+
else
|
218
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
219
|
+
end
|
220
|
+
s1 << r4
|
221
|
+
end
|
222
|
+
if s1.last
|
223
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
224
|
+
r1.extend(Fnumber0)
|
225
|
+
else
|
226
|
+
@index = i1
|
227
|
+
r1 = nil
|
228
|
+
end
|
229
|
+
s0 << r1
|
230
|
+
if r1
|
231
|
+
i7, s7 = index, []
|
232
|
+
if (match_len = has_terminal?('.', false, index))
|
233
|
+
r8 = true
|
234
|
+
@index += match_len
|
235
|
+
else
|
236
|
+
terminal_parse_failure('.')
|
237
|
+
r8 = nil
|
238
|
+
end
|
239
|
+
s7 << r8
|
240
|
+
if r8
|
241
|
+
s9, i9 = [], index
|
242
|
+
loop do
|
243
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
244
|
+
r10 = true
|
245
|
+
@index += 1
|
246
|
+
else
|
247
|
+
terminal_parse_failure('[0-9]')
|
248
|
+
r10 = nil
|
249
|
+
end
|
250
|
+
if r10
|
251
|
+
s9 << r10
|
252
|
+
else
|
253
|
+
break
|
254
|
+
end
|
255
|
+
end
|
256
|
+
if s9.empty?
|
257
|
+
@index = i9
|
258
|
+
r9 = nil
|
259
|
+
else
|
260
|
+
r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
|
261
|
+
end
|
262
|
+
s7 << r9
|
263
|
+
end
|
264
|
+
if s7.last
|
265
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
266
|
+
r7.extend(Fnumber1)
|
267
|
+
else
|
268
|
+
@index = i7
|
269
|
+
r7 = nil
|
270
|
+
end
|
271
|
+
if r7
|
272
|
+
r6 = r7
|
273
|
+
else
|
274
|
+
r6 = instantiate_node(SyntaxNode,input, index...index)
|
275
|
+
end
|
276
|
+
s0 << r6
|
277
|
+
if r6
|
278
|
+
i12, s12 = index, []
|
279
|
+
if has_terminal?(@regexps[gr = '\A[Ee]'] ||= Regexp.new(gr), :regexp, index)
|
280
|
+
r13 = true
|
281
|
+
@index += 1
|
282
|
+
else
|
283
|
+
terminal_parse_failure('[Ee]')
|
284
|
+
r13 = nil
|
285
|
+
end
|
286
|
+
s12 << r13
|
287
|
+
if r13
|
288
|
+
if has_terminal?(@regexps[gr = '\A[-+]'] ||= Regexp.new(gr), :regexp, index)
|
289
|
+
r15 = true
|
290
|
+
@index += 1
|
291
|
+
else
|
292
|
+
terminal_parse_failure('[-+]')
|
293
|
+
r15 = nil
|
294
|
+
end
|
295
|
+
if r15
|
296
|
+
r14 = r15
|
297
|
+
else
|
298
|
+
r14 = instantiate_node(SyntaxNode,input, index...index)
|
299
|
+
end
|
300
|
+
s12 << r14
|
301
|
+
if r14
|
302
|
+
s16, i16 = [], index
|
303
|
+
loop do
|
304
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
305
|
+
r17 = true
|
306
|
+
@index += 1
|
307
|
+
else
|
308
|
+
terminal_parse_failure('[0-9]')
|
309
|
+
r17 = nil
|
310
|
+
end
|
311
|
+
if r17
|
312
|
+
s16 << r17
|
313
|
+
else
|
314
|
+
break
|
315
|
+
end
|
316
|
+
end
|
317
|
+
if s16.empty?
|
318
|
+
@index = i16
|
319
|
+
r16 = nil
|
320
|
+
else
|
321
|
+
r16 = instantiate_node(SyntaxNode,input, i16...index, s16)
|
322
|
+
end
|
323
|
+
s12 << r16
|
324
|
+
end
|
325
|
+
end
|
326
|
+
if s12.last
|
327
|
+
r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
|
328
|
+
r12.extend(Fnumber2)
|
329
|
+
else
|
330
|
+
@index = i12
|
331
|
+
r12 = nil
|
332
|
+
end
|
333
|
+
if r12
|
334
|
+
r11 = r12
|
335
|
+
else
|
336
|
+
r11 = instantiate_node(SyntaxNode,input, index...index)
|
337
|
+
end
|
338
|
+
s0 << r11
|
339
|
+
end
|
340
|
+
end
|
341
|
+
if s0.last
|
342
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
343
|
+
r0.extend(Fnumber3)
|
344
|
+
r0.extend(Fnumber4)
|
345
|
+
else
|
346
|
+
@index = i0
|
347
|
+
r0 = nil
|
348
|
+
end
|
349
|
+
|
350
|
+
node_cache[:fnumber][start_index] = r0
|
351
|
+
|
352
|
+
r0
|
353
|
+
end
|
354
|
+
|
355
|
+
module Infin0
|
356
|
+
def to_rb; Float::INFINITY end
|
357
|
+
end
|
358
|
+
|
359
|
+
module Infin1
|
360
|
+
def to_rb; -Float::INFINITY end
|
361
|
+
end
|
362
|
+
|
363
|
+
module Infin2
|
364
|
+
def to_rb; Float::NAN end
|
365
|
+
end
|
366
|
+
|
367
|
+
def _nt_infin
|
368
|
+
start_index = index
|
369
|
+
if node_cache[:infin].has_key?(index)
|
370
|
+
cached = node_cache[:infin][index]
|
371
|
+
if cached
|
372
|
+
node_cache[:infin][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
373
|
+
@index = cached.interval.end
|
374
|
+
end
|
375
|
+
return cached
|
376
|
+
end
|
377
|
+
|
378
|
+
i0 = index
|
379
|
+
if (match_len = has_terminal?('Infinity', false, index))
|
380
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
381
|
+
r1.extend(Infin0)
|
382
|
+
@index += match_len
|
383
|
+
else
|
384
|
+
terminal_parse_failure('Infinity')
|
385
|
+
r1 = nil
|
386
|
+
end
|
387
|
+
if r1
|
388
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
389
|
+
r0 = r1
|
390
|
+
else
|
391
|
+
if (match_len = has_terminal?('-Infinity', false, index))
|
392
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
393
|
+
r2.extend(Infin1)
|
394
|
+
@index += match_len
|
395
|
+
else
|
396
|
+
terminal_parse_failure('-Infinity')
|
397
|
+
r2 = nil
|
398
|
+
end
|
399
|
+
if r2
|
400
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
401
|
+
r0 = r2
|
402
|
+
else
|
403
|
+
if (match_len = has_terminal?('NaN', false, index))
|
404
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
405
|
+
r3.extend(Infin2)
|
406
|
+
@index += match_len
|
407
|
+
else
|
408
|
+
terminal_parse_failure('NaN')
|
409
|
+
r3 = nil
|
410
|
+
end
|
411
|
+
if r3
|
412
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
413
|
+
r0 = r3
|
414
|
+
else
|
415
|
+
@index = i0
|
416
|
+
r0 = nil
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
node_cache[:infin][start_index] = r0
|
422
|
+
|
423
|
+
r0
|
424
|
+
end
|
425
|
+
|
426
|
+
module Simple0
|
427
|
+
def to_rb; false end
|
428
|
+
end
|
429
|
+
|
430
|
+
module Simple1
|
431
|
+
def to_rb; true end
|
432
|
+
end
|
433
|
+
|
434
|
+
module Simple2
|
435
|
+
def to_rb; nil end
|
436
|
+
end
|
437
|
+
|
438
|
+
module Simple3
|
439
|
+
def to_rb; CBOR::Simple.new(23) end
|
440
|
+
end
|
441
|
+
|
442
|
+
module Simple4
|
443
|
+
def ows1
|
444
|
+
elements[1]
|
445
|
+
end
|
446
|
+
|
447
|
+
def value
|
448
|
+
elements[2]
|
449
|
+
end
|
450
|
+
|
451
|
+
def ows2
|
452
|
+
elements[3]
|
453
|
+
end
|
454
|
+
|
455
|
+
end
|
456
|
+
|
457
|
+
module Simple5
|
458
|
+
def to_rb; CBOR::Simple.new(value.to_rb) end
|
459
|
+
end
|
460
|
+
|
461
|
+
def _nt_simple
|
462
|
+
start_index = index
|
463
|
+
if node_cache[:simple].has_key?(index)
|
464
|
+
cached = node_cache[:simple][index]
|
465
|
+
if cached
|
466
|
+
node_cache[:simple][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
467
|
+
@index = cached.interval.end
|
468
|
+
end
|
469
|
+
return cached
|
470
|
+
end
|
471
|
+
|
472
|
+
i0 = index
|
473
|
+
if (match_len = has_terminal?('false', false, index))
|
474
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
475
|
+
r1.extend(Simple0)
|
476
|
+
@index += match_len
|
477
|
+
else
|
478
|
+
terminal_parse_failure('false')
|
479
|
+
r1 = nil
|
480
|
+
end
|
481
|
+
if r1
|
482
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
483
|
+
r0 = r1
|
484
|
+
else
|
485
|
+
if (match_len = has_terminal?('true', false, index))
|
486
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
487
|
+
r2.extend(Simple1)
|
488
|
+
@index += match_len
|
489
|
+
else
|
490
|
+
terminal_parse_failure('true')
|
491
|
+
r2 = nil
|
492
|
+
end
|
493
|
+
if r2
|
494
|
+
r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
|
495
|
+
r0 = r2
|
496
|
+
else
|
497
|
+
if (match_len = has_terminal?('null', false, index))
|
498
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
499
|
+
r3.extend(Simple2)
|
500
|
+
@index += match_len
|
501
|
+
else
|
502
|
+
terminal_parse_failure('null')
|
503
|
+
r3 = nil
|
504
|
+
end
|
505
|
+
if r3
|
506
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
507
|
+
r0 = r3
|
508
|
+
else
|
509
|
+
if (match_len = has_terminal?('undefined', false, index))
|
510
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
511
|
+
r4.extend(Simple3)
|
512
|
+
@index += match_len
|
513
|
+
else
|
514
|
+
terminal_parse_failure('undefined')
|
515
|
+
r4 = nil
|
516
|
+
end
|
517
|
+
if r4
|
518
|
+
r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
|
519
|
+
r0 = r4
|
520
|
+
else
|
521
|
+
i5, s5 = index, []
|
522
|
+
if (match_len = has_terminal?('simple(', false, index))
|
523
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
524
|
+
@index += match_len
|
525
|
+
else
|
526
|
+
terminal_parse_failure('simple(')
|
527
|
+
r6 = nil
|
528
|
+
end
|
529
|
+
s5 << r6
|
530
|
+
if r6
|
531
|
+
r7 = _nt_ows
|
532
|
+
s5 << r7
|
533
|
+
if r7
|
534
|
+
r8 = _nt_value
|
535
|
+
s5 << r8
|
536
|
+
if r8
|
537
|
+
r9 = _nt_ows
|
538
|
+
s5 << r9
|
539
|
+
if r9
|
540
|
+
if (match_len = has_terminal?(')', false, index))
|
541
|
+
r10 = true
|
542
|
+
@index += match_len
|
543
|
+
else
|
544
|
+
terminal_parse_failure(')')
|
545
|
+
r10 = nil
|
546
|
+
end
|
547
|
+
s5 << r10
|
548
|
+
end
|
549
|
+
end
|
550
|
+
end
|
551
|
+
end
|
552
|
+
if s5.last
|
553
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
554
|
+
r5.extend(Simple4)
|
555
|
+
r5.extend(Simple5)
|
556
|
+
else
|
557
|
+
@index = i5
|
558
|
+
r5 = nil
|
559
|
+
end
|
560
|
+
if r5
|
561
|
+
r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
|
562
|
+
r0 = r5
|
563
|
+
else
|
564
|
+
@index = i0
|
565
|
+
r0 = nil
|
566
|
+
end
|
567
|
+
end
|
568
|
+
end
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
node_cache[:simple][start_index] = r0
|
573
|
+
|
574
|
+
r0
|
575
|
+
end
|
576
|
+
|
577
|
+
module Tagged0
|
578
|
+
def tag
|
579
|
+
elements[0]
|
580
|
+
end
|
581
|
+
|
582
|
+
def ows1
|
583
|
+
elements[2]
|
584
|
+
end
|
585
|
+
|
586
|
+
def value
|
587
|
+
elements[3]
|
588
|
+
end
|
589
|
+
|
590
|
+
def ows2
|
591
|
+
elements[4]
|
592
|
+
end
|
593
|
+
|
594
|
+
end
|
595
|
+
|
596
|
+
module Tagged1
|
597
|
+
def to_rb
|
598
|
+
CBOR::Tagged.new(tag.text_value.to_i, value.to_rb)
|
599
|
+
end
|
600
|
+
end
|
601
|
+
|
602
|
+
def _nt_tagged
|
603
|
+
start_index = index
|
604
|
+
if node_cache[:tagged].has_key?(index)
|
605
|
+
cached = node_cache[:tagged][index]
|
606
|
+
if cached
|
607
|
+
node_cache[:tagged][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
608
|
+
@index = cached.interval.end
|
609
|
+
end
|
610
|
+
return cached
|
611
|
+
end
|
612
|
+
|
613
|
+
i0, s0 = index, []
|
614
|
+
s1, i1 = [], index
|
615
|
+
loop do
|
616
|
+
if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
|
617
|
+
r2 = true
|
618
|
+
@index += 1
|
619
|
+
else
|
620
|
+
terminal_parse_failure('[0-9]')
|
621
|
+
r2 = nil
|
622
|
+
end
|
623
|
+
if r2
|
624
|
+
s1 << r2
|
625
|
+
else
|
626
|
+
break
|
627
|
+
end
|
628
|
+
end
|
629
|
+
if s1.empty?
|
630
|
+
@index = i1
|
631
|
+
r1 = nil
|
632
|
+
else
|
633
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
634
|
+
end
|
635
|
+
s0 << r1
|
636
|
+
if r1
|
637
|
+
if (match_len = has_terminal?('(', false, index))
|
638
|
+
r3 = true
|
639
|
+
@index += match_len
|
640
|
+
else
|
641
|
+
terminal_parse_failure('(')
|
642
|
+
r3 = nil
|
643
|
+
end
|
644
|
+
s0 << r3
|
645
|
+
if r3
|
646
|
+
r4 = _nt_ows
|
647
|
+
s0 << r4
|
648
|
+
if r4
|
649
|
+
r5 = _nt_value
|
650
|
+
s0 << r5
|
651
|
+
if r5
|
652
|
+
r6 = _nt_ows
|
653
|
+
s0 << r6
|
654
|
+
if r6
|
655
|
+
if (match_len = has_terminal?(')', false, index))
|
656
|
+
r7 = true
|
657
|
+
@index += match_len
|
658
|
+
else
|
659
|
+
terminal_parse_failure(')')
|
660
|
+
r7 = nil
|
661
|
+
end
|
662
|
+
s0 << r7
|
663
|
+
end
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|
667
|
+
end
|
668
|
+
if s0.last
|
669
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
670
|
+
r0.extend(Tagged0)
|
671
|
+
r0.extend(Tagged1)
|
672
|
+
else
|
673
|
+
@index = i0
|
674
|
+
r0 = nil
|
675
|
+
end
|
676
|
+
|
677
|
+
node_cache[:tagged][start_index] = r0
|
678
|
+
|
679
|
+
r0
|
680
|
+
end
|
681
|
+
|
682
|
+
module String0
|
683
|
+
def s
|
684
|
+
elements[1]
|
685
|
+
end
|
686
|
+
|
687
|
+
end
|
688
|
+
|
689
|
+
module String1
|
690
|
+
#'
|
691
|
+
def to_rb
|
692
|
+
s.elements.map(&:partval).join
|
693
|
+
end
|
694
|
+
end
|
695
|
+
|
696
|
+
def _nt_string
|
697
|
+
start_index = index
|
698
|
+
if node_cache[:string].has_key?(index)
|
699
|
+
cached = node_cache[:string][index]
|
700
|
+
if cached
|
701
|
+
node_cache[:string][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
702
|
+
@index = cached.interval.end
|
703
|
+
end
|
704
|
+
return cached
|
705
|
+
end
|
706
|
+
|
707
|
+
i0, s0 = index, []
|
708
|
+
if (match_len = has_terminal?('"', false, index))
|
709
|
+
r1 = true
|
710
|
+
@index += match_len
|
711
|
+
else
|
712
|
+
terminal_parse_failure('"')
|
713
|
+
r1 = nil
|
714
|
+
end
|
715
|
+
s0 << r1
|
716
|
+
if r1
|
717
|
+
s2, i2 = [], index
|
718
|
+
loop do
|
719
|
+
r3 = _nt_string_part
|
720
|
+
if r3
|
721
|
+
s2 << r3
|
722
|
+
else
|
723
|
+
break
|
724
|
+
end
|
725
|
+
end
|
726
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
727
|
+
s0 << r2
|
728
|
+
if r2
|
729
|
+
if (match_len = has_terminal?('"', false, index))
|
730
|
+
r4 = true
|
731
|
+
@index += match_len
|
732
|
+
else
|
733
|
+
terminal_parse_failure('"')
|
734
|
+
r4 = nil
|
735
|
+
end
|
736
|
+
s0 << r4
|
737
|
+
end
|
738
|
+
end
|
739
|
+
if s0.last
|
740
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
741
|
+
r0.extend(String0)
|
742
|
+
r0.extend(String1)
|
743
|
+
else
|
744
|
+
@index = i0
|
745
|
+
r0 = nil
|
746
|
+
end
|
747
|
+
|
748
|
+
node_cache[:string][start_index] = r0
|
749
|
+
|
750
|
+
r0
|
751
|
+
end
|
752
|
+
|
753
|
+
module StringPart0
|
754
|
+
def partval; text_value end
|
755
|
+
end
|
756
|
+
|
757
|
+
module StringPart1
|
758
|
+
def s
|
759
|
+
elements[1]
|
760
|
+
end
|
761
|
+
end
|
762
|
+
|
763
|
+
module StringPart2
|
764
|
+
#"
|
765
|
+
def partval
|
766
|
+
v = s.text_value
|
767
|
+
{"b" => "\b", "f" => "\f", "n" => "\n", "r" => "\r", "t" => "\t"}[v] || v
|
768
|
+
end
|
769
|
+
end
|
770
|
+
|
771
|
+
module StringPart3
|
772
|
+
end
|
773
|
+
|
774
|
+
module StringPart4
|
775
|
+
end
|
776
|
+
|
777
|
+
module StringPart5
|
778
|
+
def s
|
779
|
+
elements[1]
|
780
|
+
end
|
781
|
+
|
782
|
+
def t
|
783
|
+
elements[3]
|
784
|
+
end
|
785
|
+
end
|
786
|
+
|
787
|
+
module StringPart6
|
788
|
+
def partval; (((s.text_value.to_i(16) & 0x3FF) << 10) +
|
789
|
+
(t.text_value.to_i(16) & 0x3FF) + 0x10000).chr(Encoding::UTF_8) end
|
790
|
+
end
|
791
|
+
|
792
|
+
module StringPart7
|
793
|
+
end
|
794
|
+
|
795
|
+
module StringPart8
|
796
|
+
end
|
797
|
+
|
798
|
+
module StringPart9
|
799
|
+
def s
|
800
|
+
elements[1]
|
801
|
+
end
|
802
|
+
end
|
803
|
+
|
804
|
+
module StringPart10
|
805
|
+
def partval; s.text_value.to_i(16).chr(Encoding::UTF_8) end
|
806
|
+
end
|
807
|
+
|
808
|
+
def _nt_string_part
|
809
|
+
start_index = index
|
810
|
+
if node_cache[:string_part].has_key?(index)
|
811
|
+
cached = node_cache[:string_part][index]
|
812
|
+
if cached
|
813
|
+
node_cache[:string_part][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
814
|
+
@index = cached.interval.end
|
815
|
+
end
|
816
|
+
return cached
|
817
|
+
end
|
818
|
+
|
819
|
+
i0 = index
|
820
|
+
s1, i1 = [], index
|
821
|
+
loop do
|
822
|
+
if has_terminal?(@regexps[gr = '\A[^\\\\"]'] ||= Regexp.new(gr), :regexp, index)
|
823
|
+
r2 = true
|
824
|
+
@index += 1
|
825
|
+
else
|
826
|
+
terminal_parse_failure('[^\\\\"]')
|
827
|
+
r2 = nil
|
828
|
+
end
|
829
|
+
if r2
|
830
|
+
s1 << r2
|
831
|
+
else
|
832
|
+
break
|
833
|
+
end
|
834
|
+
end
|
835
|
+
if s1.empty?
|
836
|
+
@index = i1
|
837
|
+
r1 = nil
|
838
|
+
else
|
839
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
840
|
+
r1.extend(StringPart0)
|
841
|
+
end
|
842
|
+
if r1
|
843
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
844
|
+
r0 = r1
|
845
|
+
else
|
846
|
+
i3, s3 = index, []
|
847
|
+
if (match_len = has_terminal?("\\", false, index))
|
848
|
+
r4 = true
|
849
|
+
@index += match_len
|
850
|
+
else
|
851
|
+
terminal_parse_failure("\\")
|
852
|
+
r4 = nil
|
853
|
+
end
|
854
|
+
s3 << r4
|
855
|
+
if r4
|
856
|
+
if has_terminal?(@regexps[gr = '\A["\\\\/bfnrt]'] ||= Regexp.new(gr), :regexp, index)
|
857
|
+
r5 = true
|
858
|
+
@index += 1
|
859
|
+
else
|
860
|
+
terminal_parse_failure('["\\\\/bfnrt]')
|
861
|
+
r5 = nil
|
862
|
+
end
|
863
|
+
s3 << r5
|
864
|
+
end
|
865
|
+
if s3.last
|
866
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
867
|
+
r3.extend(StringPart1)
|
868
|
+
r3.extend(StringPart2)
|
869
|
+
else
|
870
|
+
@index = i3
|
871
|
+
r3 = nil
|
872
|
+
end
|
873
|
+
if r3
|
874
|
+
r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
|
875
|
+
r0 = r3
|
876
|
+
else
|
877
|
+
i6, s6 = index, []
|
878
|
+
if (match_len = has_terminal?("\\u", false, index))
|
879
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
880
|
+
@index += match_len
|
881
|
+
else
|
882
|
+
terminal_parse_failure("\\u")
|
883
|
+
r7 = nil
|
884
|
+
end
|
885
|
+
s6 << r7
|
886
|
+
if r7
|
887
|
+
i8, s8 = index, []
|
888
|
+
if has_terminal?(@regexps[gr = '\A[dD]'] ||= Regexp.new(gr), :regexp, index)
|
889
|
+
r9 = true
|
890
|
+
@index += 1
|
891
|
+
else
|
892
|
+
terminal_parse_failure('[dD]')
|
893
|
+
r9 = nil
|
894
|
+
end
|
895
|
+
s8 << r9
|
896
|
+
if r9
|
897
|
+
if has_terminal?(@regexps[gr = '\A[89abAB]'] ||= Regexp.new(gr), :regexp, index)
|
898
|
+
r10 = true
|
899
|
+
@index += 1
|
900
|
+
else
|
901
|
+
terminal_parse_failure('[89abAB]')
|
902
|
+
r10 = nil
|
903
|
+
end
|
904
|
+
s8 << r10
|
905
|
+
if r10
|
906
|
+
s11, i11 = [], index
|
907
|
+
loop do
|
908
|
+
if has_terminal?(@regexps[gr = '\A[0-9a-fA-F]'] ||= Regexp.new(gr), :regexp, index)
|
909
|
+
r12 = true
|
910
|
+
@index += 1
|
911
|
+
else
|
912
|
+
terminal_parse_failure('[0-9a-fA-F]')
|
913
|
+
r12 = nil
|
914
|
+
end
|
915
|
+
if r12
|
916
|
+
s11 << r12
|
917
|
+
else
|
918
|
+
break
|
919
|
+
end
|
920
|
+
if s11.size == 2
|
921
|
+
break
|
922
|
+
end
|
923
|
+
end
|
924
|
+
if s11.size < 2
|
925
|
+
@index = i11
|
926
|
+
r11 = nil
|
927
|
+
else
|
928
|
+
r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
|
929
|
+
end
|
930
|
+
s8 << r11
|
931
|
+
end
|
932
|
+
end
|
933
|
+
if s8.last
|
934
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
935
|
+
r8.extend(StringPart3)
|
936
|
+
else
|
937
|
+
@index = i8
|
938
|
+
r8 = nil
|
939
|
+
end
|
940
|
+
s6 << r8
|
941
|
+
if r8
|
942
|
+
if (match_len = has_terminal?("\\u", false, index))
|
943
|
+
r13 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
944
|
+
@index += match_len
|
945
|
+
else
|
946
|
+
terminal_parse_failure("\\u")
|
947
|
+
r13 = nil
|
948
|
+
end
|
949
|
+
s6 << r13
|
950
|
+
if r13
|
951
|
+
i14, s14 = index, []
|
952
|
+
if has_terminal?(@regexps[gr = '\A[dD]'] ||= Regexp.new(gr), :regexp, index)
|
953
|
+
r15 = true
|
954
|
+
@index += 1
|
955
|
+
else
|
956
|
+
terminal_parse_failure('[dD]')
|
957
|
+
r15 = nil
|
958
|
+
end
|
959
|
+
s14 << r15
|
960
|
+
if r15
|
961
|
+
if has_terminal?(@regexps[gr = '\A[cCdDeEfF]'] ||= Regexp.new(gr), :regexp, index)
|
962
|
+
r16 = true
|
963
|
+
@index += 1
|
964
|
+
else
|
965
|
+
terminal_parse_failure('[cCdDeEfF]')
|
966
|
+
r16 = nil
|
967
|
+
end
|
968
|
+
s14 << r16
|
969
|
+
if r16
|
970
|
+
s17, i17 = [], index
|
971
|
+
loop do
|
972
|
+
if has_terminal?(@regexps[gr = '\A[0-9a-fA-F]'] ||= Regexp.new(gr), :regexp, index)
|
973
|
+
r18 = true
|
974
|
+
@index += 1
|
975
|
+
else
|
976
|
+
terminal_parse_failure('[0-9a-fA-F]')
|
977
|
+
r18 = nil
|
978
|
+
end
|
979
|
+
if r18
|
980
|
+
s17 << r18
|
981
|
+
else
|
982
|
+
break
|
983
|
+
end
|
984
|
+
if s17.size == 2
|
985
|
+
break
|
986
|
+
end
|
987
|
+
end
|
988
|
+
if s17.size < 2
|
989
|
+
@index = i17
|
990
|
+
r17 = nil
|
991
|
+
else
|
992
|
+
r17 = instantiate_node(SyntaxNode,input, i17...index, s17)
|
993
|
+
end
|
994
|
+
s14 << r17
|
995
|
+
end
|
996
|
+
end
|
997
|
+
if s14.last
|
998
|
+
r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
|
999
|
+
r14.extend(StringPart4)
|
1000
|
+
else
|
1001
|
+
@index = i14
|
1002
|
+
r14 = nil
|
1003
|
+
end
|
1004
|
+
s6 << r14
|
1005
|
+
end
|
1006
|
+
end
|
1007
|
+
end
|
1008
|
+
if s6.last
|
1009
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
1010
|
+
r6.extend(StringPart5)
|
1011
|
+
r6.extend(StringPart6)
|
1012
|
+
else
|
1013
|
+
@index = i6
|
1014
|
+
r6 = nil
|
1015
|
+
end
|
1016
|
+
if r6
|
1017
|
+
r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
|
1018
|
+
r0 = r6
|
1019
|
+
else
|
1020
|
+
i19, s19 = index, []
|
1021
|
+
if (match_len = has_terminal?("\\u", false, index))
|
1022
|
+
r20 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
1023
|
+
@index += match_len
|
1024
|
+
else
|
1025
|
+
terminal_parse_failure("\\u")
|
1026
|
+
r20 = nil
|
1027
|
+
end
|
1028
|
+
s19 << r20
|
1029
|
+
if r20
|
1030
|
+
i21 = index
|
1031
|
+
i22, s22 = index, []
|
1032
|
+
if has_terminal?(@regexps[gr = '\A[0-9abcefABCEF]'] ||= Regexp.new(gr), :regexp, index)
|
1033
|
+
r23 = true
|
1034
|
+
@index += 1
|
1035
|
+
else
|
1036
|
+
terminal_parse_failure('[0-9abcefABCEF]')
|
1037
|
+
r23 = nil
|
1038
|
+
end
|
1039
|
+
s22 << r23
|
1040
|
+
if r23
|
1041
|
+
s24, i24 = [], index
|
1042
|
+
loop do
|
1043
|
+
if has_terminal?(@regexps[gr = '\A[0-9a-fA-F]'] ||= Regexp.new(gr), :regexp, index)
|
1044
|
+
r25 = true
|
1045
|
+
@index += 1
|
1046
|
+
else
|
1047
|
+
terminal_parse_failure('[0-9a-fA-F]')
|
1048
|
+
r25 = nil
|
1049
|
+
end
|
1050
|
+
if r25
|
1051
|
+
s24 << r25
|
1052
|
+
else
|
1053
|
+
break
|
1054
|
+
end
|
1055
|
+
if s24.size == 3
|
1056
|
+
break
|
1057
|
+
end
|
1058
|
+
end
|
1059
|
+
if s24.size < 3
|
1060
|
+
@index = i24
|
1061
|
+
r24 = nil
|
1062
|
+
else
|
1063
|
+
r24 = instantiate_node(SyntaxNode,input, i24...index, s24)
|
1064
|
+
end
|
1065
|
+
s22 << r24
|
1066
|
+
end
|
1067
|
+
if s22.last
|
1068
|
+
r22 = instantiate_node(SyntaxNode,input, i22...index, s22)
|
1069
|
+
r22.extend(StringPart7)
|
1070
|
+
else
|
1071
|
+
@index = i22
|
1072
|
+
r22 = nil
|
1073
|
+
end
|
1074
|
+
if r22
|
1075
|
+
r22 = SyntaxNode.new(input, (index-1)...index) if r22 == true
|
1076
|
+
r21 = r22
|
1077
|
+
else
|
1078
|
+
i26, s26 = index, []
|
1079
|
+
if has_terminal?(@regexps[gr = '\A[dD]'] ||= Regexp.new(gr), :regexp, index)
|
1080
|
+
r27 = true
|
1081
|
+
@index += 1
|
1082
|
+
else
|
1083
|
+
terminal_parse_failure('[dD]')
|
1084
|
+
r27 = nil
|
1085
|
+
end
|
1086
|
+
s26 << r27
|
1087
|
+
if r27
|
1088
|
+
if has_terminal?(@regexps[gr = '\A[0-7]'] ||= Regexp.new(gr), :regexp, index)
|
1089
|
+
r28 = true
|
1090
|
+
@index += 1
|
1091
|
+
else
|
1092
|
+
terminal_parse_failure('[0-7]')
|
1093
|
+
r28 = nil
|
1094
|
+
end
|
1095
|
+
s26 << r28
|
1096
|
+
if r28
|
1097
|
+
s29, i29 = [], index
|
1098
|
+
loop do
|
1099
|
+
if has_terminal?(@regexps[gr = '\A[0-9a-fA-F]'] ||= Regexp.new(gr), :regexp, index)
|
1100
|
+
r30 = true
|
1101
|
+
@index += 1
|
1102
|
+
else
|
1103
|
+
terminal_parse_failure('[0-9a-fA-F]')
|
1104
|
+
r30 = nil
|
1105
|
+
end
|
1106
|
+
if r30
|
1107
|
+
s29 << r30
|
1108
|
+
else
|
1109
|
+
break
|
1110
|
+
end
|
1111
|
+
if s29.size == 2
|
1112
|
+
break
|
1113
|
+
end
|
1114
|
+
end
|
1115
|
+
if s29.size < 2
|
1116
|
+
@index = i29
|
1117
|
+
r29 = nil
|
1118
|
+
else
|
1119
|
+
r29 = instantiate_node(SyntaxNode,input, i29...index, s29)
|
1120
|
+
end
|
1121
|
+
s26 << r29
|
1122
|
+
end
|
1123
|
+
end
|
1124
|
+
if s26.last
|
1125
|
+
r26 = instantiate_node(SyntaxNode,input, i26...index, s26)
|
1126
|
+
r26.extend(StringPart8)
|
1127
|
+
else
|
1128
|
+
@index = i26
|
1129
|
+
r26 = nil
|
1130
|
+
end
|
1131
|
+
if r26
|
1132
|
+
r26 = SyntaxNode.new(input, (index-1)...index) if r26 == true
|
1133
|
+
r21 = r26
|
1134
|
+
else
|
1135
|
+
@index = i21
|
1136
|
+
r21 = nil
|
1137
|
+
end
|
1138
|
+
end
|
1139
|
+
s19 << r21
|
1140
|
+
end
|
1141
|
+
if s19.last
|
1142
|
+
r19 = instantiate_node(SyntaxNode,input, i19...index, s19)
|
1143
|
+
r19.extend(StringPart9)
|
1144
|
+
r19.extend(StringPart10)
|
1145
|
+
else
|
1146
|
+
@index = i19
|
1147
|
+
r19 = nil
|
1148
|
+
end
|
1149
|
+
if r19
|
1150
|
+
r19 = SyntaxNode.new(input, (index-1)...index) if r19 == true
|
1151
|
+
r0 = r19
|
1152
|
+
else
|
1153
|
+
@index = i0
|
1154
|
+
r0 = nil
|
1155
|
+
end
|
1156
|
+
end
|
1157
|
+
end
|
1158
|
+
end
|
1159
|
+
|
1160
|
+
node_cache[:string_part][start_index] = r0
|
1161
|
+
|
1162
|
+
r0
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
module Hstring0
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
module Hstring1
|
1169
|
+
def s
|
1170
|
+
elements[1]
|
1171
|
+
end
|
1172
|
+
|
1173
|
+
end
|
1174
|
+
|
1175
|
+
module Hstring2
|
1176
|
+
#"
|
1177
|
+
def to_rb;
|
1178
|
+
s.text_value.chars.each_slice(2).map{|a| a.join.to_i(16).chr(Encoding::BINARY)}.join.b
|
1179
|
+
end
|
1180
|
+
end
|
1181
|
+
|
1182
|
+
def _nt_hstring
|
1183
|
+
start_index = index
|
1184
|
+
if node_cache[:hstring].has_key?(index)
|
1185
|
+
cached = node_cache[:hstring][index]
|
1186
|
+
if cached
|
1187
|
+
node_cache[:hstring][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1188
|
+
@index = cached.interval.end
|
1189
|
+
end
|
1190
|
+
return cached
|
1191
|
+
end
|
1192
|
+
|
1193
|
+
i0, s0 = index, []
|
1194
|
+
if (match_len = has_terminal?("h'", false, index))
|
1195
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
|
1196
|
+
@index += match_len
|
1197
|
+
else
|
1198
|
+
terminal_parse_failure("h'")
|
1199
|
+
r1 = nil
|
1200
|
+
end
|
1201
|
+
s0 << r1
|
1202
|
+
if r1
|
1203
|
+
s2, i2 = [], index
|
1204
|
+
loop do
|
1205
|
+
i3, s3 = index, []
|
1206
|
+
if has_terminal?(@regexps[gr = '\A[0-9a-fA-F]'] ||= Regexp.new(gr), :regexp, index)
|
1207
|
+
r4 = true
|
1208
|
+
@index += 1
|
1209
|
+
else
|
1210
|
+
terminal_parse_failure('[0-9a-fA-F]')
|
1211
|
+
r4 = nil
|
1212
|
+
end
|
1213
|
+
s3 << r4
|
1214
|
+
if r4
|
1215
|
+
if has_terminal?(@regexps[gr = '\A[0-9a-fA-F]'] ||= Regexp.new(gr), :regexp, index)
|
1216
|
+
r5 = true
|
1217
|
+
@index += 1
|
1218
|
+
else
|
1219
|
+
terminal_parse_failure('[0-9a-fA-F]')
|
1220
|
+
r5 = nil
|
1221
|
+
end
|
1222
|
+
s3 << r5
|
1223
|
+
end
|
1224
|
+
if s3.last
|
1225
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
1226
|
+
r3.extend(Hstring0)
|
1227
|
+
else
|
1228
|
+
@index = i3
|
1229
|
+
r3 = nil
|
1230
|
+
end
|
1231
|
+
if r3
|
1232
|
+
s2 << r3
|
1233
|
+
else
|
1234
|
+
break
|
1235
|
+
end
|
1236
|
+
end
|
1237
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
1238
|
+
s0 << r2
|
1239
|
+
if r2
|
1240
|
+
if (match_len = has_terminal?("'", false, index))
|
1241
|
+
r6 = true
|
1242
|
+
@index += match_len
|
1243
|
+
else
|
1244
|
+
terminal_parse_failure("'")
|
1245
|
+
r6 = nil
|
1246
|
+
end
|
1247
|
+
s0 << r6
|
1248
|
+
end
|
1249
|
+
end
|
1250
|
+
if s0.last
|
1251
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1252
|
+
r0.extend(Hstring1)
|
1253
|
+
r0.extend(Hstring2)
|
1254
|
+
else
|
1255
|
+
@index = i0
|
1256
|
+
r0 = nil
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
node_cache[:hstring][start_index] = r0
|
1260
|
+
|
1261
|
+
r0
|
1262
|
+
end
|
1263
|
+
|
1264
|
+
module Array0
|
1265
|
+
def ows1
|
1266
|
+
elements[1]
|
1267
|
+
end
|
1268
|
+
|
1269
|
+
def value
|
1270
|
+
elements[2]
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
def ows2
|
1274
|
+
elements[3]
|
1275
|
+
end
|
1276
|
+
end
|
1277
|
+
|
1278
|
+
module Array1
|
1279
|
+
def value
|
1280
|
+
elements[0]
|
1281
|
+
end
|
1282
|
+
|
1283
|
+
def ows
|
1284
|
+
elements[1]
|
1285
|
+
end
|
1286
|
+
|
1287
|
+
def an
|
1288
|
+
elements[2]
|
1289
|
+
end
|
1290
|
+
end
|
1291
|
+
|
1292
|
+
module Array2
|
1293
|
+
def spec
|
1294
|
+
elements[1]
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
def a1
|
1298
|
+
elements[2]
|
1299
|
+
end
|
1300
|
+
|
1301
|
+
def ows
|
1302
|
+
elements[3]
|
1303
|
+
end
|
1304
|
+
|
1305
|
+
end
|
1306
|
+
|
1307
|
+
module Array3
|
1308
|
+
def to_rb
|
1309
|
+
r = if e = a1.elements
|
1310
|
+
[e[0].to_rb] + e[2].elements.map {|x| x.value.to_rb }
|
1311
|
+
else
|
1312
|
+
[]
|
1313
|
+
end
|
1314
|
+
if spec.is_stream?
|
1315
|
+
r.cbor_stream!
|
1316
|
+
end
|
1317
|
+
r
|
1318
|
+
end
|
1319
|
+
end
|
1320
|
+
|
1321
|
+
def _nt_array
|
1322
|
+
start_index = index
|
1323
|
+
if node_cache[:array].has_key?(index)
|
1324
|
+
cached = node_cache[:array][index]
|
1325
|
+
if cached
|
1326
|
+
node_cache[:array][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1327
|
+
@index = cached.interval.end
|
1328
|
+
end
|
1329
|
+
return cached
|
1330
|
+
end
|
1331
|
+
|
1332
|
+
i0, s0 = index, []
|
1333
|
+
if (match_len = has_terminal?('[', false, index))
|
1334
|
+
r1 = true
|
1335
|
+
@index += match_len
|
1336
|
+
else
|
1337
|
+
terminal_parse_failure('[')
|
1338
|
+
r1 = nil
|
1339
|
+
end
|
1340
|
+
s0 << r1
|
1341
|
+
if r1
|
1342
|
+
r2 = _nt_spec
|
1343
|
+
s0 << r2
|
1344
|
+
if r2
|
1345
|
+
i4, s4 = index, []
|
1346
|
+
r5 = _nt_value
|
1347
|
+
s4 << r5
|
1348
|
+
if r5
|
1349
|
+
r6 = _nt_ows
|
1350
|
+
s4 << r6
|
1351
|
+
if r6
|
1352
|
+
s7, i7 = [], index
|
1353
|
+
loop do
|
1354
|
+
i8, s8 = index, []
|
1355
|
+
if (match_len = has_terminal?(',', false, index))
|
1356
|
+
r9 = true
|
1357
|
+
@index += match_len
|
1358
|
+
else
|
1359
|
+
terminal_parse_failure(',')
|
1360
|
+
r9 = nil
|
1361
|
+
end
|
1362
|
+
s8 << r9
|
1363
|
+
if r9
|
1364
|
+
r10 = _nt_ows
|
1365
|
+
s8 << r10
|
1366
|
+
if r10
|
1367
|
+
r11 = _nt_value
|
1368
|
+
s8 << r11
|
1369
|
+
if r11
|
1370
|
+
r12 = _nt_ows
|
1371
|
+
s8 << r12
|
1372
|
+
end
|
1373
|
+
end
|
1374
|
+
end
|
1375
|
+
if s8.last
|
1376
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
1377
|
+
r8.extend(Array0)
|
1378
|
+
else
|
1379
|
+
@index = i8
|
1380
|
+
r8 = nil
|
1381
|
+
end
|
1382
|
+
if r8
|
1383
|
+
s7 << r8
|
1384
|
+
else
|
1385
|
+
break
|
1386
|
+
end
|
1387
|
+
end
|
1388
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
1389
|
+
s4 << r7
|
1390
|
+
end
|
1391
|
+
end
|
1392
|
+
if s4.last
|
1393
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
1394
|
+
r4.extend(Array1)
|
1395
|
+
else
|
1396
|
+
@index = i4
|
1397
|
+
r4 = nil
|
1398
|
+
end
|
1399
|
+
if r4
|
1400
|
+
r3 = r4
|
1401
|
+
else
|
1402
|
+
r3 = instantiate_node(SyntaxNode,input, index...index)
|
1403
|
+
end
|
1404
|
+
s0 << r3
|
1405
|
+
if r3
|
1406
|
+
r13 = _nt_ows
|
1407
|
+
s0 << r13
|
1408
|
+
if r13
|
1409
|
+
if (match_len = has_terminal?(']', false, index))
|
1410
|
+
r14 = true
|
1411
|
+
@index += match_len
|
1412
|
+
else
|
1413
|
+
terminal_parse_failure(']')
|
1414
|
+
r14 = nil
|
1415
|
+
end
|
1416
|
+
s0 << r14
|
1417
|
+
end
|
1418
|
+
end
|
1419
|
+
end
|
1420
|
+
end
|
1421
|
+
if s0.last
|
1422
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1423
|
+
r0.extend(Array2)
|
1424
|
+
r0.extend(Array3)
|
1425
|
+
else
|
1426
|
+
@index = i0
|
1427
|
+
r0 = nil
|
1428
|
+
end
|
1429
|
+
|
1430
|
+
node_cache[:array][start_index] = r0
|
1431
|
+
|
1432
|
+
r0
|
1433
|
+
end
|
1434
|
+
|
1435
|
+
module Map0
|
1436
|
+
def ows1
|
1437
|
+
elements[1]
|
1438
|
+
end
|
1439
|
+
|
1440
|
+
def kp
|
1441
|
+
elements[2]
|
1442
|
+
end
|
1443
|
+
|
1444
|
+
def ows2
|
1445
|
+
elements[3]
|
1446
|
+
end
|
1447
|
+
end
|
1448
|
+
|
1449
|
+
module Map1
|
1450
|
+
def kp
|
1451
|
+
elements[0]
|
1452
|
+
end
|
1453
|
+
|
1454
|
+
def ows
|
1455
|
+
elements[1]
|
1456
|
+
end
|
1457
|
+
|
1458
|
+
def an
|
1459
|
+
elements[2]
|
1460
|
+
end
|
1461
|
+
end
|
1462
|
+
|
1463
|
+
module Map2
|
1464
|
+
def spec
|
1465
|
+
elements[1]
|
1466
|
+
end
|
1467
|
+
|
1468
|
+
def a1
|
1469
|
+
elements[2]
|
1470
|
+
end
|
1471
|
+
|
1472
|
+
def ows
|
1473
|
+
elements[3]
|
1474
|
+
end
|
1475
|
+
|
1476
|
+
end
|
1477
|
+
|
1478
|
+
module Map3
|
1479
|
+
def to_rb
|
1480
|
+
r = if e = a1.elements
|
1481
|
+
Hash[ [e[0].to_rb] + e[2].elements.map {|x| x.kp.to_rb } ]
|
1482
|
+
else
|
1483
|
+
{}
|
1484
|
+
end
|
1485
|
+
if spec.is_stream?
|
1486
|
+
r.cbor_stream!
|
1487
|
+
end
|
1488
|
+
r
|
1489
|
+
end
|
1490
|
+
end
|
1491
|
+
|
1492
|
+
def _nt_map
|
1493
|
+
start_index = index
|
1494
|
+
if node_cache[:map].has_key?(index)
|
1495
|
+
cached = node_cache[:map][index]
|
1496
|
+
if cached
|
1497
|
+
node_cache[:map][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1498
|
+
@index = cached.interval.end
|
1499
|
+
end
|
1500
|
+
return cached
|
1501
|
+
end
|
1502
|
+
|
1503
|
+
i0, s0 = index, []
|
1504
|
+
if (match_len = has_terminal?('{', false, index))
|
1505
|
+
r1 = true
|
1506
|
+
@index += match_len
|
1507
|
+
else
|
1508
|
+
terminal_parse_failure('{')
|
1509
|
+
r1 = nil
|
1510
|
+
end
|
1511
|
+
s0 << r1
|
1512
|
+
if r1
|
1513
|
+
r2 = _nt_spec
|
1514
|
+
s0 << r2
|
1515
|
+
if r2
|
1516
|
+
i4, s4 = index, []
|
1517
|
+
r5 = _nt_kp
|
1518
|
+
s4 << r5
|
1519
|
+
if r5
|
1520
|
+
r6 = _nt_ows
|
1521
|
+
s4 << r6
|
1522
|
+
if r6
|
1523
|
+
s7, i7 = [], index
|
1524
|
+
loop do
|
1525
|
+
i8, s8 = index, []
|
1526
|
+
if (match_len = has_terminal?(',', false, index))
|
1527
|
+
r9 = true
|
1528
|
+
@index += match_len
|
1529
|
+
else
|
1530
|
+
terminal_parse_failure(',')
|
1531
|
+
r9 = nil
|
1532
|
+
end
|
1533
|
+
s8 << r9
|
1534
|
+
if r9
|
1535
|
+
r10 = _nt_ows
|
1536
|
+
s8 << r10
|
1537
|
+
if r10
|
1538
|
+
r11 = _nt_kp
|
1539
|
+
s8 << r11
|
1540
|
+
if r11
|
1541
|
+
r12 = _nt_ows
|
1542
|
+
s8 << r12
|
1543
|
+
end
|
1544
|
+
end
|
1545
|
+
end
|
1546
|
+
if s8.last
|
1547
|
+
r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
|
1548
|
+
r8.extend(Map0)
|
1549
|
+
else
|
1550
|
+
@index = i8
|
1551
|
+
r8 = nil
|
1552
|
+
end
|
1553
|
+
if r8
|
1554
|
+
s7 << r8
|
1555
|
+
else
|
1556
|
+
break
|
1557
|
+
end
|
1558
|
+
end
|
1559
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
1560
|
+
s4 << r7
|
1561
|
+
end
|
1562
|
+
end
|
1563
|
+
if s4.last
|
1564
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
1565
|
+
r4.extend(Map1)
|
1566
|
+
else
|
1567
|
+
@index = i4
|
1568
|
+
r4 = nil
|
1569
|
+
end
|
1570
|
+
if r4
|
1571
|
+
r3 = r4
|
1572
|
+
else
|
1573
|
+
r3 = instantiate_node(SyntaxNode,input, index...index)
|
1574
|
+
end
|
1575
|
+
s0 << r3
|
1576
|
+
if r3
|
1577
|
+
r13 = _nt_ows
|
1578
|
+
s0 << r13
|
1579
|
+
if r13
|
1580
|
+
if (match_len = has_terminal?('}', false, index))
|
1581
|
+
r14 = true
|
1582
|
+
@index += match_len
|
1583
|
+
else
|
1584
|
+
terminal_parse_failure('}')
|
1585
|
+
r14 = nil
|
1586
|
+
end
|
1587
|
+
s0 << r14
|
1588
|
+
end
|
1589
|
+
end
|
1590
|
+
end
|
1591
|
+
end
|
1592
|
+
if s0.last
|
1593
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1594
|
+
r0.extend(Map2)
|
1595
|
+
r0.extend(Map3)
|
1596
|
+
else
|
1597
|
+
@index = i0
|
1598
|
+
r0 = nil
|
1599
|
+
end
|
1600
|
+
|
1601
|
+
node_cache[:map][start_index] = r0
|
1602
|
+
|
1603
|
+
r0
|
1604
|
+
end
|
1605
|
+
|
1606
|
+
module Kp0
|
1607
|
+
def v1
|
1608
|
+
elements[0]
|
1609
|
+
end
|
1610
|
+
|
1611
|
+
def ows1
|
1612
|
+
elements[1]
|
1613
|
+
end
|
1614
|
+
|
1615
|
+
def ows2
|
1616
|
+
elements[3]
|
1617
|
+
end
|
1618
|
+
|
1619
|
+
def v2
|
1620
|
+
elements[4]
|
1621
|
+
end
|
1622
|
+
end
|
1623
|
+
|
1624
|
+
module Kp1
|
1625
|
+
def to_rb
|
1626
|
+
[v1.to_rb, v2.to_rb]
|
1627
|
+
end
|
1628
|
+
end
|
1629
|
+
|
1630
|
+
def _nt_kp
|
1631
|
+
start_index = index
|
1632
|
+
if node_cache[:kp].has_key?(index)
|
1633
|
+
cached = node_cache[:kp][index]
|
1634
|
+
if cached
|
1635
|
+
node_cache[:kp][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1636
|
+
@index = cached.interval.end
|
1637
|
+
end
|
1638
|
+
return cached
|
1639
|
+
end
|
1640
|
+
|
1641
|
+
i0, s0 = index, []
|
1642
|
+
r1 = _nt_value
|
1643
|
+
s0 << r1
|
1644
|
+
if r1
|
1645
|
+
r2 = _nt_ows
|
1646
|
+
s0 << r2
|
1647
|
+
if r2
|
1648
|
+
if (match_len = has_terminal?(":", false, index))
|
1649
|
+
r3 = true
|
1650
|
+
@index += match_len
|
1651
|
+
else
|
1652
|
+
terminal_parse_failure(":")
|
1653
|
+
r3 = nil
|
1654
|
+
end
|
1655
|
+
s0 << r3
|
1656
|
+
if r3
|
1657
|
+
r4 = _nt_ows
|
1658
|
+
s0 << r4
|
1659
|
+
if r4
|
1660
|
+
r5 = _nt_value
|
1661
|
+
s0 << r5
|
1662
|
+
end
|
1663
|
+
end
|
1664
|
+
end
|
1665
|
+
end
|
1666
|
+
if s0.last
|
1667
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1668
|
+
r0.extend(Kp0)
|
1669
|
+
r0.extend(Kp1)
|
1670
|
+
else
|
1671
|
+
@index = i0
|
1672
|
+
r0 = nil
|
1673
|
+
end
|
1674
|
+
|
1675
|
+
node_cache[:kp][start_index] = r0
|
1676
|
+
|
1677
|
+
r0
|
1678
|
+
end
|
1679
|
+
|
1680
|
+
def _nt_ows
|
1681
|
+
start_index = index
|
1682
|
+
if node_cache[:ows].has_key?(index)
|
1683
|
+
cached = node_cache[:ows][index]
|
1684
|
+
if cached
|
1685
|
+
node_cache[:ows][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1686
|
+
@index = cached.interval.end
|
1687
|
+
end
|
1688
|
+
return cached
|
1689
|
+
end
|
1690
|
+
|
1691
|
+
s0, i0 = [], index
|
1692
|
+
loop do
|
1693
|
+
if has_terminal?(@regexps[gr = '\A[ \\t\\n\\r]'] ||= Regexp.new(gr), :regexp, index)
|
1694
|
+
r1 = true
|
1695
|
+
@index += 1
|
1696
|
+
else
|
1697
|
+
terminal_parse_failure('[ \\t\\n\\r]')
|
1698
|
+
r1 = nil
|
1699
|
+
end
|
1700
|
+
if r1
|
1701
|
+
s0 << r1
|
1702
|
+
else
|
1703
|
+
break
|
1704
|
+
end
|
1705
|
+
end
|
1706
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1707
|
+
|
1708
|
+
node_cache[:ows][start_index] = r0
|
1709
|
+
|
1710
|
+
r0
|
1711
|
+
end
|
1712
|
+
|
1713
|
+
module Streamstring0
|
1714
|
+
def ows
|
1715
|
+
elements[1]
|
1716
|
+
end
|
1717
|
+
|
1718
|
+
def string
|
1719
|
+
elements[2]
|
1720
|
+
end
|
1721
|
+
end
|
1722
|
+
|
1723
|
+
module Streamstring1
|
1724
|
+
def string
|
1725
|
+
elements[0]
|
1726
|
+
end
|
1727
|
+
|
1728
|
+
def ows1
|
1729
|
+
elements[1]
|
1730
|
+
end
|
1731
|
+
|
1732
|
+
def an
|
1733
|
+
elements[2]
|
1734
|
+
end
|
1735
|
+
|
1736
|
+
def ows2
|
1737
|
+
elements[3]
|
1738
|
+
end
|
1739
|
+
end
|
1740
|
+
|
1741
|
+
module Streamstring2
|
1742
|
+
def ows1
|
1743
|
+
elements[1]
|
1744
|
+
end
|
1745
|
+
|
1746
|
+
def ows2
|
1747
|
+
elements[3]
|
1748
|
+
end
|
1749
|
+
|
1750
|
+
def a1
|
1751
|
+
elements[4]
|
1752
|
+
end
|
1753
|
+
|
1754
|
+
end
|
1755
|
+
|
1756
|
+
module Streamstring3
|
1757
|
+
def to_rb
|
1758
|
+
r = if e = a1.elements
|
1759
|
+
[e[0].to_rb] + e[2].elements.map {|x| x.string.to_rb }
|
1760
|
+
else
|
1761
|
+
[]
|
1762
|
+
end
|
1763
|
+
r.join.cbor_stream!(r.map(&:size))
|
1764
|
+
end
|
1765
|
+
end
|
1766
|
+
|
1767
|
+
module Streamstring4
|
1768
|
+
def ows
|
1769
|
+
elements[1]
|
1770
|
+
end
|
1771
|
+
|
1772
|
+
def hstring
|
1773
|
+
elements[2]
|
1774
|
+
end
|
1775
|
+
end
|
1776
|
+
|
1777
|
+
module Streamstring5
|
1778
|
+
def hstring
|
1779
|
+
elements[0]
|
1780
|
+
end
|
1781
|
+
|
1782
|
+
def ows1
|
1783
|
+
elements[1]
|
1784
|
+
end
|
1785
|
+
|
1786
|
+
def an
|
1787
|
+
elements[2]
|
1788
|
+
end
|
1789
|
+
|
1790
|
+
def ows2
|
1791
|
+
elements[3]
|
1792
|
+
end
|
1793
|
+
end
|
1794
|
+
|
1795
|
+
module Streamstring6
|
1796
|
+
def ows1
|
1797
|
+
elements[1]
|
1798
|
+
end
|
1799
|
+
|
1800
|
+
def ows2
|
1801
|
+
elements[3]
|
1802
|
+
end
|
1803
|
+
|
1804
|
+
def a1
|
1805
|
+
elements[4]
|
1806
|
+
end
|
1807
|
+
|
1808
|
+
end
|
1809
|
+
|
1810
|
+
module Streamstring7
|
1811
|
+
def to_rb
|
1812
|
+
r = if e = a1.elements
|
1813
|
+
[e[0].to_rb] + e[2].elements.map {|x| x.hstring.to_rb }
|
1814
|
+
else
|
1815
|
+
[]
|
1816
|
+
end
|
1817
|
+
r.join.b.cbor_stream!(r.map(&:size))
|
1818
|
+
end
|
1819
|
+
end
|
1820
|
+
|
1821
|
+
def _nt_streamstring
|
1822
|
+
start_index = index
|
1823
|
+
if node_cache[:streamstring].has_key?(index)
|
1824
|
+
cached = node_cache[:streamstring][index]
|
1825
|
+
if cached
|
1826
|
+
node_cache[:streamstring][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1827
|
+
@index = cached.interval.end
|
1828
|
+
end
|
1829
|
+
return cached
|
1830
|
+
end
|
1831
|
+
|
1832
|
+
i0 = index
|
1833
|
+
i1, s1 = index, []
|
1834
|
+
if (match_len = has_terminal?('(', false, index))
|
1835
|
+
r2 = true
|
1836
|
+
@index += match_len
|
1837
|
+
else
|
1838
|
+
terminal_parse_failure('(')
|
1839
|
+
r2 = nil
|
1840
|
+
end
|
1841
|
+
s1 << r2
|
1842
|
+
if r2
|
1843
|
+
r3 = _nt_ows
|
1844
|
+
s1 << r3
|
1845
|
+
if r3
|
1846
|
+
if (match_len = has_terminal?("_", false, index))
|
1847
|
+
r4 = true
|
1848
|
+
@index += match_len
|
1849
|
+
else
|
1850
|
+
terminal_parse_failure("_")
|
1851
|
+
r4 = nil
|
1852
|
+
end
|
1853
|
+
s1 << r4
|
1854
|
+
if r4
|
1855
|
+
r5 = _nt_ows
|
1856
|
+
s1 << r5
|
1857
|
+
if r5
|
1858
|
+
i6, s6 = index, []
|
1859
|
+
r7 = _nt_string
|
1860
|
+
s6 << r7
|
1861
|
+
if r7
|
1862
|
+
r8 = _nt_ows
|
1863
|
+
s6 << r8
|
1864
|
+
if r8
|
1865
|
+
s9, i9 = [], index
|
1866
|
+
loop do
|
1867
|
+
i10, s10 = index, []
|
1868
|
+
if (match_len = has_terminal?(",", false, index))
|
1869
|
+
r11 = true
|
1870
|
+
@index += match_len
|
1871
|
+
else
|
1872
|
+
terminal_parse_failure(",")
|
1873
|
+
r11 = nil
|
1874
|
+
end
|
1875
|
+
s10 << r11
|
1876
|
+
if r11
|
1877
|
+
r12 = _nt_ows
|
1878
|
+
s10 << r12
|
1879
|
+
if r12
|
1880
|
+
r13 = _nt_string
|
1881
|
+
s10 << r13
|
1882
|
+
end
|
1883
|
+
end
|
1884
|
+
if s10.last
|
1885
|
+
r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
|
1886
|
+
r10.extend(Streamstring0)
|
1887
|
+
else
|
1888
|
+
@index = i10
|
1889
|
+
r10 = nil
|
1890
|
+
end
|
1891
|
+
if r10
|
1892
|
+
s9 << r10
|
1893
|
+
else
|
1894
|
+
break
|
1895
|
+
end
|
1896
|
+
end
|
1897
|
+
r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
|
1898
|
+
s6 << r9
|
1899
|
+
if r9
|
1900
|
+
r14 = _nt_ows
|
1901
|
+
s6 << r14
|
1902
|
+
end
|
1903
|
+
end
|
1904
|
+
end
|
1905
|
+
if s6.last
|
1906
|
+
r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
|
1907
|
+
r6.extend(Streamstring1)
|
1908
|
+
else
|
1909
|
+
@index = i6
|
1910
|
+
r6 = nil
|
1911
|
+
end
|
1912
|
+
s1 << r6
|
1913
|
+
if r6
|
1914
|
+
if (match_len = has_terminal?(')', false, index))
|
1915
|
+
r15 = true
|
1916
|
+
@index += match_len
|
1917
|
+
else
|
1918
|
+
terminal_parse_failure(')')
|
1919
|
+
r15 = nil
|
1920
|
+
end
|
1921
|
+
s1 << r15
|
1922
|
+
end
|
1923
|
+
end
|
1924
|
+
end
|
1925
|
+
end
|
1926
|
+
end
|
1927
|
+
if s1.last
|
1928
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
1929
|
+
r1.extend(Streamstring2)
|
1930
|
+
r1.extend(Streamstring3)
|
1931
|
+
else
|
1932
|
+
@index = i1
|
1933
|
+
r1 = nil
|
1934
|
+
end
|
1935
|
+
if r1
|
1936
|
+
r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
|
1937
|
+
r0 = r1
|
1938
|
+
else
|
1939
|
+
i16, s16 = index, []
|
1940
|
+
if (match_len = has_terminal?('(', false, index))
|
1941
|
+
r17 = true
|
1942
|
+
@index += match_len
|
1943
|
+
else
|
1944
|
+
terminal_parse_failure('(')
|
1945
|
+
r17 = nil
|
1946
|
+
end
|
1947
|
+
s16 << r17
|
1948
|
+
if r17
|
1949
|
+
r18 = _nt_ows
|
1950
|
+
s16 << r18
|
1951
|
+
if r18
|
1952
|
+
if (match_len = has_terminal?("_", false, index))
|
1953
|
+
r19 = true
|
1954
|
+
@index += match_len
|
1955
|
+
else
|
1956
|
+
terminal_parse_failure("_")
|
1957
|
+
r19 = nil
|
1958
|
+
end
|
1959
|
+
s16 << r19
|
1960
|
+
if r19
|
1961
|
+
r20 = _nt_ows
|
1962
|
+
s16 << r20
|
1963
|
+
if r20
|
1964
|
+
i21, s21 = index, []
|
1965
|
+
r22 = _nt_hstring
|
1966
|
+
s21 << r22
|
1967
|
+
if r22
|
1968
|
+
r23 = _nt_ows
|
1969
|
+
s21 << r23
|
1970
|
+
if r23
|
1971
|
+
s24, i24 = [], index
|
1972
|
+
loop do
|
1973
|
+
i25, s25 = index, []
|
1974
|
+
if (match_len = has_terminal?(",", false, index))
|
1975
|
+
r26 = true
|
1976
|
+
@index += match_len
|
1977
|
+
else
|
1978
|
+
terminal_parse_failure(",")
|
1979
|
+
r26 = nil
|
1980
|
+
end
|
1981
|
+
s25 << r26
|
1982
|
+
if r26
|
1983
|
+
r27 = _nt_ows
|
1984
|
+
s25 << r27
|
1985
|
+
if r27
|
1986
|
+
r28 = _nt_hstring
|
1987
|
+
s25 << r28
|
1988
|
+
end
|
1989
|
+
end
|
1990
|
+
if s25.last
|
1991
|
+
r25 = instantiate_node(SyntaxNode,input, i25...index, s25)
|
1992
|
+
r25.extend(Streamstring4)
|
1993
|
+
else
|
1994
|
+
@index = i25
|
1995
|
+
r25 = nil
|
1996
|
+
end
|
1997
|
+
if r25
|
1998
|
+
s24 << r25
|
1999
|
+
else
|
2000
|
+
break
|
2001
|
+
end
|
2002
|
+
end
|
2003
|
+
r24 = instantiate_node(SyntaxNode,input, i24...index, s24)
|
2004
|
+
s21 << r24
|
2005
|
+
if r24
|
2006
|
+
r29 = _nt_ows
|
2007
|
+
s21 << r29
|
2008
|
+
end
|
2009
|
+
end
|
2010
|
+
end
|
2011
|
+
if s21.last
|
2012
|
+
r21 = instantiate_node(SyntaxNode,input, i21...index, s21)
|
2013
|
+
r21.extend(Streamstring5)
|
2014
|
+
else
|
2015
|
+
@index = i21
|
2016
|
+
r21 = nil
|
2017
|
+
end
|
2018
|
+
s16 << r21
|
2019
|
+
if r21
|
2020
|
+
if (match_len = has_terminal?(')', false, index))
|
2021
|
+
r30 = true
|
2022
|
+
@index += match_len
|
2023
|
+
else
|
2024
|
+
terminal_parse_failure(')')
|
2025
|
+
r30 = nil
|
2026
|
+
end
|
2027
|
+
s16 << r30
|
2028
|
+
end
|
2029
|
+
end
|
2030
|
+
end
|
2031
|
+
end
|
2032
|
+
end
|
2033
|
+
if s16.last
|
2034
|
+
r16 = instantiate_node(SyntaxNode,input, i16...index, s16)
|
2035
|
+
r16.extend(Streamstring6)
|
2036
|
+
r16.extend(Streamstring7)
|
2037
|
+
else
|
2038
|
+
@index = i16
|
2039
|
+
r16 = nil
|
2040
|
+
end
|
2041
|
+
if r16
|
2042
|
+
r16 = SyntaxNode.new(input, (index-1)...index) if r16 == true
|
2043
|
+
r0 = r16
|
2044
|
+
else
|
2045
|
+
@index = i0
|
2046
|
+
r0 = nil
|
2047
|
+
end
|
2048
|
+
end
|
2049
|
+
|
2050
|
+
node_cache[:streamstring][start_index] = r0
|
2051
|
+
|
2052
|
+
r0
|
2053
|
+
end
|
2054
|
+
|
2055
|
+
module Spec0
|
2056
|
+
def ows1
|
2057
|
+
elements[0]
|
2058
|
+
end
|
2059
|
+
|
2060
|
+
def a1
|
2061
|
+
elements[1]
|
2062
|
+
end
|
2063
|
+
|
2064
|
+
def ows2
|
2065
|
+
elements[2]
|
2066
|
+
end
|
2067
|
+
end
|
2068
|
+
|
2069
|
+
module Spec1
|
2070
|
+
def is_stream?
|
2071
|
+
!a1.empty?
|
2072
|
+
end
|
2073
|
+
end
|
2074
|
+
|
2075
|
+
def _nt_spec
|
2076
|
+
start_index = index
|
2077
|
+
if node_cache[:spec].has_key?(index)
|
2078
|
+
cached = node_cache[:spec][index]
|
2079
|
+
if cached
|
2080
|
+
node_cache[:spec][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
2081
|
+
@index = cached.interval.end
|
2082
|
+
end
|
2083
|
+
return cached
|
2084
|
+
end
|
2085
|
+
|
2086
|
+
i0, s0 = index, []
|
2087
|
+
r1 = _nt_ows
|
2088
|
+
s0 << r1
|
2089
|
+
if r1
|
2090
|
+
if (match_len = has_terminal?("_", false, index))
|
2091
|
+
r3 = true
|
2092
|
+
@index += match_len
|
2093
|
+
else
|
2094
|
+
terminal_parse_failure("_")
|
2095
|
+
r3 = nil
|
2096
|
+
end
|
2097
|
+
if r3
|
2098
|
+
r2 = r3
|
2099
|
+
else
|
2100
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
2101
|
+
end
|
2102
|
+
s0 << r2
|
2103
|
+
if r2
|
2104
|
+
r4 = _nt_ows
|
2105
|
+
s0 << r4
|
2106
|
+
end
|
2107
|
+
end
|
2108
|
+
if s0.last
|
2109
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
2110
|
+
r0.extend(Spec0)
|
2111
|
+
r0.extend(Spec1)
|
2112
|
+
else
|
2113
|
+
@index = i0
|
2114
|
+
r0 = nil
|
2115
|
+
end
|
2116
|
+
|
2117
|
+
node_cache[:spec][start_index] = r0
|
2118
|
+
|
2119
|
+
r0
|
2120
|
+
end
|
2121
|
+
|
2122
|
+
end
|
2123
|
+
|
2124
|
+
class CBOR_DIAGParser < Treetop::Runtime::CompiledParser
|
2125
|
+
include CBOR_DIAG
|
2126
|
+
end
|
2127
|
+
|