edn-abnf 0.5.41 → 0.5.43

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: 0fdf950deb0a96865e863046f39d4071d3856ce24fc476c1f96077457002b8d8
4
- data.tar.gz: 3920f2ebfb1b4dacc025d86f8bcb6fc2ed3e59694ec174ba6c1f50ccd5650dc6
3
+ metadata.gz: fe28153b880f4ed0b622b3eb4405d8eb72f480729c25d8b30edee80e95e85a74
4
+ data.tar.gz: e10f8b6e293a1ed72f1e4aed231339318752d023e1ddf3d7af94e161c57fc2dd
5
5
  SHA512:
6
- metadata.gz: 14148161150b25960f24543bb03c673632af5c8302a5773e15863b88ade9c3a9ef20e6db2ec67bbb3a58bada47c673d8f32d877df11bd0a79d9619ab43e42c1f
7
- data.tar.gz: 2ad6f10909561f0a87e59c87efdbecedb1b6bbf14a559fa59c6154d9d45d550a91e2e36850457c415118d6de93b8968a9b3053e65ad1d25de368e60e54aee350
6
+ metadata.gz: 4e91ccd12231bc740812ba3f774cab99fa3e307b80bd5f729ec0429e8cbd8b99fa74986e8f094c6a2176f6a8dff20764b7645d5d20724b8f7c82957bbfaa52ef
7
+ data.tar.gz: a4834aa184a7b22a57d5a729939f10a3bbde519900faf6199b0609dcbb5473728356f053d5a6b16c0b22ea9c6507faeab23ff014af02e67303dec735259cd2e6
data/bin/edn-abnf CHANGED
@@ -7,12 +7,6 @@ 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
-
16
10
  require_relative '../lib/edn-abnf.rb'
17
11
 
18
12
  def snaky(name)
@@ -216,6 +210,7 @@ begin
216
210
  end
217
211
  rescue CBOR_DIAG::AppParseError, ArgumentError => e
218
212
  warn "** #{e}"
213
+ warn e.backtrace if $options.verbose
219
214
  exit 1
220
215
  rescue CBOR::OutOfBytesError, RuntimeError, JSON::GeneratorError => e
221
216
  warn "** (encoded CBOR input:) #{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.41"
3
+ s.version = "0.5.43"
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,6 +9,9 @@ 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
12
15
  def inspect
13
16
  "#<CBOR::Box #{self.class} value=#{value.inspect}, options=#{options.inspect}>"
14
17
  end
@@ -1,8 +1,9 @@
1
1
  require_relative "b64grammar.rb"
2
2
 
3
3
  class CBOR_DIAG::App_b64
4
- def self.decode(_, s)
4
+ def self.decode(prefix, s)
5
5
  parser = B64GRAMMARParser.new # B? XXX
6
+ s = EDN.to_one_string(prefix, s)
6
7
  ast = parser.parse(s)
7
8
  if !ast
8
9
  raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in b64'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
@@ -7,8 +7,9 @@ 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(app_prefix, s)
10
+ def self.decode(prefix, s)
11
11
  parser = DTGRAMMARParser.new
12
+ s = EDN.to_one_string(prefix, s)
12
13
  ast = parser.parse(s)
13
14
  if !ast
14
15
  raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in dt'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
@@ -21,13 +22,13 @@ class CBOR_DIAG::App_dt
21
22
  else
22
23
  t.to_i
23
24
  end
24
- case app_prefix
25
+ case prefix
25
26
  when 'dt'
26
27
  tv
27
28
  when 'DT'
28
29
  CBOR::Tagged.new(1, tv)
29
30
  else
30
- fail app_prefix
31
+ fail prefix
31
32
  end
32
33
  end
33
34
  end
@@ -1,8 +1,9 @@
1
1
  require_relative "hgrammar.rb"
2
2
 
3
3
  class CBOR_DIAG::App_h
4
- def self.decode(_, s)
4
+ def self.decode(prefix, s)
5
5
  parser = HGRAMMARParser.new
6
+ s = EDN.to_one_string(prefix, s)
6
7
  ast = parser.parse(s)
7
8
  if !ast
8
9
  raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in h'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
@@ -4,20 +4,21 @@ require 'ipaddr'
4
4
  require "cbor-diagnostic-app/0"
5
5
 
6
6
  class CBOR_DIAG::App_ip
7
- def self.decode(app_prefix, s)
7
+ def self.decode(prefix, s)
8
8
  parser = IPGRAMMARParser.new
9
+ s = EDN.to_one_string(prefix, s)
9
10
  ast = parser.parse(s)
10
11
  if !ast
11
12
  raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in ip'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
12
13
  end
13
14
  fam, ipv = ast.ast
