edn-abnf 0.0.10 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,700 @@
1
+ # Encoding: UTF-8
2
+ # Autogenerated from a Treetop grammar. Edits may be lost.
3
+
4
+
5
+ module DTGRAMMAR
6
+ include Treetop::Runtime
7
+
8
+ def root
9
+ @root ||= :app_string_dt
10
+ end
11
+
12
+ def _nt_app_string_dt
13
+ start_index = index
14
+ if node_cache[:app_string_dt].has_key?(index)
15
+ cached = node_cache[:app_string_dt][index]
16
+ if cached
17
+ node_cache[:app_string_dt][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
18
+ @index = cached.interval.end
19
+ end
20
+ return cached
21
+ end
22
+
23
+ r0 = _nt_date_time
24
+
25
+ node_cache[:app_string_dt][start_index] = r0
26
+
27
+ r0
28
+ end
29
+
30
+ def _nt_date_fullyear
31
+ start_index = index
32
+ if node_cache[:date_fullyear].has_key?(index)
33
+ cached = node_cache[:date_fullyear][index]
34
+ if cached
35
+ node_cache[:date_fullyear][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
36
+ @index = cached.interval.end
37
+ end
38
+ return cached
39
+ end
40
+
41
+ s0, i0 = [], index
42
+ loop do
43
+ r1 = _nt_DIGIT
44
+ if r1
45
+ s0 << r1
46
+ else
47
+ break
48
+ end
49
+ if s0.size == 4
50
+ break
51
+ end
52
+ end
53
+ if s0.size < 4
54
+ @index = i0
55
+ r0 = nil
56
+ else
57
+ if s0.size < 4
58
+ @terminal_failures.pop
59
+ end
60
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
61
+ end
62
+
63
+ node_cache[:date_fullyear][start_index] = r0
64
+
65
+ r0
66
+ end
67
+
68
+ def _nt_date_month
69
+ start_index = index
70
+ if node_cache[:date_month].has_key?(index)
71
+ cached = node_cache[:date_month][index]
72
+ if cached
73
+ node_cache[:date_month][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
74
+ @index = cached.interval.end
75
+ end
76
+ return cached
77
+ end
78
+
79
+ s0, i0 = [], index
80
+ loop do
81
+ r1 = _nt_DIGIT
82
+ if r1
83
+ s0 << r1
84
+ else
85
+ break
86
+ end
87
+ if s0.size == 2
88
+ break
89
+ end
90
+ end
91
+ if s0.size < 2
92
+ @index = i0
93
+ r0 = nil
94
+ else
95
+ if s0.size < 2
96
+ @terminal_failures.pop
97
+ end
98
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
99
+ end
100
+
101
+ node_cache[:date_month][start_index] = r0
102
+
103
+ r0
104
+ end
105
+
106
+ def _nt_date_mday
107
+ start_index = index
108
+ if node_cache[:date_mday].has_key?(index)
109
+ cached = node_cache[:date_mday][index]
110
+ if cached
111
+ node_cache[:date_mday][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
+ s0, i0 = [], index
118
+ loop do
119
+ r1 = _nt_DIGIT
120
+ if r1
121
+ s0 << r1
122
+ else
123
+ break
124
+ end
125
+ if s0.size == 2
126
+ break
127
+ end
128
+ end
129
+ if s0.size < 2
130
+ @index = i0
131
+ r0 = nil
132
+ else
133
+ if s0.size < 2
134
+ @terminal_failures.pop
135
+ end
136
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
137
+ end
138
+
139
+ node_cache[:date_mday][start_index] = r0
140
+
141
+ r0
142
+ end
143
+
144
+ def _nt_time_hour
145
+ start_index = index
146
+ if node_cache[:time_hour].has_key?(index)
147
+ cached = node_cache[:time_hour][index]
148
+ if cached
149
+ node_cache[:time_hour][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
150
+ @index = cached.interval.end
151
+ end
152
+ return cached
153
+ end
154
+
155
+ s0, i0 = [], index
156
+ loop do
157
+ r1 = _nt_DIGIT
158
+ if r1
159
+ s0 << r1
160
+ else
161
+ break
162
+ end
163
+ if s0.size == 2
164
+ break
165
+ end
166
+ end
167
+ if s0.size < 2
168
+ @index = i0
169
+ r0 = nil
170
+ else
171
+ if s0.size < 2
172
+ @terminal_failures.pop
173
+ end
174
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
175
+ end
176
+
177
+ node_cache[:time_hour][start_index] = r0
178
+
179
+ r0
180
+ end
181
+
182
+ def _nt_time_minute
183
+ start_index = index
184
+ if node_cache[:time_minute].has_key?(index)
185
+ cached = node_cache[:time_minute][index]
186
+ if cached
187
+ node_cache[:time_minute][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
188
+ @index = cached.interval.end
189
+ end
190
+ return cached
191
+ end
192
+
193
+ s0, i0 = [], index
194
+ loop do
195
+ r1 = _nt_DIGIT
196
+ if r1
197
+ s0 << r1
198
+ else
199
+ break
200
+ end
201
+ if s0.size == 2
202
+ break
203
+ end
204
+ end
205
+ if s0.size < 2
206
+ @index = i0
207
+ r0 = nil
208
+ else
209
+ if s0.size < 2
210
+ @terminal_failures.pop
211
+ end
212
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
213
+ end
214
+
215
+ node_cache[:time_minute][start_index] = r0
216
+
217
+ r0
218
+ end
219
+
220
+ def _nt_time_second
221
+ start_index = index
222
+ if node_cache[:time_second].has_key?(index)
223
+ cached = node_cache[:time_second][index]
224
+ if cached
225
+ node_cache[:time_second][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
226
+ @index = cached.interval.end
227
+ end
228
+ return cached
229
+ end
230
+
231
+ s0, i0 = [], index
232
+ loop do
233
+ r1 = _nt_DIGIT
234
+ if r1
235
+ s0 << r1
236
+ else
237
+ break
238
+ end
239
+ if s0.size == 2
240
+ break
241
+ end
242
+ end
243
+ if s0.size < 2
244
+ @index = i0
245
+ r0 = nil
246
+ else
247
+ if s0.size < 2
248
+ @terminal_failures.pop
249
+ end
250
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
251
+ end
252
+
253
+ node_cache[:time_second][start_index] = r0
254
+
255
+ r0
256
+ end
257
+
258
+ module TimeSecfrac0
259
+ end
260
+
261
+ def _nt_time_secfrac
262
+ start_index = index
263
+ if node_cache[:time_secfrac].has_key?(index)
264
+ cached = node_cache[:time_secfrac][index]
265
+ if cached
266
+ node_cache[:time_secfrac][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
267
+ @index = cached.interval.end
268
+ end
269
+ return cached
270
+ end
271
+
272
+ i0, s0 = index, []
273
+ if (match_len = has_terminal?(".", false, index))
274
+ r1 = true
275
+ @index += match_len
276
+ else
277
+ terminal_parse_failure('"."')
278
+ r1 = nil
279
+ end
280
+ s0 << r1
281
+ if r1
282
+ s2, i2 = [], index
283
+ loop do
284
+ r3 = _nt_DIGIT
285
+ if r3
286
+ s2 << r3
287
+ else
288
+ break
289
+ end
290
+ end
291
+ if s2.empty?
292
+ @index = i2
293
+ r2 = nil
294
+ else
295
+ r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
296
+ end
297
+ s0 << r2
298
+ end
299
+ if s0.last
300
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
301
+ r0.extend(TimeSecfrac0)
302
+ else
303
+ @index = i0
304
+ r0 = nil
305
+ end
306
+
307
+ node_cache[:time_secfrac][start_index] = r0
308
+
309
+ r0
310
+ end
311
+
312
+ module TimeNumoffset0
313
+ def time_hour
314
+ elements[1]
315
+ end
316
+
317
+ def time_minute
318
+ elements[3]
319
+ end
320
+ end
321
+
322
+ def _nt_time_numoffset
323
+ start_index = index
324
+ if node_cache[:time_numoffset].has_key?(index)
325
+ cached = node_cache[:time_numoffset][index]
326
+ if cached
327
+ node_cache[:time_numoffset][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
328
+ @index = cached.interval.end
329
+ end
330
+ return cached
331
+ end
332
+
333
+ i0, s0 = index, []
334
+ i1 = index
335
+ if (match_len = has_terminal?("+", false, index))
336
+ r2 = true
337
+ @index += match_len
338
+ else
339
+ terminal_parse_failure('"+"')
340
+ r2 = nil
341
+ end
342
+ if r2
343
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
344
+ r1 = r2
345
+ else
346
+ if (match_len = has_terminal?("-", false, index))
347
+ r3 = true
348
+ @index += match_len
349
+ else
350
+ terminal_parse_failure('"-"')
351
+ r3 = nil
352
+ end
353
+ if r3
354
+ r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
355
+ r1 = r3
356
+ else
357
+ @index = i1
358
+ r1 = nil
359
+ end
360
+ end
361
+ s0 << r1
362
+ if r1
363
+ r4 = _nt_time_hour
364
+ s0 << r4
365
+ if r4
366
+ if (match_len = has_terminal?(":", false, index))
367
+ r5 = true
368
+ @index += match_len
369
+ else
370
+ terminal_parse_failure('":"')
371
+ r5 = nil
372
+ end
373
+ s0 << r5
374
+ if r5
375
+ r6 = _nt_time_minute
376
+ s0 << r6
377
+ end
378
+ end
379
+ end
380
+ if s0.last
381
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
382
+ r0.extend(TimeNumoffset0)
383
+ else
384
+ @index = i0
385
+ r0 = nil
386
+ end
387
+
388
+ node_cache[:time_numoffset][start_index] = r0
389
+
390
+ r0
391
+ end
392
+
393
+ def _nt_time_offset
394
+ start_index = index
395
+ if node_cache[:time_offset].has_key?(index)
396
+ cached = node_cache[:time_offset][index]
397
+ if cached
398
+ node_cache[:time_offset][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
399
+ @index = cached.interval.end
400
+ end
401
+ return cached
402
+ end
403
+
404
+ i0 = index
405
+ if (match_len = has_terminal?("z", :insens, index))
406
+ r1 = instantiate_node(SyntaxNode,input, index...(index + match_len))
407
+ @index += match_len
408
+ else
409
+ terminal_parse_failure('"Z"')
410
+ r1 = nil
411
+ end
412
+ if r1
413
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
414
+ r0 = r1
415
+ else
416
+ r2 = _nt_time_numoffset
417
+ if r2
418
+ r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
419
+ r0 = r2
420
+ else
421
+ @index = i0
422
+ r0 = nil
423
+ end
424
+ end
425
+
426
+ node_cache[:time_offset][start_index] = r0
427
+
428
+ r0
429
+ end
430
+
431
+ module PartialTime0
432
+ def time_hour
433
+ elements[0]
434
+ end
435
+
436
+ def time_minute
437
+ elements[2]
438
+ end
439
+
440
+ def time_second
441
+ elements[4]
442
+ end
443
+
444
+ end
445
+
446
+ def _nt_partial_time
447
+ start_index = index
448
+ if node_cache[:partial_time].has_key?(index)
449
+ cached = node_cache[:partial_time][index]
450
+ if cached
451
+ node_cache[:partial_time][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
452
+ @index = cached.interval.end
453
+ end
454
+ return cached
455
+ end
456
+
457
+ i0, s0 = index, []
458
+ r1 = _nt_time_hour
459
+ s0 << r1
460
+ if r1
461
+ if (match_len = has_terminal?(":", false, index))
462
+ r2 = true
463
+ @index += match_len
464
+ else
465
+ terminal_parse_failure('":"')
466
+ r2 = nil
467
+ end
468
+ s0 << r2
469
+ if r2
470
+ r3 = _nt_time_minute
471
+ s0 << r3
472
+ if r3
473
+ if (match_len = has_terminal?(":", false, index))
474
+ r4 = true
475
+ @index += match_len
476
+ else
477
+ terminal_parse_failure('":"')
478
+ r4 = nil
479
+ end
480
+ s0 << r4
481
+ if r4
482
+ r5 = _nt_time_second
483
+ s0 << r5
484
+ if r5
485
+ r7 = _nt_time_secfrac
486
+ if r7
487
+ r6 = r7
488
+ else
489
+ r6 = instantiate_node(SyntaxNode,input, index...index)
490
+ end
491
+ s0 << r6
492
+ end
493
+ end
494
+ end
495
+ end
496
+ end
497
+ if s0.last
498
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
499
+ r0.extend(PartialTime0)
500
+ else
501
+ @index = i0
502
+ r0 = nil
503
+ end
504
+
505
+ node_cache[:partial_time][start_index] = r0
506
+
507
+ r0
508
+ end
509
+
510
+ module FullDate0
511
+ def date_fullyear
512
+ elements[0]
513
+ end
514
+
515
+ def date_month
516
+ elements[2]
517
+ end
518
+
519
+ def date_mday
520
+ elements[4]
521
+ end
522
+ end
523
+
524
+ def _nt_full_date
525
+ start_index = index
526
+ if node_cache[:full_date].has_key?(index)
527
+ cached = node_cache[:full_date][index]
528
+ if cached
529
+ node_cache[:full_date][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
530
+ @index = cached.interval.end
531
+ end
532
+ return cached
533
+ end
534
+
535
+ i0, s0 = index, []
536
+ r1 = _nt_date_fullyear
537
+ s0 << r1
538
+ if r1
539
+ if (match_len = has_terminal?("-", false, index))
540
+ r2 = true
541
+ @index += match_len
542
+ else
543
+ terminal_parse_failure('"-"')
544
+ r2 = nil
545
+ end
546
+ s0 << r2
547
+ if r2
548
+ r3 = _nt_date_month
549
+ s0 << r3
550
+ if r3
551
+ if (match_len = has_terminal?("-", false, index))
552
+ r4 = true
553
+ @index += match_len
554
+ else
555
+ terminal_parse_failure('"-"')
556
+ r4 = nil
557
+ end
558
+ s0 << r4
559
+ if r4
560
+ r5 = _nt_date_mday
561
+ s0 << r5
562
+ end
563
+ end
564
+ end
565
+ end
566
+ if s0.last
567
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
568
+ r0.extend(FullDate0)
569
+ else
570
+ @index = i0
571
+ r0 = nil
572
+ end
573
+
574
+ node_cache[:full_date][start_index] = r0
575
+
576
+ r0
577
+ end
578
+
579
+ module FullTime0
580
+ def partial_time
581
+ elements[0]
582
+ end
583
+
584
+ def time_offset
585
+ elements[1]
586
+ end
587
+ end
588
+
589
+ def _nt_full_time
590
+ start_index = index
591
+ if node_cache[:full_time].has_key?(index)
592
+ cached = node_cache[:full_time][index]
593
+ if cached
594
+ node_cache[:full_time][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
595
+ @index = cached.interval.end
596
+ end
597
+ return cached
598
+ end
599
+
600
+ i0, s0 = index, []
601
+ r1 = _nt_partial_time
602
+ s0 << r1
603
+ if r1
604
+ r2 = _nt_time_offset
605
+ s0 << r2
606
+ end
607
+ if s0.last
608
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
609
+ r0.extend(FullTime0)
610
+ else
611
+ @index = i0
612
+ r0 = nil
613
+ end
614
+
615
+ node_cache[:full_time][start_index] = r0
616
+
617
+ r0
618
+ end
619
+
620
+ module DateTime0
621
+ def full_date
622
+ elements[0]
623
+ end
624
+
625
+ def full_time
626
+ elements[2]
627
+ end
628
+ end
629
+
630
+ def _nt_date_time
631
+ start_index = index
632
+ if node_cache[:date_time].has_key?(index)
633
+ cached = node_cache[:date_time][index]
634
+ if cached
635
+ node_cache[:date_time][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
636
+ @index = cached.interval.end
637
+ end
638
+ return cached
639
+ end
640
+
641
+ i0, s0 = index, []
642
+ r1 = _nt_full_date
643
+ s0 << r1
644
+ if r1
645
+ if (match_len = has_terminal?("t", :insens, index))
646
+ r2 = instantiate_node(SyntaxNode,input, index...(index + match_len))
647
+ @index += match_len
648
+ else
649
+ terminal_parse_failure('"T"')
650
+ r2 = nil
651
+ end
652
+ s0 << r2
653
+ if r2
654
+ r3 = _nt_full_time
655
+ s0 << r3
656
+ end
657
+ end
658
+ if s0.last
659
+ r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
660
+ r0.extend(DateTime0)
661
+ else
662
+ @index = i0
663
+ r0 = nil
664
+ end
665
+
666
+ node_cache[:date_time][start_index] = r0
667
+
668
+ r0
669
+ end
670
+
671
+ def _nt_DIGIT
672
+ start_index = index
673
+ if node_cache[:DIGIT].has_key?(index)
674
+ cached = node_cache[:DIGIT][index]
675
+ if cached
676
+ node_cache[:DIGIT][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
677
+ @index = cached.interval.end
678
+ end
679
+ return cached
680
+ end
681
+
682
+ if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
683
+ r0 = instantiate_node(SyntaxNode,input, index...(index + 1))
684
+ @index += 1
685
+ else
686
+ terminal_parse_failure('[0-9]')
687
+ r0 = nil
688
+ end
689
+
690
+ node_cache[:DIGIT][start_index] = r0
691
+
692
+ r0
693
+ end
694
+
695
+ end
696
+
697
+ class DTGRAMMARParser < Treetop::Runtime::CompiledParser
698
+ include DTGRAMMAR
699
+ end
700
+
@@ -0,0 +1,22 @@
1
+ require_relative "ipgrammar.rb"
2
+ require 'ipaddr'
3
+
4
+ class CBOR_DIAG::App_ip
5
+ def self.decode(app_prefix, s)
6
+ parser = IPGRAMMARParser.new
7
+ ast = parser.parse(s)
8
+ if !ast
9
+ raise ArgumentError, "cbor-diagnostic: Parse Error in h'#{s}':\n" << EDN.reason(parser, s)
10
+ end
11
+ fam, ipv = ast.ast
12
+ case app_prefix
13
+ when 'ip'
14
+ ipv
15
+ when 'IP'
16
+ CBOR::Tagged.new(fam, ipv)
17
+ else
18
+ fail app_prefix
19
+ end
20
+ end
21
+ # s.gsub(/#.*|\s|\/[^\/]*\//, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join
22
+ end