edn-abnf 0.0.4 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eb52693cd7d9aef79f242492135b2e923c156d91aac9d193023ba8ee5c3f5b3
4
- data.tar.gz: 76c8893695b10b13c351d93de8132c63238d295c95eb6b8aec565ae73a2169df
3
+ metadata.gz: 119b776b0bf643c32c9c0c2481b654e3087d0a7747f0a3f9bf9ae2460837a67a
4
+ data.tar.gz: bc7545b0786eeae5f5d33c6b95b702fe383ccdc306ecc5370e932413e089838e
5
5
  SHA512:
6
- metadata.gz: fc9855abe0afd6f8fda6026d31a2f611ebabfce7125278604c1c6e1a56093ded138b9e0cf5e34bba73a4365cc66fad21cf185fb09a3d7ca4f393683d76c14214
7
- data.tar.gz: d83a6154649f595a6da5e3f8f4ae40445157c7face9e54fae984df32b6e1e22e0c8c276aa2e04e9587a7ac4b7114f340d485c0d1e73016737bf61485be143c85
6
+ metadata.gz: e5c9dd0f7c19367133392c803bdf4719d6e0ec45d49d74c3fc05bb59e2d38e6ce0ffe38f17c0610c454783b795d5528e3bb030f32b452df9a802cbd447fc4c13
7
+ data.tar.gz: 994b84d2f1e90643aacfb3ef117d150bafbbd2a28f63057f25b51d5a1222d5a222a5d7fd8c77c83232c28e7378084bfaccc0d04db3e0f60eafecca7ed2eecb86
data/edn-abnf.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "edn-abnf"
3
- s.version = "0.0.4"
3
+ s.version = "0.0.6"
4
4
  s.summary = "CDDL (Concise Data Definition Language) converters and miscellaneous tools"