14
- case app_prefix
15
+ case prefix
15
16
  when 'ip'
16
17
  ipv
17
18
  when 'IP'
18
19
  CBOR::Tagged.new(fam, ipv)
19
20
  else
20
- fail app_prefix
21
+ fail prefix
21
22
  end
22
23
  end
23
24
  end
@@ -1,14 +1,14 @@
1
1
  require "cbor-diagnostic-app/0"
2
2
 
3
3
  class CBOR_DIAG::Helper
4
- def self.decode_string(app_prefix, s, to_text = false)
4
+ def self.decode_string(prefix, s, to_text = false)
5
5
  ret = if CBOR::Sequence === s
6
6
  args = s.elements
7
7
  else
8
8
  args = [s]
9
9
  end.map { |el|
10
10
  unless String === el || el.respond_to?(:value) && String === el.value
11
- raise ArgumentError.new("cbor-diagnostic: #{app_prefix}<<>>: #{el.cbor_diagnostic} not a string: Argument Error")
11
+ raise ArgumentError.new("cbor-diagnostic: #{prefix}<<>>: #{el.cbor_diagnostic} not a string: Argument Error")
12
12
  end
13
13
  el.b
14
14
  }.join.b # .b needed so empty array becomes byte string, too
@@ -20,13 +20,13 @@ class CBOR_DIAG::Helper
20
20
  end
21
21
 
22
22
  class CBOR_DIAG::App_b1
23
- def self.decode(app_prefix, s)
24
- CBOR_DIAG::Helper.decode_string(app_prefix, s, false)
23
+ def self.decode(prefix, s)
24
+ CBOR_DIAG::Helper.decode_string(prefix, s, false)
25
25
  end
26
26
  end
27
27
 
28
28
  class CBOR_DIAG::App_t1
29
- def self.decode(app_prefix, s)
30
- CBOR_DIAG::Helper.decode_string(app_prefix, s, true)
29
+ def self.decode(prefix, s)
30
+ CBOR_DIAG::Helper.decode_string(prefix, s, true)
31
31
  end
32
32
  end
@@ -1,13 +1,13 @@
1
1
  require "cbor-diagnostic-app/0"
2
2
 
3
3
  class CBOR_DIAG::App_zzz
4
- def self.decode(app_prefix, s)
5
- CBOR::Tagged.new(999, [app_prefix, s])
4
+ def self.decode(prefix, s)
5
+ CBOR::Tagged.new(999, [prefix, s])
6
6
  end
7
7
  end
8
8
 
9
9
  class CBOR_DIAG::App_yyy
10
- def self.decode(app_prefix, s)
11
- CBOR::Tagged.new(999, [app_prefix, s])
10
+ def self.decode(prefix, s)
11
+ CBOR::Tagged.new(999, [prefix, s])
12
12
  end
13
13
  end
data/lib/edn-abnf.rb CHANGED
@@ -5,6 +5,7 @@ class EDN
5
5
  @@parser = EDNGRAMMARParser.new
6
6
 
7
7
  def self.reason(parser, s)
8
+ s = s.to_str
8
9
  reason = [parser.failure_reason]
9
10
  parser.failure_reason =~ /^(Expected .+) after ./m
10
11
  expected = $1
@@ -16,7 +17,16 @@ class EDN
16
17
  reason.join("\n")
17
18
  end
18
19
 
20
+ def self.to_one_string(prefix, s)
21
+ begin
22
+ s.to_str
23
+ rescue NoMethodError => e
24
+ raise ArgumentError.new("cbor-diagnostic #{prefix}<<>>: #{e}: #{s.inspect}")
25
+ end
26
+ end
27
+
19
28
  def self.from_edn(s)
29
+ s = s.to_str
20
30
  ast = @@parser.parse s
21
31
  if !ast
22
32
  raise ArgumentError, "Parse Error:\n" << self.reason(@@parser, s)
@@ -112,8 +112,8 @@ class Treetop::Runtime::SyntaxNode
112
112
  end
113
113
 
114
114
  # MTI app-extensions:
115
- require 'cbor-diagnostic-app/h'
116
- require 'cbor-diagnostic-app/b64'
117
- require 'cbor-diagnostic-app/dt'
118
- require 'cbor-diagnostic-app/ip'
119
- require 'cbor-diagnostic-app/t1_b1'
115
+ require_relative '../cbor-diagnostic-app/h'
116
+ require_relative '../cbor-diagnostic-app/b64'
117
+ require_relative '../cbor-diagnostic-app/dt'
118
+ require_relative '../cbor-diagnostic-app/ip'
119
+ require_relative '../cbor-diagnostic-app/t1_b1'
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.41
4
+ version: 0.5.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann