edn-abnf 0.5.46 → 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 +15 -50
- data/edn-abnf.gemspec +1 -1
- data/lib/cbor-diag-support.rb +15 -57
- data/lib/cbor-diagnostic-app/b64.rb +1 -2
- data/lib/cbor-diagnostic-app/dt.rb +3 -4
- data/lib/cbor-diagnostic-app/h.rb +1 -9
- data/lib/cbor-diagnostic-app/hgrammar.rb +76 -435
- data/lib/cbor-diagnostic-app/ip.rb +3 -4
- data/lib/edn-abnf.rb +1 -12
- data/lib/parser/edn-util.rb +5 -13
- data/lib/parser/edngrammar.rb +4204 -7069
- metadata +2 -4
- data/lib/cbor-diagnostic-app/t1_b1.rb +0 -32
- 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
|
@@ -7,6 +7,12 @@ require 'json'
|
|
|
7
7
|
require 'cbor-pretty'
|
|
8
8
|
require 'cbor-deterministic'
|
|
9
9
|
|
|
10
|
+
# Temporary fix for name conflicts between cbor-diag and edn-abnf
|
|
11
|
+
diag_path = $LOAD_PATH.grep(/gems\/cbor-diag/).first
|
|
12
|
+
edn_path = $LOAD_PATH.grep(/gems\/edn-abnf/).first
|
|
13
|
+
$LOAD_PATH[$LOAD_PATH.index(diag_path)] = edn_path
|
|
14
|
+
$LOAD_PATH << diag_path
|
|
15
|
+
|
|
10
16
|
require_relative '../lib/edn-abnf.rb'
|
|
11
17
|
|
|
12
18
|
def snaky(name)
|
|
@@ -35,7 +41,7 @@ require 'ostruct'
|
|
|
35
41
|
|
|
36
42
|
$error = 0
|
|
37
43
|
|
|
38
|
-
output_formats = [:basic, :neat, :json, :yaml, :edn, :diag, :pretty, :hex, :cbor, :"test-vector"
|
|
44
|
+
output_formats = [:basic, :neat, :json, :yaml, :edn, :diag, :pretty, :hex, :cbor, :"test-vector"]
|
|
39
45
|
|
|
40
46
|
$options = OpenStruct.new
|
|
41
47
|
begin
|
|
@@ -76,31 +82,9 @@ begin
|
|
|
76
82
|
end
|
|
77
83
|
end
|
|
78
84
|
end
|
|
79
|
-
opts.on("-AAPP", "--app-later=APP", "Handle application extension later") do |v|
|
|
80
|
-
v.split(",") do |nm|
|
|
81
|
-
if nm =~ /\A[a-z][a-z0-9]*\z/
|
|
82
|
-
code = <<-RUBY
|
|
83
|
-
class CBOR_DIAG::App_#{nm}
|
|
84
|
-
def self.decode(app_prefix, s)
|
|
85
|
-
CBOR::Tagged.new(999, [app_prefix, s])
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
RUBY
|
|
89
|
-
eval(code, TOPLEVEL_BINDING, "(app-extension #{nm})")
|
|
90
|
-
else
|
|
91
|
-
raise ArgumentError.new("edn-abnf: app-extension name #{nm} not supported")
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
opts.on("--[no-]app-now", "Handle postponed application extensions now") do |v|
|
|
96
|
-
$options.app_now = v
|
|
97
|
-
end
|
|
98
85
|
opts.on("-f", "--[no-]fallback", "use tag 999 for unknown app-extensions") do |v|
|
|
99
86
|
$options.fallback = v
|
|
100
87
|
end
|
|
101
|
-
opts.on("-b", "--[no-]brace", "retry parsind with braces around added") do |v|
|
|
102
|
-
$options.brace = v
|
|
103
|
-
end
|
|
104
88
|
opts.on("-wCOL", "--wrap=COL", Integer, "EDN: wrap at column COL") do |v|
|
|
105
89
|
$options.wrap = v
|
|
106
90
|
end
|
|
@@ -109,19 +93,12 @@ begin
|
|
|
109
93
|
end
|
|
110
94
|
end
|
|
111
95
|
op.parse!
|
|
112
|
-
rescue LoadError => e
|
|
113
|
-
warn "Unsupported application extension '#{e.message.split('/')[1]}'"
|
|
114
|
-
exit 1
|
|
115
96
|
rescue Exception => e
|
|
116
|
-
warn e.inspect unless e.to_s == 'exit'
|
|
117
97
|
warn op unless e.to_s == 'exit'
|
|
118
98
|
exit 1
|
|
119
99
|
end
|
|
120
100
|
|
|
121
|
-
$feat = Set[]
|
|
122
|
-
|
|
123
101
|
if !$options.edn
|
|
124
|
-
$fn = ARGV.join(";")
|
|
125
102
|
ARGF.binmode if $options.cbor
|
|
126
103
|
$options.edn = ARGF.read
|
|
127
104
|
else
|
|
@@ -138,12 +115,11 @@ if $options.lines
|
|
|
138
115
|
exit 1
|
|
139
116
|
end
|
|
140
117
|
CSV.parse(edn_file) do |ok, ednin, out|
|
|
141
|
-
if
|
|
118
|
+
if ok[0] == "#"
|
|
142
119
|
puts "# #{ok}, #{ednin.inspect}, #{out}" if $options.verbose
|
|
143
120
|
next
|
|
144
121
|
end
|
|
145
122
|
if ok[0] == "x"
|
|
146
|
-
warn "#{[ok, ednin, out].inspect}" unless ednin
|
|
147
123
|
result = tree_from_edn_possibly_hex(ednin)
|
|
148
124
|
result_hex = result.to_cbor.hexi
|
|
149
125
|
result_diag = result.cbor_diagnostic
|
|
@@ -160,8 +136,8 @@ if $options.lines
|
|
|
160
136
|
end
|
|
161
137
|
begin
|
|
162
138
|
ok = ok == "="
|
|
163
|
-
puts "➔ #{ok
|
|
164
|
-
result = tree_from_edn_possibly_hex(ednin
|
|
139
|
+
puts "➔ #{ok}, #{ednin}, #{out}" if $options.verbose
|
|
140
|
+
result = tree_from_edn_possibly_hex(ednin)
|
|
165
141
|
diag = result.cbor_diagnostic
|
|
166
142
|
if out == diag && !ok
|
|
167
143
|
puts "** ≠ / #{diag.inspect} / #{out.inspect}"
|
|
@@ -175,7 +151,7 @@ if $options.lines
|
|
|
175
151
|
end
|
|
176
152
|
puts "reparsed / #{diag.inspect} / #{out.inspect}" if $options.verbose
|
|
177
153
|
end
|
|
178
|
-
rescue
|
|
154
|
+
rescue ArgumentError => e
|
|
179
155
|
if ok
|
|
180
156
|
puts "** #{e} / #{result.inspect} / #{out.inspect}"
|
|
181
157
|
$error += 1
|
|
@@ -198,31 +174,20 @@ end
|
|
|
198
174
|
|
|
199
175
|
begin
|
|
200
176
|
if $options.cbor
|
|
201
|
-
result = CBOR.
|
|
177
|
+
result = CBOR.decode(edn_file)
|
|
202
178
|
else
|
|
203
|
-
|
|
204
|
-
begin
|
|
205
|
-
edn = EDN.from_edn(edn_file)
|
|
206
|
-
rescue ArgumentError # Parse error
|
|
207
|
-
edn = EDN.from_edn("{\n" + edn_file + "}\n")
|
|
208
|
-
end
|
|
209
|
-
else
|
|
210
|
-
edn = EDN.from_edn(edn_file)
|
|
211
|
-
end
|
|
179
|
+
edn = EDN.from_edn(edn_file)
|
|
212
180
|
result = edn.tree # XXX .tree?
|
|
213
181
|
end
|
|
214
182
|
rescue CBOR_DIAG::AppParseError, ArgumentError => e
|
|
215
|
-
|
|
216
|
-
warn e.backtrace if $options.verbose
|
|
183
|
+
puts "** #{e}"
|
|
217
184
|
exit 1
|
|
218
185
|
rescue CBOR::OutOfBytesError, RuntimeError, JSON::GeneratorError => e
|
|
219
|
-
|
|
186
|
+
puts "** (encoded CBOR input:) #{e}"
|
|
220
187
|
exit 1
|
|
221
188
|
end
|
|
222
189
|
|
|
223
190
|
case $options.target
|
|
224
|
-
when :feat
|
|
225
|
-
puts [$fn, $feat.to_a.join(",")].join(":")
|
|
226
191
|
when :basic
|
|
227
192
|
pp result
|
|
228
193
|
when :neat, :json
|
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
|
@@ -9,13 +9,10 @@ module CBOR
|
|
|
9
9
|
def to_s
|
|
10
10
|
value.to_s
|
|
11
11
|
end
|
|
12
|
-
def to_str
|
|
13
|
-
value.to_str
|
|
14
|
-
end
|
|
15
12
|
def inspect
|
|
16
13
|
"#<CBOR::Box #{self.class} value=#{value.inspect}, options=#{options.inspect}>"
|
|
17
14
|
end
|
|
18
|
-
def self.
|
|
15
|
+
def self.from_number(n, options={})
|
|
19
16
|
case n
|
|
20
17
|
when Box
|
|
21
18
|
n.class.new(n.value, n.options.merge(options))
|
|
@@ -23,13 +20,23 @@ module CBOR
|
|
|
23
20
|
Ibox.new(n, options.dup)
|
|
24
21
|
when ::Float
|
|
25
22
|
Fbox.new(n, options.dup)
|
|
26
|
-
when ::String, ::Array, ::Hash, ::CBOR::Tagged
|
|
27
|
-
Xbox.new(n, options.dup)
|
|
28
23
|
else
|
|
29
24
|
raise ArgumentError, "cbor-diagnostic: can't box number from #{n.inspect}':\n"
|
|
30
25
|
end
|
|
31
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
|
|
32
38
|
|
|
39
|
+
class Ibox < Box
|
|
33
40
|
INTEGER_EI = {
|
|
34
41
|
"i" => [23, 0],
|
|
35
42
|
"0" => [0xFF, 1],
|
|
@@ -37,7 +44,7 @@ module CBOR
|
|
|
37
44
|
"2" => [0xFFFFFFFF, 4],
|
|
38
45
|
"3" => [0xFFFFFFFFFFFFFFFF, 8]
|
|
39
46
|
}
|
|
40
|
-
def
|
|
47
|
+
def make_head(ib, plusbytes, d)
|
|
41
48
|
case plusbytes
|
|
42
49
|
when 0
|
|
43
50
|
[ib + d].pack("C")
|
|
@@ -54,55 +61,6 @@ module CBOR
|
|
|
54
61
|
end
|
|
55
62
|
end
|
|
56
63
|
|
|
57
|
-
def to_cbor
|
|
58
|
-
CBOR.encode(value)
|
|
59
|
-
end
|
|
60
|
-
def cbor_diagnostic(opts = {})
|
|
61
|
-
ret = value.cbor_diagnostic(opts)
|
|
62
|
-
if ei = options[:ei]
|
|
63
|
-
ret << "_#{ei}"
|
|
64
|
-
end
|
|
65
|
-
ret
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
class Xbox < Box
|
|
70
|
-
def encoding; value.encoding end
|
|
71
|
-
def size; value.size end
|
|
72
|
-
def b; value.b end
|
|
73
|
-
def to_cbor
|
|
74
|
-
enc = CBOR.encode(value)
|
|
75
|
-
if ei = options[:ei]
|
|
76
|
-
maxval, plusbytes = INTEGER_EI[ei]
|
|
77
|
-
if maxval
|
|
78
|
-
ib = enc.getbyte(0) & 0xE0
|
|
79
|
-
ai = enc.getbyte(0) & 0x1F
|
|
80
|
-
d, replacement = case ai
|
|
81
|
-
when 0...24; [ai, 0]
|
|
82
|
-
when 24; [enc[1..1].ord, 1]
|
|
83
|
-
when 25; [enc[1..2].unpack1("n"), 2]
|
|
84
|
-
when 26; [enc[1..4].unpack1("N"), 4]
|
|
85
|
-
when 27; [enc[1..8].unpack1("Q>"), 8]
|
|
86
|
-
# when 31; XXX conflicting EI information
|
|
87
|
-
else raise "unknown additional information #{ai} in ib #{ib}"
|
|
88
|
-
end
|
|
89
|
-
raise ArgumentError, "cbor-diagnostic: #{value} doesn't fit into encoding indicator _#{ei}':\n" unless d <= maxval
|
|
90
|
-
ib = enc.getbyte(0) & 0xE0
|
|
91
|
-
new_head = CBOR::Ibox.make_head(ib, plusbytes, d)
|
|
92
|
-
enc[0..replacement] = new_head
|
|
93
|
-
else
|
|
94
|
-
if ei == "" && value == ""
|
|
95
|
-
enc = CBOR.encode(value.cbor_stream!([]))
|
|
96
|
-
else
|
|
97
|
-
warn "*** cbor-diagnostic: ignoring unsupported encoding indicator _#{ei} for #{value.inspect}"
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
enc
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
class Ibox < Box
|
|
106
64
|
def to_cbor
|
|
107
65
|
if ei = options[:ei]
|
|
108
66
|
maxval, plusbytes = INTEGER_EI[ei]
|
|
@@ -116,7 +74,7 @@ module CBOR
|
|
|
116
74
|
end
|
|
117
75
|
raise ArgumentError, "cbor-diagnostic: #{value} doesn't fit into encoding indicator _#{ei}':\n" unless d <= maxval
|
|
118
76
|
|
|
119
|
-
|
|
77
|
+
make_head(ib, plusbytes, d)
|
|
120
78
|
|
|
121
79
|
# s = bignum_to_bytes(d)
|
|
122
80
|
# head(0xc0, TAG_BIGNUM_BASE + (ib >> 5))
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
require_relative "b64grammar.rb"
|
|
2
2
|
|
|
3
3
|
class CBOR_DIAG::App_b64
|
|
4
|
-
def self.decode(
|
|
4
|
+
def self.decode(_, s)
|
|
5
5
|
parser = B64GRAMMARParser.new # B? XXX
|
|
6
|
-
s = EDN.to_one_string(prefix, s)
|
|
7
6
|
ast = parser.parse(s)
|
|
8
7
|
if !ast
|
|
9
8
|
raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in b64'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
|
|
@@ -7,9 +7,8 @@ require 'time'
|
|
|
7
7
|
# Probably should copy over Time#xmlschema and fix that for us.
|
|
8
8
|
|
|
9
9
|
class CBOR_DIAG::App_dt
|
|
10
|
-
def self.decode(
|
|
10
|
+
def self.decode(app_prefix, s)
|
|
11
11
|
parser = DTGRAMMARParser.new
|
|
12
|
-
s = EDN.to_one_string(prefix, s)
|
|
13
12
|
ast = parser.parse(s)
|
|
14
13
|
if !ast
|
|
15
14
|
raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in dt'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
|
|
@@ -22,13 +21,13 @@ class CBOR_DIAG::App_dt
|
|
|
22
21
|
else
|
|
23
22
|
t.to_i
|
|
24
23
|
end
|
|
25
|
-
case
|
|
24
|
+
case app_prefix
|
|
26
25
|
when 'dt'
|
|
27
26
|
tv
|
|
28
27
|
when 'DT'
|
|
29
28
|
CBOR::Tagged.new(1, tv)
|
|
30
29
|
else
|
|
31
|
-
fail
|
|
30
|
+
fail app_prefix
|
|
32
31
|
end
|
|
33
32
|
end
|
|
34
33
|
end
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
require_relative "hgrammar.rb"
|
|
2
2
|
|
|
3
3
|
class CBOR_DIAG::App_h
|
|
4
|
-
def self.decode(
|
|
4
|
+
def self.decode(_, s)
|
|
5
5
|
parser = HGRAMMARParser.new
|
|
6
|
-
s = EDN.to_one_string(prefix, s)
|
|
7
|
-
s.scan(/#.*|\s|\/[^\/]*\//).each do |comment|
|
|
8
|
-
case comment
|
|
9
|
-
in /\A\s\z/; $feat << :h_comment_space
|
|
10
|
-
in /\A#.*\z/; $feat << :h_comment_hash
|
|
11
|
-
in /\A\/[^\/]*\/\z/; $feat << :h_comment_slash
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
6
|
ast = parser.parse(s)
|
|
15
7
|
if !ast
|
|
16
8
|
raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in h'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
|