edn-abnf 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/edn-abnf +32 -7
  3. data/edn-abnf.gemspec +2 -1
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0ccd3540b2b3966eb739a688fd22322c2e0a7300e315d647b583ce5960f33f6
4
- data.tar.gz: 98cdfdc738e65e68970cc9efec4d1616f54d8bfc2bcb296ec3d72c0f0363aa82
3
+ metadata.gz: 0e8b236b54352f4702a4d5995eaaab5d7578addef93777e1a722c668ac1c6202
4
+ data.tar.gz: 3168853cab882f8db393a9e5921a527d788f658f63fb3877c45315f9cc078ca7
5
5
  SHA512:
6
- metadata.gz: 3e3ee53333c99241e2e9c4f29b06df4b2fd148dbedece4d6287058891e299fefffa8724c914a7931f51b0a8f879449afd1264dcc2dbe3301ccd7eb007418e0bb
7
- data.tar.gz: 73b08bd9557d8780e63ab65b21c71bd573f429ef1c3b29fab03773c61601d9f9ab474d8e8afdd97ac8a232cd815a57900b495ab100e0f38f85dd663a76c9d705
6
+ metadata.gz: 5ae982135b96e6fa336b23a77d106a0d759cc112e2770cef7532dfd69ac0dee29342f5192c60ffa5aef927d0bad16960f9e9b174535200ebcf9ab568f1a030f2
7
+ data.tar.gz: a16821958a1e34e3cdd6dd1040440f9e964ea39adbd2af0a0f965a6246d2a8964fbeae17dcd39ad59376a43f50e7542d3085648356f66ee010d44f3346b74245
data/bin/edn-abnf CHANGED
@@ -10,7 +10,23 @@ require_relative '../lib/edn-abnf.rb'
10
10
  def snaky(name)
11
11
  name.gsub(/-/, "_")
12
12
  end
13
-
13
+
14
+ class String
15
+ def hexi
16
+ bytes.map{|x| "%02x" % x}.join
17
+ end
18
+ def xeh
19
+ gsub(/\s/, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join
20
+ end
21
+ end
22
+
23
+ def tree_from_edn_possibly_hex(s)
24
+ if s[0..1] == "h]"
25
+ s = s[2..-1].xeh.force_encoding(Encoding::UTF_8)
26
+ end
27
+ EDN.from_edn(s).tree
28
+ end
29
+
14
30
  Encoding.default_external = Encoding::UTF_8
15
31
  require 'optparse'
16
32
  require 'ostruct'
@@ -30,7 +46,7 @@ begin
30
46
  opts.on("-eEDN", "--e=EDN", "supply EDN on command line") do |v|
31
47
  $options.edn = v
32
48
  end
33
- opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :edn, :diag], "Target format") do |v|
49
+ opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :edn, :diag], "Target format (default: diag)") do |v|
34
50
  $options.target = v
35
51
  end
36
52
  end
@@ -61,17 +77,26 @@ if $options.lines
61
77
  puts "# #{ok}, #{ednin.inspect}, #{out}" if $options.verbose
62
78
  next
63
79
  end
80
+ if ok[0] == "x"
81
+ result = tree_from_edn_possibly_hex(ednin)
82
+ result_hex = result.to_cbor.hexi
83
+ result_diag = result.cbor_diagnostic
84
+ puts "x #{ok}, #{ednin.inspect} / #{out} ➔ #{result_diag.inspect} / #{result_hex}" if $options.verbose
85
+ if result_hex != out
86
+ puts "** x / #{ednin.inspect} / #{out} ≠ #{result_diag.inspect} / #{result_hex}"
87
+ end
88
+ next
89
+ end
64
90
  begin
65
91
  ok = ok == "="
66
92
  puts "➔ #{ok}, #{ednin}, #{out}" if $options.verbose
67
- edn = EDN.from_edn(ednin)
68
- result = edn.tree
93
+ result = tree_from_edn_possibly_hex(ednin)
69
94
  diag = result.cbor_diagnostic
70
95
  if out == diag && !ok
71
96
  puts "** ≠ / #{diag.inspect} / #{out.inspect}"
72
97
  end
73
98
  if out != diag && ok
74
- outdiag = EDN.from_edn(out).tree.cbor_diagnostic
99
+ outdiag = tree_from_edn_possibly_hex(out).cbor_diagnostic
75
100
  if outdiag != diag
76
101
  puts "** ≡ / #{ednin.inspect} #{diag.inspect} / #{out.inspect} #{outdiag.inspect}"
77
102
  end
@@ -99,14 +124,14 @@ rescue ArgumentError => e
99
124
  end
100
125
 
101
126
  case $options.target
102
- when :basic, nil
127
+ when :basic
103
128
  pp result
104
129
  when :neat, :json
105
130
  require 'neatjson'
106
131
  puts JSON.neat_generate(result, after_comma: 1, after_colon: 1)
107
132
  when :yaml
108
133
  puts result.to_yaml
109
- when :edn, :diag
134
+ when :edn, :diag, nil
110
135
  puts result.cbor_diagnostic
111
136
  else
112
137
  warn ["Unknown target format: ", $options.target].inspect
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.2.3"
3
+ s.version = "0.3.1"
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"
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency 'treetop', '~>1'
19
19
  s.add_dependency 'json', '~>2'
20
20
  s.add_dependency 'neatjson', '~>0.10'
21
+ s.add_dependency 'cbor-diag'
21
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edn-abnf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-19 00:00:00.000000000 Z
11
+ date: 2024-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cbor-diag
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: edn-abnf implements converters and miscellaneous tools for CBOR EDN's
84
98
  ABNF
85
99
  email: cabo@tzi.org