edn-abnf 0.5.39 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17c5fde6eec17c35da2e94196c5eb582ef05e8586c997c38b989f044460c9a03
4
- data.tar.gz: 964e47d82a247a6b17a0b479a8b2ac1dacf284baa5068a4458938726980de944
3
+ metadata.gz: 35b0986f4a0d059f1223e057a2cd2ea5c6852e2a682ad5fa1a3c1e135b2446c7
4
+ data.tar.gz: 98f4bdb66e78f3b3c85edd88bcd18dbb3a832dd9153d178a79f89baf911ac109
5
5
  SHA512:
6
- metadata.gz: 1d1b16c8fcc99e5cad651830b0ddb515b1321b2f177951376128fc26fc62fd5afbf1848a119876ad54557042192dea72a679bffc3b4d1bd515bc41b2520c4558
7
- data.tar.gz: 8bc3c115e0b0576c4796d65846064747a7254fd9e9082ca4a99048d3130f485134a8fdd5a40d677a2239b50acb7b3a9d69c69c0a0c52609f43ecbc8a71881a4e
6
+ metadata.gz: 3e7ce39d92102381078c9d3da002dd2362808fd9c7faaca0676fbdc532d430ffeb85c6c6f770b34466571814529c66aaa172b26a179e26d8b081bea9cb08b5af
7
+ data.tar.gz: 62c3946d702aec9897e4149021e3798459abbe93927e87942faec2df9373190b4d86877e9dfd01ff5f8b40c3635fafd0203f18e2f4244dc22b8d713bc4c5361b
data/bin/edn-abnf CHANGED
@@ -82,31 +82,9 @@ begin
82
82
  end
83
83
  end
84
84
  end
85
- opts.on("-AAPP", "--app-later=APP", "Handle application extension later") do |v|
86
- v.split(",") do |nm|
87
- if nm =~ /\A[a-z][a-z0-9]*\z/
88
- code = <<-RUBY
89
- class CBOR_DIAG::App_#{nm}
90
- def self.decode(app_prefix, s)
91
- CBOR::Tagged.new(999, [app_prefix, s])
92
- end
93
- end
94
- RUBY
95
- eval(code, TOPLEVEL_BINDING, "(app-extension #{nm})")
96
- else
97
- raise ArgumentError.new("edn-abnf: app-extension name #{nm} not supported")
98
- end
99
- end
100
- end
101
- opts.on("--[no-]app-now", "Handle postponed application extensions now") do |v|
102
- $options.app_now = v
103
- end
104
85
  opts.on("-f", "--[no-]fallback", "use tag 999 for unknown app-extensions") do |v|
105
86
  $options.fallback = v
106
87
  end
107
- opts.on("-b", "--[no-]brace", "retry parsind with braces around added") do |v|
108
- $options.brace = v
109
- end
110
88
  opts.on("-wCOL", "--wrap=COL", Integer, "EDN: wrap at column COL") do |v|
111
89
  $options.wrap = v
112
90
  end
@@ -115,11 +93,7 @@ begin
115
93
  end
116
94
  end
117
95
  op.parse!
118
- rescue LoadError => e
119
- warn "Unsupported application extension '#{e.message.split('/')[1]}'"
120
- exit 1
121
96
  rescue Exception => e
122
- warn e.inspect unless e.to_s == 'exit'
123
97
  warn op unless e.to_s == 'exit'
124
98
  exit 1
125
99
  end
@@ -141,12 +115,11 @@ if $options.lines
141
115
  exit 1
142
116
  end
143
117
  CSV.parse(edn_file) do |ok, ednin, out|
144
- if !ok || ok[0] == "#" || ok == "op"
118
+ if ok[0] == "#"
145
119
  puts "# #{ok}, #{ednin.inspect}, #{out}" if $options.verbose
146
120
  next
147
121
  end
148
122
  if ok[0] == "x"
149
- warn "#{[ok, ednin, out].inspect}" unless ednin
150
123
  result = tree_from_edn_possibly_hex(ednin)
151
124
  result_hex = result.to_cbor.hexi
152
125
  result_diag = result.cbor_diagnostic
@@ -163,8 +136,8 @@ if $options.lines
163
136
  end
164
137
  begin
165
138
  ok = ok == "="
