edn-abnf 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/edn-abnf.gemspec +2 -2
- data/lib/cbor-diagnostic-app/b64.rb +7 -1
- data/lib/cbor-diagnostic-app/b64grammar.rb +498 -0
- data/lib/cbor-diagnostic-app/h.rb +8 -2
- data/lib/cbor-diagnostic-app/hgrammar.rb +457 -0
- data/lib/edn-abnf.rb +4 -3
- data/lib/parser/edn-util.rb +5 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc5ceebd31ab8dcb7737436c41348a218438eb914ac7090e85015fb6ecbda313
|
4
|
+
data.tar.gz: 8859e52ce3b6154d0d409e01a1d4d279c1f60f589121eeb749f7d171b60c2452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 350cb3b5cf59fc45721f626e2a6eb2cf5b936da60952aa4d758b14f8152f98e2f08afe490d2c3e063a2db6900ac1323f59c2e8f6248a11e8f9ff7ac440020130
|
7
|
+
data.tar.gz: 75c3ff4a6948ac326e1b60b9e49a4f440f2e18fd2dc910fc3a7b915244fc95be4edecf843cdcde6d408cc8d74df321200ef93762c3e15228c4c947ea41d600f0
|
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.
|
3
|
+
s.version = "0.0.5"
|
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['
|
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
|
-
|
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
|
-
|
1
|
+
require_relative "hgrammar.rb"
|
2
2
|
|
3
3
|
class CBOR_DIAG::App_h
|
4
4
|
def self.decode(_, s)
|
5
|
-
|
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
|
+
|
data/lib/edn-abnf.rb
CHANGED
@@ -5,9 +5,10 @@ class EDN
|
|
5
5
|
|
6
6
|
def self.reason(parser, s)
|
7
7
|
reason = [parser.failure_reason]
|
8
|
-
parser.failure_reason =~ /^(Expected .+) after
|
9
|
-
|
8
|
+
parser.failure_reason =~ /^(Expected .+) after ./m
|
9
|
+
expected = $1
|
10
10
|
if line = s.lines.to_a[parser.failure_line - 1]
|
11
|
+
reason << "#{$1.gsub("\n", '<<<NEWLINE>>>')}:" if expected
|
11
12
|
reason << line
|
12
13
|
reason << "#{'~' * (parser.failure_column - 1)}^"
|
13
14
|
end
|
@@ -17,7 +18,7 @@ class EDN
|
|
17
18
|
def self.from_edn(s)
|
18
19
|
ast = @@parser.parse s
|
19
20
|
if !ast
|
20
|
-
|
21
|
+
raise ArgumentError, "Parse Error:\n" << self.reason(@@parser, s)
|
21
22
|
end
|
22
23
|
ret = EDN.new(ast)
|
23
24
|
ret
|
data/lib/parser/edn-util.rb
CHANGED
@@ -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'
|
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
|
+
version: 0.0.5
|
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-
|
11
|
+
date: 2023-08-26 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
|