edn-abnf 0.0.1 → 0.0.2

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: 8e126887990e8896adb3bd44950656b51afc8d8f1302621c017ecbbc914361eb
4
- data.tar.gz: 9766b5bc4ec7a00e40cea828776d737b2723b6f3ae9448d1fb3dcc10a45f336a
3
+ metadata.gz: a615ce8070270a4a91acb7e811e2b9417d1245b3378e5376ea9f74e1a9d8249f
4
+ data.tar.gz: f14064f8de13e5322832a07ed1af364041d05e9b4c030288cc5fb0653cbbd847
5
5
  SHA512:
6
- metadata.gz: 1b6886f7d40dec4c34f5cb39c9900c5123605b97b68fb620f0d4ff40eefc1bdb27f26b1132464afdcd2e94be46a1be7d8d9e708f25b34a4047899bfb875e4ce9
7
- data.tar.gz: 051ca2fbe7cb43b569d0c376b4fc7a8b1d29f4a33fb0b6b8c73da78029e73042356203b6bdc3dbb4ce4fb98fd1c0e5bcfc19eb218c72fa9b190ec7dc86b0517c
6
+ metadata.gz: 98ab91da990ea04a56ef83fd07b90c1a4b32a83814a8d66366167a5f2c3f053cfb3967a0d1a362a5c6a9829b7f09ee91121b9a9d0873122862bfb778c4394676
7
+ data.tar.gz: dbf862919dcf4cb41bb0e4359aaf0d4ae43c7c78958abad6806a6a5c2ae8a72dbd8b7f593519ee00ba5bf87d3ed7457740919c97b1f8ea7ab6bce1356f2c574d
data/bin/edn-abnf CHANGED
@@ -39,8 +39,13 @@ end
39
39
 
40
40
  edn_file = ARGF.read
41
41
 
42
- edn = EDN.from_edn(edn_file)
43
- result = edn.tree # XXX .tree?
42
+ begin
43
+ edn = EDN.from_edn(edn_file)
44
+ result = edn.tree # XXX .tree?
45
+ rescue ArgumentError => e
46
+ puts "** #{e}"
47
+ exit 1
48
+ end
44
49
 
45
50
  case $options.target
46
51
  when :basic, nil
data/bin/edn-abnf~ ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pp'
3
+ require 'yaml'
4
+ require 'treetop'
5
+ require 'json'
6
+
7
+ require_relative '../lib/edn-abnf.rb'
8
+
9
+ def snaky(name)
10
+ name.gsub(/-/, "_")
11
+ end
12
+
13
+ Encoding.default_external = Encoding::UTF_8
14
+ require 'optparse'
15
+ require 'ostruct'
16
+
17
+ $options = OpenStruct.new
18
+ begin
19
+ op = OptionParser.new do |opts|
20
+ opts.banner = "Usage: edn-abnf.rb [options] [file.edn... | -]"
21
+
22
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
23
+ $options.verbose = v
24
+ end
25
+ opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :edn, :diag], "Target format") do |v|
26
+ $options.target = v
27
+ end
28
+ end
29
+ op.parse!
30
+ rescue Exception => e
31
+ warn e
32
+ exit 1
33
+ end
34
+
35
+ if ARGV == []
36
+ puts op
37
+ exit 1
38
+ end
39
+
40
+ edn_file = ARGF.read
41
+
42
+ edn = EDN.from_edn(edn_file)
43
+ result = edn.tree # XXX .tree?
44
+
45
+ case $options.target
46
+ when :basic, nil
47
+ pp result
48
+ when :neat, :json
49
+ require 'neatjson'
50
+ puts JSON.neat_generate(result, after_comma: 1, after_colon: 1)
51
+ when :yaml
52
+ puts result.to_yaml
53
+ when :edn, :diag
54
+ puts result.cbor_diagnostic
55
+ else
56
+ warn ["Unknown target format: ", $options.target].inspect
57
+ end
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.0.1"
3
+ s.version = "0.0.2"
4
4
  s.summary = "CDDL (Concise Data Definition Language) converters and miscellaneous tools"
5
5
  s.description = %q{edn-abnf implements converters and miscellaneous tools for CBOR EDN's ABNF}
6
6
  s.author = "Carsten Bormann"
@@ -0,0 +1,16 @@
1
+ # mockup only; needs parser!
2
+
3
+ class CBOR_DIAG::App_b64
4
+ def self.decode(_, s)
5
+ t = s.gsub(/\s/, '').chars.each_slice(4).map(&:join)
6
+ if last = t[-1]
7
+ last << "=" * (4 - last.size)
8
+ end
9
+ b = t.join.tr("-_", "+/")
10
+ begin
11
+ b.unpack("m0")[0]
12
+ rescue ArgumentError
13
+ raise ArgumentError, "cbor-diagnostic: invalid base64 #{b.inspect}", caller[1..-1]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ # mockup only; needs parser!
2
+
3
+ class CBOR_DIAG::App_h
4
+ def self.decode(_, s)
5
+ s.gsub(/#.*|\s|\/[^\/]*\//, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join
6
+ end
7
+ end
@@ -2,6 +2,8 @@ require 'cbor-diagnostic'
2
2
  module CBOR_DIAG
3
3
  end
4
4
  require 'cbor-diagnostic-app/dt'
5
+ require 'cbor-diagnostic-app/h'
6
+ require 'cbor-diagnostic-app/b64'
5
7
 
6
8
  require 'treetop'
7
9
  require_relative './edngrammar'
@@ -1077,7 +1077,7 @@ module EDNGRAMMAR
1077
1077
  EDNGRAMMAR.const_set(:APPS, Hash.new { |h, k|
1078
1078
  h[k] = begin ::CBOR_DIAG.const_get("App_#{app}")
1079
1079
  rescue NameError
1080
- raise ArgumentError.new("cbor-diagnostic: Unknown application-oriented extension #{k}")
1080
+ raise ArgumentError, "cbor-diagnostic: Unknown application-oriented extension '#{k}'", caller
1081
1081
  end
1082
1082
  }) unless ::EDNGRAMMAR.const_defined?(:APPS)
1083
1083
  ::EDNGRAMMAR::APPS[app].decode(app, data)
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.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
@@ -71,11 +71,15 @@ description: edn-abnf implements converters and miscellaneous tools for CBOR EDN
71
71
  email: cabo@tzi.org
72
72
  executables:
73
73
  - edn-abnf
74
+ - edn-abnf~
74
75
  extensions: []
75
76
  extra_rdoc_files: []
76
77
  files:
77
78
  - bin/edn-abnf
79
+ - bin/edn-abnf~
78
80
  - edn-abnf.gemspec
81
+ - lib/cbor-diagnostic-app/b64.rb
82
+ - lib/cbor-diagnostic-app/h.rb
79
83
  - lib/edn-abnf.rb
80
84
  - lib/parser/edn-util.rb
81
85
  - lib/parser/edngrammar.rb