edn-abnf 0.5.33 → 0.5.35

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: dc4cf907d32b47cc51a4326a110558a79a25ba4733873a5d6d84fd52f4e54903
4
- data.tar.gz: 5424613f24e9fb8defca526961a428bba49832c57e952e848d8cbdd1b7a06f99
3
+ metadata.gz: 066fe883e4f63f1d4f093c32c280a69ad282f587bd289224b5f9c3c869be7e73
4
+ data.tar.gz: 34bccaaa9015884fbb9bc9dcc9f8c1eba352dc0178a5ba33c6a71305c2d2b51c
5
5
  SHA512:
6
- metadata.gz: a0b733fbad7e31b0f371fb832c86e958476ee29da4a83d06673b216829cca62a7262f719d378480a9f315997554883df44b1fddbe47082c4af28c14727e630d1
7
- data.tar.gz: 54abb14762231cfb8dbfd87a21b4f86594f0cbcc666f3333920dd2922f104f41a4cb9fc9277376dee952b831a92c563a056c6485dbf79e3a6e7e088272d1e39e
6
+ metadata.gz: 5ca8b9c5816196a430547ebe8ed8b6b90599161b41f51443bb319cec2b86220ffe158df62f5520afbd67cb3450ecebc3ce0e970c90e8f3040f7dd1eb355f7543
7
+ data.tar.gz: b1bfc0fc1f5b6f076837b47900ceb9962163e32a488ef3c89d63ac1135eec991c7c8d3fa69cbf5355d7af8757c232f7fd89cd8ffdecd38a5b1ea8ae6152007b6
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.33"
3
+ s.version = "0.5.35"
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_number(n, options={})
15
+ def self.from_instance(n, options={})
16
16
  case n
17
17
  when Box
18
18
  n.class.new(n.value, n.options.merge(options))
@@ -20,23 +20,13 @@ 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)
23
25
  else
24
26
  raise ArgumentError, "cbor-diagnostic: can't box number from #{n.inspect}':\n"
25
27
  end
26
28
  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
38
29
 
39
- class Ibox < Box
40
30
  INTEGER_EI = {
41
31
  "i" => [23, 0],
42
32
  "0" => [0xFF, 1],
@@ -44,7 +34,7 @@ module CBOR
44
34
  "2" => [0xFFFFFFFF, 4],
45
35
  "3" => [0xFFFFFFFFFFFFFFFF, 8]
46
36
  }
47
- def make_head(ib, plusbytes, d)
37
+ def self.make_head(ib, plusbytes, d)
48
38
  case plusbytes
49
39
  when 0
50
40
  [ib + d].pack("C")
@@ -61,6 +51,52 @@ module CBOR
61
51
  end
62
52
  end
63
53
 
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
64
100
  def to_cbor
65
101
  if ei = options[:ei]
66
102
  maxval, plusbytes = INTEGER_EI[ei]
@@ -74,7 +110,7 @@ module CBOR
74
110
  end
75
111
  raise ArgumentError, "cbor-diagnostic: #{value} doesn't fit into encoding indicator _#{ei}':\n" unless d <= maxval
76
112
 
77
- make_head(ib, plusbytes, d)
113
+ CBOR::Ibox.make_head(ib, plusbytes, d)
78
114
 
79
115
  # s = bignum_to_bytes(d)
80
116
  # head(0xc0, TAG_BIGNUM_BASE + (ib >> 5))
@@ -197,10 +197,12 @@ module EDNGRAMMAR
197
197
 
198
198
  module String11
199
199
  def ast
200
+ val = elements[0].ast
200
201
  if ei = spec.text_value[1..-1]
201
- warn "*** ignoring unimplemented encoding indicator #{ei.inspect} for #{elements[0].text_value}"
202
+ # warn "*** implementing encoding indicator #{ei.inspect} for #{elements[0].text_value}"
203
+ val = CBOR::Box.from_instance(val, {ei: ei})
202
204
  end
203
- elements[0].ast
205
+ val
204
206
  end
205
207
  end
206
208
 
@@ -452,7 +454,7 @@ module EDNGRAMMAR
452
454
 
453
455
  if ei = spec.text_value[1..-1]
454
456
  # warn "*** implementing encoding indicator #{ei.inspect} for #{elements[0].text_value}"
455
- val = CBOR::Box.from_number(val, {ei: ei})
457
+ val = CBOR::Box.from_instance(val, {ei: ei})
456
458
  end
457
459
  val
458
460
  end
@@ -1800,10 +1802,12 @@ module EDNGRAMMAR
1800
1802
 
1801
1803
  module Tagged1
1802
1804
  def ast
1805
+ val = CBOR::Tagged.new(uint.text_value.to_i, item.ast)
1803
1806
  if ei = spec.text_value[1..-1]
1804
- warn "*** ignoring unimplemented encoding indicator #{ei.inspect} after tag number #{uint.text_value}"
1807
+ val = CBOR::Box.from_instance(val, {ei: ei})
1808
+ # warn "*** implementing encoding indicator #{ei.inspect} after tag number #{uint.text_value}"
1805
1809
  end
1806
- CBOR::Tagged.new(uint.text_value.to_i, item.ast)
1810
+ val
1807
1811
  end
1808
1812
  end
1809
1813
 
@@ -3084,7 +3088,8 @@ module EDNGRAMMAR
3084
3088
  if ei == ""
3085
3089
  r.cbor_stream!
3086
3090
  elsif ei
3087
- warn "*** ignoring unimplemented encoding indicator #{ei.inspect} after ["
3091
+ r = CBOR::Box.from_instance(r, {ei: ei})
3092
+ # warn "*** implementing XXX encoding indicator #{ei.inspect} after ["
3088
3093
  end
3089
3094
  r
3090
3095
  end
@@ -3271,7 +3276,8 @@ module EDNGRAMMAR
3271
3276
  if ei == ""
3272
3277
  r.cbor_stream!
3273
3278
  elsif ei
3274
- warn "*** ignoring unimplemented encoding indicator #{ei.inspect} after {" # }
3279
+ r = CBOR::Box.from_instance(r, {ei: ei})
3280
+ # warn "*** implementing encoding indicator #{ei.inspect} after {" # }
3275
3281
  end
3276
3282
  r
3277
3283
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edn-abnf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.33
4
+ version: 0.5.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann