edn-abnf 0.5.36pre2 → 0.6.1pre
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 +4 -4
- data/bin/edn-abnf +6 -7
- data/edn-abnf.gemspec +1 -1
- data/lib/cbor-diag-support.rb +15 -51
- data/lib/cbor-diagnostic-app/hgrammar.rb +75 -434
- data/lib/parser/edngrammar.rb +4501 -7963
- metadata +2 -3
- data/lib/cbor-diagnostic-app/zzz.rb +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35b0986f4a0d059f1223e057a2cd2ea5c6852e2a682ad5fa1a3c1e135b2446c7
|
|
4
|
+
data.tar.gz: 98f4bdb66e78f3b3c85edd88bcd18dbb3a832dd9153d178a79f89baf911ac109
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e7ce39d92102381078c9d3da002dd2362808fd9c7faaca0676fbdc532d430ffeb85c6c6f770b34466571814529c66aaa172b26a179e26d8b081bea9cb08b5af
|
|
7
|
+
data.tar.gz: 62c3946d702aec9897e4149021e3798459abbe93927e87942faec2df9373190b4d86877e9dfd01ff5f8b40c3635fafd0203f18e2f4244dc22b8d713bc4c5361b
|
data/bin/edn-abnf
CHANGED
|
@@ -115,12 +115,11 @@ if $options.lines
|
|
|
115
115
|
exit 1
|
|
116
116
|
end
|
|
117
117
|
CSV.parse(edn_file) do |ok, ednin, out|
|
|
118
|
-
if
|
|
118
|
+
if ok[0] == "#"
|
|
119
119
|
puts "# #{ok}, #{ednin.inspect}, #{out}" if $options.verbose
|
|
120
120
|
next
|
|
121
121
|
end
|
|
122
122
|
if ok[0] == "x"
|
|
123
|
-
warn "#{[ok, ednin, out].inspect}" unless ednin
|
|
124
123
|
result = tree_from_edn_possibly_hex(ednin)
|
|
125
124
|
result_hex = result.to_cbor.hexi
|
|
126
125
|
result_diag = result.cbor_diagnostic
|
|
@@ -137,8 +136,8 @@ if $options.lines
|
|
|
137
136
|
end
|
|
138
137
|
begin
|
|
139
138
|
ok = ok == "="
|
|
140
|
-
puts "➔ #{ok
|
|
141
|
-
result = tree_from_edn_possibly_hex(ednin
|
|
139
|
+
puts "➔ #{ok}, #{ednin}, #{out}" if $options.verbose
|
|
140
|
+
result = tree_from_edn_possibly_hex(ednin)
|
|
142
141
|
diag = result.cbor_diagnostic
|
|
143
142
|
if out == diag && !ok
|
|
144
143
|
puts "** ≠ / #{diag.inspect} / #{out.inspect}"
|
|
@@ -152,7 +151,7 @@ if $options.lines
|
|
|
152
151
|
end
|
|
153
152
|
puts "reparsed / #{diag.inspect} / #{out.inspect}" if $options.verbose
|
|
154
153
|
end
|
|
155
|
-
rescue
|
|
154
|
+
rescue ArgumentError => e
|
|
156
155
|
if ok
|
|
157
156
|
puts "** #{e} / #{result.inspect} / #{out.inspect}"
|
|
158
157
|
$error += 1
|
|
@@ -181,10 +180,10 @@ begin
|
|
|
181
180
|
result = edn.tree # XXX .tree?
|
|
182
181
|
end
|
|
183
182
|
rescue CBOR_DIAG::AppParseError, ArgumentError => e
|
|
184
|
-
|
|
183
|
+
puts "** #{e}"
|
|
185
184
|
exit 1
|
|
186
185
|
rescue CBOR::OutOfBytesError, RuntimeError, JSON::GeneratorError => e
|
|
187
|
-
|
|
186
|
+
puts "** (encoded CBOR input:) #{e}"
|
|
188
187
|
exit 1
|
|
189
188
|
end
|
|
190
189
|
|
data/edn-abnf.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "edn-abnf"
|
|
3
|
-
s.version = "0.
|
|
3
|
+
s.version = "0.6.1pre"
|
|
4
4
|
s.summary = "CBOR Extended Diagnostic Notation (EDN) implemented in ABNF"
|
|
5
5
|
s.description = %q{edn-abnf implements converters and miscellaneous tools for CBOR EDN's ABNF}
|
|
6
6
|
s.author = "Carsten Bormann"
|
data/lib/cbor-diag-support.rb
CHANGED
|
@@ -12,7 +12,7 @@ module CBOR
|
|
|
12
12
|
def inspect
|
|
13
13
|
"#<CBOR::Box #{self.class} value=#{value.inspect}, options=#{options.inspect}>"
|
|
14
14
|
end
|
|
15
|
-
def self.
|
|
15
|
+
def self.from_number(n, options={})
|
|
16
16
|
case n
|
|
17
17
|
when Box
|
|
18
18
|
n.class.new(n.value, n.options.merge(options))
|
|
@@ -20,13 +20,23 @@ module CBOR
|
|
|
20
20
|
Ibox.new(n, options.dup)
|
|
21
21
|
when ::Float
|
|
22
22
|
Fbox.new(n, options.dup)
|
|
23
|
-
when ::String, ::Array, ::Hash, ::CBOR::Tagged
|
|
24
|
-
Xbox.new(n, options.dup)
|
|
25
23
|
else
|
|
26
24
|
raise ArgumentError, "cbor-diagnostic: can't box number from #{n.inspect}':\n"
|
|
27
25
|
end
|
|
28
26
|
end
|
|
27
|
+
def to_cbor
|
|
28
|
+
CBOR.encode(value)
|
|
29
|
+
end
|
|
30
|
+
def cbor_diagnostic(opts = {})
|
|
31
|
+
ret = value.cbor_diagnostic(opts)
|
|
32
|
+
if ei = options[:ei]
|
|
33
|
+
ret << "_#{ei}"
|
|
34
|
+
end
|
|
35
|
+
ret
|
|
36
|
+
end
|
|
37
|
+
end
|
|
29
38
|
|
|
39
|
+
class Ibox < Box
|
|
30
40
|
INTEGER_EI = {
|
|
31
41
|
"i" => [23, 0],
|
|
32
42
|
"0" => [0xFF, 1],
|
|
@@ -34,7 +44,7 @@ module CBOR
|
|
|
34
44
|
"2" => [0xFFFFFFFF, 4],
|
|
35
45
|
"3" => [0xFFFFFFFFFFFFFFFF, 8]
|
|
36
46
|
}
|
|
37
|
-
def
|
|
47
|
+
def make_head(ib, plusbytes, d)
|
|
38
48
|
case plusbytes
|
|
39
49
|
when 0
|
|
40
50
|
[ib + d].pack("C")
|
|
@@ -51,52 +61,6 @@ module CBOR
|
|
|
51
61
|
end
|
|
52
62
|
end
|
|
53
63
|
|
|
54
|
-
def to_cbor
|
|
55
|
-
CBOR.encode(value)
|
|
56
|
-
end
|
|
57
|
-
def cbor_diagnostic(opts = {})
|
|
58
|
-
ret = value.cbor_diagnostic(opts)
|
|
59
|
-
if ei = options[:ei]
|
|
60
|
-
ret << "_#{ei}"
|
|
61
|
-
end
|
|
62
|
-
ret
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
class Xbox < Box
|
|
67
|
-
def to_cbor
|
|
68
|
-
enc = CBOR.encode(value)
|
|
69
|
-
if ei = options[:ei]
|
|
70
|
-
maxval, plusbytes = INTEGER_EI[ei]
|
|
71
|
-
if maxval
|
|
72
|
-
ib = enc.getbyte(0) & 0xE0
|
|
73
|
-
ai = enc.getbyte(0) & 0x1F
|
|
74
|
-
d, replacement = case ai
|
|
75
|
-
when 0...24; [ai, 0]
|
|
76
|
-
when 24; [enc[1..1].ord, 1]
|
|
77
|
-
when 25; [enc[1..2].unpack1("n"), 2]
|
|
78
|
-
when 26; [enc[1..4].unpack1("N"), 4]
|
|
79
|
-
when 27; [enc[1..8].unpack1("Q>"), 8]
|
|
80
|
-
# when 31; XXX conflicting EI information
|
|
81
|
-
else raise "unknown additional information #{ai} in ib #{ib}"
|
|
82
|
-
end
|
|
83
|
-
raise ArgumentError, "cbor-diagnostic: #{value} doesn't fit into encoding indicator _#{ei}':\n" unless d <= maxval
|
|
84
|
-
ib = enc.getbyte(0) & 0xE0
|
|
85
|
-
new_head = CBOR::Ibox.make_head(ib, plusbytes, d)
|
|
86
|
-
enc[0..replacement] = new_head
|
|
87
|
-
else
|
|
88
|
-
if ei == "" && value == ""
|
|
89
|
-
enc = CBOR.encode(value.cbor_stream!([]))
|
|
90
|
-
else
|
|
91
|
-
warn "*** cbor-diagnostic: ignoring unsupported encoding indicator _#{ei} for #{value.inspect}"
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
enc
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
class Ibox < Box
|
|
100
64
|
def to_cbor
|
|
101
65
|
if ei = options[:ei]
|
|
102
66
|
maxval, plusbytes = INTEGER_EI[ei]
|
|
@@ -110,7 +74,7 @@ module CBOR
|
|
|
110
74
|
end
|
|
111
75
|
raise ArgumentError, "cbor-diagnostic: #{value} doesn't fit into encoding indicator _#{ei}':\n" unless d <= maxval
|
|
112
76
|
|
|
113
|
-
|
|
77
|
+
make_head(ib, plusbytes, d)
|
|
114
78
|
|
|
115
79
|
# s = bignum_to_bytes(d)
|
|
116
80
|
# head(0xc0, TAG_BIGNUM_BASE + (ib >> 5))
|