5
5
  s.description = %q{edn-abnf implements converters and miscellaneous tools for CBOR EDN's ABNF}
6
6
  s.author = "Carsten Bormann"
7
7
  s.email = "cabo@tzi.org"
8
8
  s.license = "MIT"
9
9
  s.homepage = "http://github.com/cabo/edn-abnf"
10
- s.files = Dir['lib/**/*.rb'] + %w(edn-abnf.gemspec) + Dir['data/*.cddl'] + Dir['bin/**/*.rb']
10
+ s.files = Dir['lib/**/*.rb'] + %w(edn-abnf.gemspec) + Dir['bin/**/*.rb']
11
11
  s.executables = Dir['bin/*'].map {|x| File.basename(x)}
12
12
  s.required_ruby_version = '>= 1.9.2'
13
13
 
@@ -1,7 +1,13 @@
1
- # mockup only; needs parser!
1
+ require_relative "b64grammar.rb"
2
2
 
3
3
  class CBOR_DIAG::App_b64
4
4
  def self.decode(_, s)
5
+ parser = B64GRAMMARParser.new # B? XXX
6
+ ast = parser.parse(s)
7
+ if !ast
8
+ raise ArgumentError, "cbor-diagnostic: Parse Error in b64'#{s}':\n" << EDN.reason(parser, s)
9
+ end
10
+ # lazy -- not using parse tree...:
5
11
  t = s.gsub(/\s/, '').chars.each_slice(4).map(&:join)
6
12
  if last = t[-1]
7
13
  last << "=" * (4 - last.size)
@@ -0,0 +1,498 @@
1
+ # Encoding: UTF-8
2
+ # Autogenerated from a Treetop grammar. Edits may be lost.
3
+
4
+
5
+ module B64GRAMMAR
6
+ include Treetop::Runtime
7
+
8
+ def root
9
+ @root ||= :app_string_b64
10
+ end
11
+
12
+ module AppStringB640
13
+ def b64dig
14
+ elements[0]
15
+ end
16
+
17
+ def B
18
+ elements[1]
19
+ end
20
+ end
21
+
22
+ module AppStringB641
23
+ def B
24
+ elements[1]
25
+ end
26
+
27
+ end
28
+
29
+ module AppStringB642
30
+ def b64dig
31
+ elements[0]
32
+ end
33
+
34
+ def B
35
+ elements[1]
36
+ end
37
+
38
+ end
39
+
40
+ module AppStringB643
41
+ def b64dig1
42
+ elements[0]
43
+ end
44
+
45
+ def B1
46
+ elements[1]
47
+ end
48
+
49
+ def b64dig2
50
+ elements[2]
51
+ end
52
+
53
+ def B2
54
+ elements[3]
55
+ end
56
+
57
+ def B3
58
+ elements[5]
59
+ end
60
+ end
61
+
62
+ module AppStringB644
63
+ def B
64
+ elements[0]
65
+ end
66
+
67
+ end
68
+
69
+ def _nt_app_string_b64
70
+ start_index = index
71
+ if node_cache[:app_string_b64].has_key?(index)
72
+ cached = node_cache[:app_string_b64][index]
73
+ if cached
74
+ node_cache[:app_string_b64][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
75
+ @index = cached.interval.end
76
+ end
77
+ return cached
78
+ end
79
+
80
+ i0, s0 = index, []
81
+ r1 = _nt_B
82
+ s0 << r1
83
+ if r1
84
+ s2, i2 = [], index
85
+ loop do
86
+ s3, i3 = [], index
87
+ loop do
88
+ i4, s4 = index, []
89
+ r5 = _nt_b64dig
90
+ s4 << r5
91
+ if r5
92
+ r6 = _nt_B
93
+ s4 << r6
94
+ end
95
+ if s4.last
96
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
97
+ r4.extend(AppStringB640)
98
+ else
99
+ @index = i4
100
+ r4 = nil
101
+ end
102
+ if r4
103
+ s3 << r4
104
+ else
105
+ break
106
+ end
107
+ if s3.size == 4
108
+ break
109
+ end
110
+ end
111
+ if s3.size < 4
112
+ @index = i3
113
+ r3 = nil
114
+ else
115
+ if s3.size < 4
116
+ @terminal_failures.pop
117
+ end
118
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
119
+ end
120
+ if r3
121
+ s2 << r3
122
+ else
123
+ break
124
+ end
125
+ end
126
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
127
+ s0 << r2
128
+ if r2
129
+ i8, s8 = index, []
130
+ r9 = _nt_b64dig
131
+ s8 << r9
132
+ if r9
133
+ r10 = _nt_B
134
+ s8 << r10
135
+ if r10
136
+ r11 = _nt_b64dig
137
+ s8 << r11
138
+ if r11
139
+ r12 = _nt_B
140
+ s8 << r12
141
+ if r12
142
+ i14 = index
143
+ i15, s15 = index, []
144
+ if (match_len = has_terminal?("=", false, index))
145
+ r16 = true
146
+ @index += match_len
147
+ else
148
+ terminal_parse_failure('"="')
149
+ r16 = nil
150
+ end
151
+ s15 << r16
152
+ if r16
153
+ r17 = _nt_B
154
+ s15 << r17
155
+ if r17
156
+ if (match_len = has_terminal?("=", false, index))
157
+ r18 = true
158
+ @index += match_len
159
+ else
160
+ terminal_parse_failure('"="')
161
+ r18 = nil
162
+ end
163
+ s15 << r18
164
+ end
165
+ end
166
+ if s15.last
167
+ r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
168
+ r15.extend(AppStringB641)
169
+ else
170
+ @index = i15
171
+ r15 = nil
172
+ end
173
+ if r15
174
+ r15 = SyntaxNode.new(input, (index-1)...index) if r15 == true
175
+ r14 = r15
176
+ else
177
+ i19, s19 = index, []
178
+ r20 = _nt_b64dig
179
+ s19 << r20
180
+ if r20
181
+ r21 = _nt_B
182
+ s19 << r21
183
+ if r21
184
+ if (match_len = has_terminal?("=", false, index))
185
+ r23 = true
186
+ @index += match_len
187
+ else
188
+ terminal_parse_failure('"="')
189
+ r23 = nil
190
+ end
191
+ if r23
192
+ r22 = r23
193
+ else
194
+ r22 = instantiate_node(SyntaxNode,input, index...index)
195
+ end
196
+ s19 << r22
197
+ end
198
+ end
199
+ if s19.last
200
+ r19 = instantiate_node(SyntaxNode,input, i19...index, s19)
201
+ r19.extend(AppStringB642)
202
+ else
203
+ @index = i19
204
+ r19 = nil
205
+ end
206
+ if r19
207
+ r19 = SyntaxNode.new(input, (index-1)...index) if r19 == true
208
+ r14 = r19
209
+ else
210
+ @index = i14
211
+ r14 = nil
212
+ end
213
+ end
214
+ if r14
215
+ r13 = r14
216
+ else
217
+ r13 = instantiate_node(SyntaxNode,input, index...index)
218
+ end
219
+ s8 << r13
220
+ if r13
221
+ r24 = _nt_B
222
+ s8 << r24
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end
228
+ if s8.last
229
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
230
+ r8.extend(AppStringB643)
231
+ else
232
+ @index = i8
233
+ r8 = nil
234
+ end
235
+ if r8
236
+ r7 = r8
237
+ else
238
+ r7 = instantiate_node(SyntaxNode,input, index...index)
239
+ end
240
+ s0 << r7
241
+ end
242
+ end
243
+ if s0.last
244
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
245
+ r0.extend(AppStringB644)
246
+ else
247
+ @index = i0
248
+ r0 = nil
249
+ end
250
+
251
+ node_cache[:app_string_b64][start_index] = r0
252
+
253
+ r0
254
+ end
255
+
256
+ def _nt_b64dig
257
+ start_index = index
258
+ if node_cache[:b64dig].has_key?(index)
259
+ cached = node_cache[:b64dig][index]
260
+ if cached
261
+ node_cache[:b64dig][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
262
+ @index = cached.interval.end
263
+ end
264
+ return cached
265
+ end
266
+
267
+ i0 = index
268
+ r1 = _nt_ALPHA
269
+ if r1
270
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
271
+ r0 = r1
272
+ else
273
+ r2 = _nt_DIGIT
274
+ if r2
275
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
276
+ r0 = r2
277
+ else
278
+ if (match_len = has_terminal?("-", false, index))
279
+ r3 = true
280
+ @index += match_len
281
+ else
282
+ terminal_parse_failure('"-"')
283
+ r3 = nil
284
+ end
285
+ if r3
286
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
287
+ r0 = r3
288
+ else
289
+ if (match_len = has_terminal?("_", false, index))
290
+ r4 = true
291
+ @index += match_len
292
+ else
293
+ terminal_parse_failure('"_"')
294
+ r4 = nil
295
+ end
296
+ if r4
297
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
298
+ r0 = r4
299
+ else
300
+ if (match_len = has_terminal?("+", false, index))
301
+ r5 = true
302
+ @index += match_len
303
+ else
304
+ terminal_parse_failure('"+"')
305
+ r5 = nil
306
+ end
307
+ if r5
308
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
309
+ r0 = r5
310
+ else
311
+ if (match_len = has_terminal?("/", false, index))
312
+ r6 = true
313
+ @index += match_len
314
+ else
315
+ terminal_parse_failure('"/"')
316
+ r6 = nil
317
+ end
318
+ if r6
319
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
320
+ r0 = r6
321
+ else
322
+ @index = i0
323
+ r0 = nil
324
+ end
325
+ end
326
+ end
327
+ end
328
+ end
329
+ end
330
+
331
+ node_cache[:b64dig][start_index] = r0
332
+
333
+ r0
334
+ end
335
+
336
+ def _nt_B
337
+ start_index = index
338
+ if node_cache[:B].has_key?(index)
339
+ cached = node_cache[:B][index]
340
+ if cached
341
+ node_cache[:B][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
342
+ @index = cached.interval.end
343
+ end
344
+ return cached
345
+ end
346
+
347
+ s0, i0 = [], index
348
+ loop do
349
+ r1 = _nt_iblank
350
+ if r1
351
+ s0 << r1
352
+ else
353
+ break
354
+ end
355
+ end
356
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
357
+
358
+ node_cache[:B][start_index] = r0
359
+
360
+ r0
361
+ end
362
+
363
+ def _nt_iblank
364
+ start_index = index
365
+ if node_cache[:iblank].has_key?(index)
366
+ cached = node_cache[:iblank][index]
367
+ if cached
368
+ node_cache[:iblank][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
369
+ @index = cached.interval.end
370
+ end
371
+ return cached
372
+ end
373
+
374
+ i0 = index
375
+ if (match_len = has_terminal?("\n", false, index))
376
+ r1 = true
377
+ @index += match_len
378
+ else
379
+ terminal_parse_failure('"\\n"')
380
+ r1 = nil
381
+ end
382
+ if r1
383
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
384
+ r0 = r1
385
+ else
386
+ if (match_len = has_terminal?(" ", false, index))
387
+ r2 = true
388
+ @index += match_len
389
+ else
390
+ terminal_parse_failure('" "')
391
+ r2 = nil
392
+ end
393
+ if r2
394
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
395
+ r0 = r2
396
+ else
397
+ @index = i0
398
+ r0 = nil
399
+ end
400
+ end
401
+
402
+ node_cache[:iblank][start_index] = r0
403
+
404
+ r0
405
+ end
406
+
407
+ def _nt_lcalpha
408
+ start_index = index
409
+ if node_cache[:lcalpha].has_key?(index)
410
+ cached = node_cache[:lcalpha][index]
411
+ if cached
412
+ node_cache[:lcalpha][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
413
+ @index = cached.interval.end
414
+ end
415
+ return cached
416
+ end
417
+
418
+ if has_terminal?(@regexps[gr = '\A[a-z]'] ||= Regexp.new(gr), :regexp, index)
419
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
420
+ @index += 1
421
+ else
422
+ terminal_parse_failure('[a-z]')
423
+ r0 = nil
424
+ end
425
+
426
+ node_cache[:lcalpha][start_index] = r0
427
+
428
+ r0
429
+ end
430
+
431
+ def _nt_ALPHA
432
+ start_index = index
433
+ if node_cache[:ALPHA].has_key?(index)
434
+ cached = node_cache[:ALPHA][index]
435
+ if cached
436
+ node_cache[:ALPHA][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
437
+ @index = cached.interval.end
438
+ end
439
+ return cached
440
+ end
441
+
442
+ i0 = index
443
+ if has_terminal?(@regexps[gr = '\A[A-Z]'] ||= Regexp.new(gr), :regexp, index)
444
+ r1 = true
445
+ @index += 1
446
+ else
447
+ terminal_parse_failure('[A-Z]')
448
+ r1 = nil
449
+ end
450
+ if r1
451
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
452
+ r0 = r1
453
+ else
454
+ r2 = _nt_lcalpha
455
+ if r2
456
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
457
+ r0 = r2
458
+ else
459
+ @index = i0
460
+ r0 = nil
461
+ end
462
+ end
463
+
464
+ node_cache[:ALPHA][start_index] = r0
465
+
466
+ r0
467
+ end
468
+
469
+ def _nt_DIGIT
470
+ start_index = index
471
+ if node_cache[:DIGIT].has_key?(index)
472
+ cached = node_cache[:DIGIT][index]
473
+ if cached
474
+ node_cache[:DIGIT][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
475
+ @index = cached.interval.end
476
+ end
477
+ return cached
478
+ end
479
+
480
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
481
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
482
+ @index += 1
483
+ else
484
+ terminal_parse_failure('[0-9]')
485
+ r0 = nil
486
+ end
487
+
488
+ node_cache[:DIGIT][start_index] = r0
489
+
490
+ r0
491
+ end
492
+
493
+ end
494
+
495
+ class B64GRAMMARParser < Treetop::Runtime::CompiledParser
496
+ include B64GRAMMAR
497
+ end
498
+
@@ -1,7 +1,13 @@
1
- # mockup only; needs parser!
1
+ require_relative "hgrammar.rb"
2
2
 
3
3
  class CBOR_DIAG::App_h
4
4
  def self.decode(_, s)
5
- s.gsub(/#.*|\s|\/[^\/]*\//, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join
5
+ parser = HGRAMMARParser.new
6
+ ast = parser.parse(s)
7
+ if !ast
8
+ raise ArgumentError, "cbor-diagnostic: Parse Error in h'#{s}':\n" << EDN.reason(parser, s)
9
+ end
10
+ ast.ast
6
11
  end
12
+ # s.gsub(/#.*|\s|\/[^\/]*\//, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join
7
13
  end
@@ -0,0 +1,457 @@
1
+ # Encoding: UTF-8
2
+ # Autogenerated from a Treetop grammar. Edits may be lost.
3
+
4
+
5
+ module HGRAMMAR
6
+ include Treetop::Runtime
7
+
8
+ def root
9
+ @root ||= :app_string_h
10
+ end
11
+
12
+ module AppStringH0
13
+ def HEXDIG1
14
+ elements[0]
15
+ end
16
+
17
+ def S1
18
+ elements[1]
19
+ end
20
+
21
+ def HEXDIG2
22
+ elements[2]
23
+ end
24
+
25
+ def S2
26
+ elements[3]
27
+ end
28
+ end
29
+
30
+ module AppStringH1
31
+ def S
32
+ elements[0]
33
+ end
34
+
35
+ end
36
+
37
+ module AppStringH2
38
+ def ast
39
+ e1 = elements[1].elements
40
+ e1.map {|e| Integer(e.elements[0].text_value + e.elements[2].text_value, 16).chr("BINARY")}.join.b
41
+ end
42
+ end
43
+
44
+ def _nt_app_string_h
45
+ start_index = index
46
+ if node_cache[:app_string_h].has_key?(index)
47
+ cached = node_cache[:app_string_h][index]
48
+ if cached
49
+ node_cache[:app_string_h][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
50
+ @index = cached.interval.end
51
+ end
52
+ return cached
53
+ end
54
+
55
+ i0, s0 = index, []
56
+ r1 = _nt_S
57
+ s0 << r1
58
+ if r1
59
+ s2, i2 = [], index
60
+ loop do
61
+ i3, s3 = index, []
62
+ r4 = _nt_HEXDIG
63
+ s3 << r4
64
+ if r4
65
+ r5 = _nt_S
66
+ s3 << r5
67
+ if r5
68
+ r6 = _nt_HEXDIG
69
+ s3 << r6
70
+ if r6
71
+ r7 = _nt_S
72
+ s3 << r7
73
+ end
74
+ end
75
+ end
76
+ if s3.last
77
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
78
+ r3.extend(AppStringH0)
79
+ else
80
+ @index = i3
81
+ r3 = nil
82
+ end
83
+ if r3
84
+ s2 << r3
85
+ else
86
+ break
87
+ end
88
+ end
89
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
90
+ s0 << r2
91
+ end
92
+ if s0.last
93
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
94
+ r0.extend(AppStringH1)
95
+ r0.extend(AppStringH2)
96
+ else
97
+ @index = i0
98
+ r0 = nil
99
+ end
100
+
101
+ node_cache[:app_string_h][start_index] = r0
102
+
103
+ r0
104
+ end
105
+
106
+ def _nt_HEXDIG
107
+ start_index = index
108
+ if node_cache[:HEXDIG].has_key?(index)
109
+ cached = node_cache[:HEXDIG][index]
110
+ if cached
111
+ node_cache[:HEXDIG][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
112
+ @index = cached.interval.end
113
+ end
114
+ return cached
115
+ end
116
+
117
+ i0 = index
118
+ r1 = _nt_DIGIT
119
+ if r1
120
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
121
+ r0 = r1
122
+ else
123
+ if (match_len = has_terminal?("a", :insens, index))
124
+ r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
125
+ @index += match_len
126
+ else
127
+ terminal_parse_failure('"A"')
128
+ r2 = nil
129
+ end
130
+ if r2
131
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
132
+ r0 = r2
133
+ else
134
+ if (match_len = has_terminal?("b", :insens, index))
135
+ r3 = instantiate_node(SyntaxNode,input, index...(index + match_len))
136
+ @index += match_len
137
+ else
138
+ terminal_parse_failure('"B"')
139
+ r3 = nil
140
+ end
141
+ if r3
142
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
143
+ r0 = r3
144
+ else
145
+ if (match_len = has_terminal?("c", :insens, index))
146
+ r4 = instantiate_node(SyntaxNode,input, index...(index + match_len))
147
+ @index += match_len
148
+ else
149
+ terminal_parse_failure('"C"')
150
+ r4 = nil
151
+ end
152
+ if r4
153
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
154
+ r0 = r4
155
+ else
156
+ if (match_len = has_terminal?("d", :insens, index))
157
+ r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
158
+ @index += match_len
159
+ else
160
+ terminal_parse_failure('"D"')
161
+ r5 = nil
162
+ end
163
+ if r5
164
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
165
+ r0 = r5
166
+ else
167
+ if (match_len = has_terminal?("e", :insens, index))
168
+ r6 = instantiate_node(SyntaxNode,input, index...(index + match_len))
169
+ @index += match_len
170
+ else
171
+ terminal_parse_failure('"E"')
172
+ r6 = nil
173
+ end
174
+ if r6
175
+ r6 = SyntaxNode.new(input, (index-1)...index) if r6 == true
176
+ r0 = r6
177
+ else
178
+ if (match_len = has_terminal?("f", :insens, index))
179
+ r7 = instantiate_node(SyntaxNode,input, index...(index + match_len))
180
+ @index += match_len
181
+ else
182
+ terminal_parse_failure('"F"')
183
+ r7 = nil
184
+ end
185
+ if r7
186
+ r7 = SyntaxNode.new(input, (index-1)...index) if r7 == true
187
+ r0 = r7
188
+ else
189
+ @index = i0
190
+ r0 = nil
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
198
+
199
+ node_cache[:HEXDIG][start_index] = r0
200
+
201
+ r0
202
+ end
203
+
204
+ def _nt_DIGIT
205
+ start_index = index
206
+ if node_cache[:DIGIT].has_key?(index)
207
+ cached = node_cache[:DIGIT][index]
208
+ if cached
209
+ node_cache[:DIGIT][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
210
+ @index = cached.interval.end
211
+ end
212
+ return cached
213
+ end
214
+
215
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
216
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
217
+ @index += 1
218
+ else
219
+ terminal_parse_failure('[0-9]')
220
+ r0 = nil
221
+ end
222
+
223
+ node_cache[:DIGIT][start_index] = r0
224
+
225
+ r0
226
+ end
227
+
228
+ def _nt_blank
229
+ start_index = index
230
+ if node_cache[:blank].has_key?(index)
231
+ cached = node_cache[:blank][index]
232
+ if cached
233
+ node_cache[:blank][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
234
+ @index = cached.interval.end
235
+ end
236
+ return cached
237
+ end
238
+
239
+ i0 = index
240
+ if (match_len = has_terminal?("\t", false, index))
241
+ r1 = true
242
+ @index += match_len
243
+ else
244
+ terminal_parse_failure('"\\t"')
245
+ r1 = nil
246
+ end
247
+ if r1
248
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
249
+ r0 = r1
250
+ else
251
+ if (match_len = has_terminal?("\n", false, index))
252
+ r2 = true
253
+ @index += match_len
254
+ else
255
+ terminal_parse_failure('"\\n"')
256
+ r2 = nil
257
+ end
258
+ if r2
259
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
260
+ r0 = r2
261
+ else
262
+ if (match_len = has_terminal?("\r", false, index))
263
+ r3 = true
264
+ @index += match_len
265
+ else
266
+ terminal_parse_failure('"\\r"')
267
+ r3 = nil
268
+ end
269
+ if r3
270
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
271
+ r0 = r3
272
+ else
273
+ if (match_len = has_terminal?(" ", false, index))
274
+ r4 = true
275
+ @index += match_len
276
+ else
277
+ terminal_parse_failure('" "')
278
+ r4 = nil
279
+ end
280
+ if r4
281
+ r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
282
+ r0 = r4
283
+ else
284
+ @index = i0
285
+ r0 = nil
286
+ end
287
+ end
288
+ end
289
+ end
290
+
291
+ node_cache[:blank][start_index] = r0
292
+
293
+ r0
294
+ end
295
+
296
+ def _nt_non_slash
297
+ start_index = index
298
+ if node_cache[:non_slash].has_key?(index)
299
+ cached = node_cache[:non_slash][index]
300
+ if cached
301
+ node_cache[:non_slash][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
302
+ @index = cached.interval.end
303
+ end
304
+ return cached
305
+ end
306
+
307
+ i0 = index
308
+ r1 = _nt_blank
309
+ if r1
310
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
311
+ r0 = r1
312
+ else
313
+ if has_terminal?(@regexps[gr = '\A[!-\\.]'] ||= Regexp.new(gr), :regexp, index)
314
+ r2 = true
315
+ @index += 1
316
+ else
317
+ terminal_parse_failure('[!-\\.]')
318
+ r2 = nil
319
+ end
320
+ if r2
321
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
322
+ r0 = r2
323
+ else
324
+ if has_terminal?(@regexps[gr = '\A[0-􏿿]'] ||= Regexp.new(gr), :regexp, index)
325
+ r3 = true
326
+ @index += 1
327
+ else
328
+ terminal_parse_failure('[0-􏿿]')
329
+ r3 = nil
330
+ end
331
+ if r3
332
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
333
+ r0 = r3
334
+ else
335
+ @index = i0
336
+ r0 = nil
337
+ end
338
+ end
339
+ end
340
+
341
+ node_cache[:non_slash][start_index] = r0
342
+
343
+ r0
344
+ end
345
+
346
+ module S0
347
+ end
348
+
349
+ module S1
350
+ end
351
+
352
+ def _nt_S
353
+ start_index = index
354
+ if node_cache[:S].has_key?(index)
355
+ cached = node_cache[:S][index]
356
+ if cached
357
+ node_cache[:S][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
358
+ @index = cached.interval.end
359
+ end
360
+ return cached
361
+ end
362
+
363
+ i0, s0 = index, []
364
+ s1, i1 = [], index
365
+ loop do
366
+ r2 = _nt_blank
367
+ if r2
368
+ s1 << r2
369
+ else
370
+ break
371
+ end
372
+ end
373
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
374
+ s0 << r1
375
+ if r1
376
+ s3, i3 = [], index
377
+ loop do
378
+ i4, s4 = index, []
379
+ if (match_len = has_terminal?("/", false, index))
380
+ r5 = true
381
+ @index += match_len
382
+ else
383
+ terminal_parse_failure('"/"')
384
+ r5 = nil
385
+ end
386
+ s4 << r5
387
+ if r5
388
+ s6, i6 = [], index
389
+ loop do
390
+ r7 = _nt_non_slash
391
+ if r7
392
+ s6 << r7
393
+ else
394
+ break
395
+ end
396
+ end
397
+ r6 = instantiate_node(SyntaxNode,input, i6...index, s6)
398
+ s4 << r6
399
+ if r6
400
+ if (match_len = has_terminal?("/", false, index))
401
+ r8 = true
402
+ @index += match_len
403
+ else
404
+ terminal_parse_failure('"/"')
405
+ r8 = nil
406
+ end
407
+ s4 << r8
408
+ if r8
409
+ s9, i9 = [], index
410
+ loop do
411
+ r10 = _nt_blank
412
+ if r10
413
+ s9 << r10
414
+ else
415
+ break
416
+ end
417
+ end
418
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
419
+ s4 << r9
420
+ end
421
+ end
422
+ end
423
+ if s4.last
424
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
425
+ r4.extend(S0)
426
+ else
427
+ @index = i4
428
+ r4 = nil
429
+ end
430
+ if r4
431
+ s3 << r4
432
+ else
433
+ break
434
+ end
435
+ end
436
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
437
+ s0 << r3
438
+ end
439
+ if s0.last
440
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
441
+ r0.extend(S1)
442
+ else
443
+ @index = i0
444
+ r0 = nil
445
+ end
446
+
447
+ node_cache[:S][start_index] = r0
448
+
449
+ r0
450
+ end
451
+
452
+ end
453
+
454
+ class HGRAMMARParser < Treetop::Runtime::CompiledParser
455
+ include HGRAMMAR
456
+ end
457
+
@@ -1,9 +1,6 @@
1
1
  require 'cbor-diagnostic'
2
2
  module CBOR_DIAG
3
3
  end
4
- require 'cbor-diagnostic-app/dt'
5
- require 'cbor-diagnostic-app/h'
6
- require 'cbor-diagnostic-app/b64'
7
4
 
8
5
  require 'treetop'
9
6
  require_relative './edngrammar'
@@ -19,3 +16,8 @@ class Treetop::Runtime::SyntaxNode
19
16
  text_value.to_i(16)
20
17
  end
21
18
  end
19
+
20
+
21
+ require 'cbor-diagnostic-app/dt'
22
+ require 'cbor-diagnostic-app/h'
23
+ require 'cbor-diagnostic-app/b64'
@@ -469,7 +469,13 @@ module EDNGRAMMAR
469
469
  end
470
470
 
471
471
  module Basenumber4
472
- def ast; Integer(text_value) end
472
+ end
473
+
474
+ module Basenumber5
475
+ end
476
+
477
+ module Basenumber6
478
+ def ast; /p/i =~ text_value ? Float(text_value) : Integer(text_value) end
473
479
  end
474
480
 
475
481
  def _nt_basenumber
@@ -528,10 +534,98 @@ module EDNGRAMMAR
528
534
  r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
529
535
  end
530
536
  s5 << r7
537
+ if r7
538
+ i10, s10 = index, []
539
+ i12, s12 = index, []
540
+ if (match_len = has_terminal?(".", false, index))
541
+ r13 = true
542
+ @index += match_len
543
+ else
544
+ terminal_parse_failure('"."')
545
+ r13 = nil
546
+ end
547
+ s12 << r13
548
+ if r13
549
+ s14, i14 = [], index
550
+ loop do
551
+ r15 = _nt_HEXDIG
552
+ if r15
553
+ s14 << r15
554
+ else
555
+ break
556
+ end
557
+ end
558
+ if s14.empty?
559
+ @index = i14
560
+ r14 = nil
561
+ else
562
+ r14 = instantiate_node(SyntaxNode,input, i14...index, s14)
563
+ end
564
+ s12 << r14
565
+ end
566
+ if s12.last
567
+ r12 = instantiate_node(SyntaxNode,input, i12...index, s12)
568
+ r12.extend(Basenumber0)
569
+ else
570
+ @index = i12
571
+ r12 = nil
572
+ end
573
+ if r12
574
+ r11 = r12
575
+ else
576
+ r11 = instantiate_node(SyntaxNode,input, index...index)
577
+ end
578
+ s10 << r11
579
+ if r11
580
+ if (match_len = has_terminal?("p", :insens, index))
581
+ r16 = instantiate_node(SyntaxNode,input, index...(index + match_len))
582
+ @index += match_len
583
+ else
584
+ terminal_parse_failure('"p"')
585
+ r16 = nil
586
+ end
587
+ s10 << r16
588
+ if r16
589
+ r18 = _nt_sign
590
+ if r18
591
+ r17 = r18
592
+ else
593
+ r17 = instantiate_node(SyntaxNode,input, index...index)
594
+ end
595
+ s10 << r17
596
+ if r17
597
+ s19, i19 = [], index
598
+ loop do
599
+ r20 = _nt_DIGIT
600
+ if r20
601
+ s19 << r20
602
+ else
603
+ break
604
+ end
605
+ end
606
+ r19 = instantiate_node(SyntaxNode,input, i19...index, s19)
607
+ s10 << r19
608
+ end
609
+ end
610
+ end
611
+ if s10.last
612
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
613
+ r10.extend(Basenumber1)
614
+ else
615
+ @index = i10
616
+ r10 = nil
617
+ end
618
+ if r10
619
+ r9 = r10
620
+ else
621
+ r9 = instantiate_node(SyntaxNode,input, index...index)
622
+ end
623
+ s5 << r9
624
+ end
531
625
  end
532
626
  if s5.last
533
627
  r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
534
- r5.extend(Basenumber0)
628
+ r5.extend(Basenumber2)
535
629
  else
536
630
  @index = i5
537
631
  r5 = nil
@@ -540,81 +634,81 @@ module EDNGRAMMAR
540
634
  r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
541
635
  r4 = r5
542
636
  else
543
- i9, s9 = index, []
637
+ i21, s21 = index, []
544
638
  if (match_len = has_terminal?("o", :insens, index))
545
- r10 = instantiate_node(SyntaxNode,input, index...(index + match_len))
639
+ r22 = instantiate_node(SyntaxNode,input, index...(index + match_len))
546
640
  @index += match_len
547
641
  else
548
642
  terminal_parse_failure('"o"')
549
- r10 = nil
643
+ r22 = nil
550
644
  end
551
- s9 << r10
552
- if r10
553
- s11, i11 = [], index
645
+ s21 << r22
646
+ if r22
647
+ s23, i23 = [], index
554
648
  loop do
555
- r12 = _nt_ODIGIT
556
- if r12
557
- s11 << r12
649
+ r24 = _nt_ODIGIT
650
+ if r24
651
+ s23 << r24
558
652
  else
559
653
  break
560
654
  end
561
655
  end
562
- if s11.empty?
563
- @index = i11
564
- r11 = nil
656
+ if s23.empty?
657
+ @index = i23
658
+ r23 = nil
565
659
  else
566
- r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
660
+ r23 = instantiate_node(SyntaxNode,input, i23...index, s23)
567
661
  end
568
- s9 << r11
662
+ s21 << r23
569
663
  end
570
- if s9.last
571
- r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
572
- r9.extend(Basenumber1)
664
+ if s21.last
665
+ r21 = instantiate_node(SyntaxNode,input, i21...index, s21)
666
+ r21.extend(Basenumber3)
573
667
  else
574
- @index = i9
575
- r9 = nil
668
+ @index = i21
669
+ r21 = nil
576
670
  end
577
- if r9
578
- r9 = SyntaxNode.new(input, (index-1)...index) if r9 == true
579
- r4 = r9
671
+ if r21
672
+ r21 = SyntaxNode.new(input, (index-1)...index) if r21 == true
673
+ r4 = r21
580
674
  else
581
- i13, s13 = index, []
675
+ i25, s25 = index, []
582
676
  if (match_len = has_terminal?("b", :insens, index))
583
- r14 = instantiate_node(SyntaxNode,input, index...(index + match_len))
677
+ r26 = instantiate_node(SyntaxNode,input, index...(index + match_len))
584
678
  @index += match_len
585
679
  else
586
680
  terminal_parse_failure('"b"')
587
- r14 = nil
681
+ r26 = nil
588
682
  end
589
- s13 << r14
590
- if r14
591
- s15, i15 = [], index
683
+ s25 << r26
684
+ if r26
685
+ s27, i27 = [], index
592
686
  loop do
593
- r16 = _nt_BDIGIT
594
- if r16
595
- s15 << r16
687
+ r28 = _nt_BDIGIT
688
+ if r28
689
+ s27 << r28
596
690
  else
597
691
  break
598
692
  end
599
693
  end
600
- if s15.empty?
601
- @index = i15
602
- r15 = nil
694
+ if s27.empty?
695
+ @index = i27
696
+ r27 = nil
603
697
  else
604
- r15 = instantiate_node(SyntaxNode,input, i15...index, s15)
698
+ r27 = instantiate_node(SyntaxNode,input, i27...index, s27)
605
699
  end
606
- s13 << r15
700
+ s25 << r27
607
701
  end
608
- if s13.last
609
- r13 = instantiate_node(SyntaxNode,input, i13...index, s13)
610
- r13.extend(Basenumber2)
702
+ if s25.last
703
+ r25 = instantiate_node(SyntaxNode,input, i25...index, s25)
704
+ r25.extend(Basenumber4)
611
705
  else
612
- @index = i13
613
- r13 = nil
706
+ @index = i25
707
+ r25 = nil
614
708
  end
615
- if r13
616
- r13 = SyntaxNode.new(input, (index-1)...index) if r13 == true
617
- r4 = r13
709
+ if r25
710
+ r25 = SyntaxNode.new(input, (index-1)...index) if r25 == true
711
+ r4 = r25
618
712
  else
619
713
  @index = i4
620
714
  r4 = nil
@@ -626,8 +720,8 @@ module EDNGRAMMAR
626
720
  end
627
721
  if s0.last
628
722
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
629
- r0.extend(Basenumber3)
630
- r0.extend(Basenumber4)
723
+ r0.extend(Basenumber5)
724
+ r0.extend(Basenumber6)
631
725
  else
632
726
  @index = i0
633
727
  r0 = nil
@@ -3690,44 +3784,6 @@ module EDNGRAMMAR
3690
3784
  r0
3691
3785
  end
3692
3786
 
3693
- def _nt_ALPHA
3694
- start_index = index
3695
- if node_cache[:ALPHA].has_key?(index)
3696
- cached = node_cache[:ALPHA][index]
3697
- if cached
3698
- node_cache[:ALPHA][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
3699
- @index = cached.interval.end
3700
- end
3701
- return cached
3702
- end
3703
-
3704
- i0 = index
3705
- if has_terminal?(@regexps[gr = '\A[A-Z]'] ||= Regexp.new(gr), :regexp, index)
3706
- r1 = true
3707
- @index += 1
3708
- else
3709
- terminal_parse_failure('[A-Z]')
3710
- r1 = nil
3711
- end
3712
- if r1
3713
- r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
3714
- r0 = r1
3715
- else
3716
- r2 = _nt_lcalpha
3717
- if r2
3718
- r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
3719
- r0 = r2
3720
- else
3721
- @index = i0
3722
- r0 = nil
3723
- end
3724
- end
3725
-
3726
- node_cache[:ALPHA][start_index] = r0
3727
-
3728
- r0
3729
- end
3730
-
3731
3787
  end
3732
3788
 
3733
3789
  class EDNGRAMMARParser < Treetop::Runtime::CompiledParser
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edn-abnf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-26 00:00:00.000000000 Z
11
+ date: 2023-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,7 +93,9 @@ files:
93
93
  - bin/edn-abnf~
94
94
  - edn-abnf.gemspec
95
95
  - lib/cbor-diagnostic-app/b64.rb
96
+ - lib/cbor-diagnostic-app/b64grammar.rb
96
97
  - lib/cbor-diagnostic-app/h.rb
98
+ - lib/cbor-diagnostic-app/hgrammar.rb
97
99
  - lib/edn-abnf.rb
98
100
  - lib/parser/edn-util.rb
99
101
  - lib/parser/edngrammar.rb