166
- puts "➔ #{ok.inspect}, #{ednin.inspect}, #{out.inspect}" if $options.verbose
167
- result = tree_from_edn_possibly_hex(ednin || "")
139
+ puts "➔ #{ok}, #{ednin}, #{out}" if $options.verbose
140
+ result = tree_from_edn_possibly_hex(ednin)
168
141
  diag = result.cbor_diagnostic
169
142
  if out == diag && !ok
170
143
  puts "** ≠ / #{diag.inspect} / #{out.inspect}"
@@ -178,7 +151,7 @@ if $options.lines
178
151
  end
179
152
  puts "reparsed / #{diag.inspect} / #{out.inspect}" if $options.verbose
180
153
  end
181
- rescue CBOR_DIAG::AppParseError, ArgumentError => e
154
+ rescue ArgumentError => e
182
155
  if ok
183
156
  puts "** #{e} / #{result.inspect} / #{out.inspect}"
184
157
  $error += 1
@@ -203,22 +176,14 @@ begin
203
176
  if $options.cbor
204
177
  result = CBOR.decode(edn_file)
205
178
  else
206
- if $options.brace
207
- begin
208
- edn = EDN.from_edn(edn_file)
209
- rescue ArgumentError # Parse error
210
- edn = EDN.from_edn("{\n" + edn_file + "}\n")
211
- end
212
- else
213
- edn = EDN.from_edn(edn_file)
214
- end
179
+ edn = EDN.from_edn(edn_file)
215
180
  result = edn.tree # XXX .tree?
216
181
  end
217
182
  rescue CBOR_DIAG::AppParseError, ArgumentError => e
218
- warn "** #{e}"
183
+ puts "** #{e}"
219
184
  exit 1
220
185
  rescue CBOR::OutOfBytesError, RuntimeError, JSON::GeneratorError => e
221
- warn "** (encoded CBOR input:) #{e}"
186
+ puts "** (encoded CBOR input:) #{e}"
222
187
  exit 1
223
188
  end
224
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.5.39"
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"
@@ -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.from_instance(n, options={})
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 self.make_head(ib, plusbytes, d)
47
+ def make_head(ib, plusbytes, d)
38
48
  case plusbytes
39
49
  when 0
40
50
  [ib + d].pack("C")
@@ -51,55 +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 encoding; value.encoding end
68
- def size; value.size end
69
- def b; value.b end
70
- def to_cbor
71
- enc = CBOR.encode(value)
72
- if ei = options[:ei]
73
- maxval, plusbytes = INTEGER_EI[ei]
74
- if maxval
75
- ib = enc.getbyte(0) & 0xE0
76
- ai = enc.getbyte(0) & 0x1F
77
- d, replacement = case ai
78
- when 0...24; [ai, 0]
79
- when 24; [enc[1..1].ord, 1]
80
- when 25; [enc[1..2].unpack1("n"), 2]
81
- when 26; [enc[1..4].unpack1("N"), 4]
82
- when 27; [enc[1..8].unpack1("Q>"), 8]
83
- # when 31; XXX conflicting EI information
84
- else raise "unknown additional information #{ai} in ib #{ib}"
85
- end
86
- raise ArgumentError, "cbor-diagnostic: #{value} doesn't fit into encoding indicator _#{ei}':\n" unless d <= maxval
87
- ib = enc.getbyte(0) & 0xE0
88
- new_head = CBOR::Ibox.make_head(ib, plusbytes, d)
89
- enc[0..replacement] = new_head
90
- else
91
- if ei == "" && value == ""
92
- enc = CBOR.encode(value.cbor_stream!([]))
93
- else
94
- warn "*** cbor-diagnostic: ignoring unsupported encoding indicator _#{ei} for #{value.inspect}"
95
- end
96
- end
97
- end
98
- enc
99
- end
100
- end
101
-
102
- class Ibox < Box
103
64
  def to_cbor
104
65
  if ei = options[:ei]
105
66
  maxval, plusbytes = INTEGER_EI[ei]
@@ -113,7 +74,7 @@ module CBOR
113
74
  end
114
75
  raise ArgumentError, "cbor-diagnostic: #{value} doesn't fit into encoding indicator _#{ei}':\n" unless d <= maxval
115
76
 
116
- CBOR::Ibox.make_head(ib, plusbytes, d)
77
+ make_head(ib, plusbytes, d)
117
78
 
118
79
  # s = bignum_to_bytes(d)
119
80
  # head(0xc0, TAG_BIGNUM_BASE + (ib >> 5))