edn-abnf 0.5.36 → 0.5.38

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: 157806a4265773392a50ec9c5176afeab9230ed0dc099cf6ccff715bc7c4b40a
4
- data.tar.gz: 431fdbcefd2390e1ecd12ca2d14054cccab591899a3f2c0cc2f3f88cc10ca59c
3
+ metadata.gz: 66e20181db646536c0fa4eabd1527ba580085825de03eb89e0e26f4437e215ed
4
+ data.tar.gz: 15e82108df4dede7ab0dc29bebbfc7c6fc5e6e028a3a16de86615d3691c6db9d
5
5
  SHA512:
6
- metadata.gz: 0f2452473677f916784c1460c7216259d9e1dee8ab8822a059ff0294b0f3092473558783afbcff441ba1d2ae7ea3be461f5222bdc651e4fa53ebb70a705afe75
7
- data.tar.gz: 383d5417a02d35216bc4d5d609a2f99ce68c5dc36cc373dec34c32d63aaf1f5249438e014449975ba9183cbb4f1251ade30273335d06a5a78b55cff91b427059
6
+ metadata.gz: a95ef3f7c9c857cdbff5b6d1e60854fc6c268afc3d98052c3f236686505cd10b62e6e52e8f320b35b0514039b0e77d1fb3ab09f4bc561dd4741654970fa1d4b0
7
+ data.tar.gz: 72ba10c6341a342dc2b19030fb0d0993094564fc398c24ec8673911ce9453eca0950e7a954829c413c348e71625481038612025a3a34cc506d346e99580b0776
data/bin/edn-abnf CHANGED
@@ -82,9 +82,31 @@ 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
85
104
  opts.on("-f", "--[no-]fallback", "use tag 999 for unknown app-extensions") do |v|
86
105
  $options.fallback = v
87
106
  end
107
+ opts.on("-b", "--[no-]brace", "retry parsind with braces around added") do |v|
108
+ $options.brace = v
109
+ end
88
110
  opts.on("-wCOL", "--wrap=COL", Integer, "EDN: wrap at column COL") do |v|
89
111
  $options.wrap = v
90
112
  end
@@ -93,7 +115,11 @@ begin
93
115
  end
94
116
  end
95
117
  op.parse!
118
+ rescue LoadError => e
119
+ warn "Unsupported application extension '#{e.message.split('/')[1]}'"
120
+ exit 1
96
121
  rescue Exception => e
122
+ warn e.inspect unless e.to_s == 'exit'
97
123
  warn op unless e.to_s == 'exit'
98
124
  exit 1
99
125
  end
@@ -177,7 +203,15 @@ begin
177
203
  if $options.cbor
178
204
  result = CBOR.decode(edn_file)
179
205
  else
180
- edn = EDN.from_edn(edn_file)
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
181
215
  result = edn.tree # XXX .tree?
182
216
  end
183
217
  rescue CBOR_DIAG::AppParseError, ArgumentError => e
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.36"
3
+ s.version = "0.5.38"
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"
@@ -64,6 +64,8 @@ module CBOR
64
64
  end
65
65
 
66
66
  class Xbox < Box
67
+ def encoding; value.encoding end
68
+ def size; value.size end
67
69
  def to_cbor
68
70
  enc = CBOR.encode(value)
69
71
  if ei = options[:ei]
@@ -1802,7 +1802,14 @@ module EDNGRAMMAR
1802
1802
 
1803
1803
  module Tagged1
1804
1804
  def ast
1805
- val = CBOR::Tagged.new(uint.text_value.to_i, item.ast)
1805
+ tagnum = uint.text_value.to_i
1806
+ tagval = item.ast
1807
+ if tagnum == 999 && $options.app_now
1808
+ app, args = tagval
1809
+ val = ::EDNGRAMMAR::APPS[app].decode(app, *args)
1810
+ else
1811
+ val = CBOR::Tagged.new(tagnum, tagval)
1812
+ end
1806
1813
  if ei = spec.text_value[1..-1]
1807
1814
  val = CBOR::Box.from_instance(val, {ei: ei})
1808
1815
  # warn "*** implementing encoding indicator #{ei.inspect} after tag number #{uint.text_value}"
@@ -4785,7 +4792,12 @@ module EDNGRAMMAR
4785
4792
  unless Set[*strings.map(&:encoding)].size == 1
4786
4793
  warn "*** mixed streamstring #{strings.cbor_diagnostic}"
4787
4794
  end
4788
- strings.join.cbor_stream!(strings.map(&:size))
4795
+ strings.each do |s|
4796
+ if CBOR::Xbox === s && (ei = s.options[:ei])
4797
+ warn "*** unimplemented encoding indicator #{ei.inspect} for #{s.inspect}"
4798
+ end
4799
+ end
4800
+ strings.join.cbor_stream!(strings.map(&:size)) # XXX loses EI
4789
4801
  end
4790
4802
  end
4791
4803
 
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.36
4
+ version: 0.5.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann