edn-abnf 0.5.43 → 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: fe28153b880f4ed0b622b3eb4405d8eb72f480729c25d8b30edee80e95e85a74
4
- data.tar.gz: e10f8b6e293a1ed72f1e4aed231339318752d023e1ddf3d7af94e161c57fc2dd
3
+ metadata.gz: 35b0986f4a0d059f1223e057a2cd2ea5c6852e2a682ad5fa1a3c1e135b2446c7
4
+ data.tar.gz: 98f4bdb66e78f3b3c85edd88bcd18dbb3a832dd9153d178a79f89baf911ac109
5
5
  SHA512:
6
- metadata.gz: 4e91ccd12231bc740812ba3f774cab99fa3e307b80bd5f729ec0429e8cbd8b99fa74986e8f094c6a2176f6a8dff20764b7645d5d20724b8f7c82957bbfaa52ef
7
- data.tar.gz: a4834aa184a7b22a57d5a729939f10a3bbde519900faf6199b0609dcbb5473728356f053d5a6b16c0b22ea9c6507faeab23ff014af02e67303dec735259cd2e6
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)
@@ -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,11 +93,7 @@ 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
@@ -135,12 +115,11 @@ if $options.lines
135
115
  exit 1
136
116
  end
137
117
  CSV.parse(edn_file) do |ok, ednin, out|
138
- if !ok || ok[0] == "#" || ok == "op"
118
+ if ok[0] == "#"
139
119
  puts "# #{ok}, #{ednin.inspect}, #{out}" if $options.verbose
140
120
  next
141
121
  end
142
122
  if ok[0] == "x"
143
- warn "#{[ok, ednin, out].inspect}" unless ednin
144
123
  result = tree_from_edn_possibly_hex(ednin)
145
124
  result_hex = result.to_cbor.hexi
146
125
  result_diag = result.cbor_diagnostic
@@ -157,8 +136,8 @@ if $options.lines
157
136
  end
158
137
  begin
159
138
  ok = ok == "="
160
- puts "➔ #{ok.inspect}, #{ednin.inspect}, #{out.inspect}" if $options.verbose
161
- result = tree_from_edn_possibly_hex(ednin || "")
139
+ puts "➔ #{ok}, #{ednin}, #{out}" if $options.verbose
140
+ result = tree_from_edn_possibly_hex(ednin)
162
141
  diag = result.cbor_diagnostic
163
142
  if out == diag && !ok
164
143
  puts "** ≠ / #{diag.inspect} / #{out.inspect}"
@@ -172,7 +151,7 @@ if $options.lines
172
151
  end
173
152
  puts "reparsed / #{diag.inspect} / #{out.inspect}" if $options.verbose
174
153
  end
175
- rescue CBOR_DIAG::AppParseError, ArgumentError => e
154
+ rescue ArgumentError => e
176
155
  if ok
177
156
  puts "** #{e} / #{result.inspect} / #{out.inspect}"
178
157
  $error += 1
@@ -197,23 +176,14 @@ begin
197
176
  if $options.cbor
198
177
  result = CBOR.decode(edn_file)
199
178
  else
200
- if $options.brace
201
- begin
202
- edn = EDN.from_edn(edn_file)
203
- rescue ArgumentError # Parse error
204
- edn = EDN.from_edn("{\n" + edn_file + "}\n")
205
- end
206
- else
207
- edn = EDN.from_edn(edn_file)
208
- end
179
+ edn = EDN.from_edn(edn_file)
209
180
  result = edn.tree # XXX .tree?
210
181
  end
211
182
  rescue CBOR_DIAG::AppParseError, ArgumentError => e
212
- warn "** #{e}"
213
- warn e.backtrace if $options.verbose
183
+ puts "** #{e}"
214
184
  exit 1
215
185
  rescue CBOR::OutOfBytesError, RuntimeError, JSON::GeneratorError => e
216
- warn "** (encoded CBOR input:) #{e}"
186
+ puts "** (encoded CBOR input:) #{e}"
217
187
  exit 1
218
188
  end
219
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.43"
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"
@@ -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.from_instance(n, options={})
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 self.make_head(ib, plusbytes, d)
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
- CBOR::Ibox.make_head(ib, plusbytes, d)
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(prefix, s)
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(prefix, s)
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 prefix
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 prefix
30
+ fail app_prefix
32
31
  end
33
32
  end
34
33
  end
@@ -1,9 +1,8 @@
1
1
  require_relative "hgrammar.rb"
2
2
 
3
3
  class CBOR_DIAG::App_h
4
- def self.decode(prefix, s)
4
+ def self.decode(_, s)
5
5
  parser = HGRAMMARParser.new
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 h'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)