edn-abnf 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/edn-abnf +7 -2
- data/bin/edn-abnf~ +57 -0
- data/edn-abnf.gemspec +1 -1
- data/lib/cbor-diagnostic-app/b64.rb +16 -0
- data/lib/cbor-diagnostic-app/h.rb +7 -0
- data/lib/parser/edn-util.rb +2 -0
- data/lib/parser/edngrammar.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a615ce8070270a4a91acb7e811e2b9417d1245b3378e5376ea9f74e1a9d8249f
|
4
|
+
data.tar.gz: f14064f8de13e5322832a07ed1af364041d05e9b4c030288cc5fb0653cbbd847
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
43
|
-
|
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.
|
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
|
data/lib/parser/edn-util.rb
CHANGED
data/lib/parser/edngrammar.rb
CHANGED
@@ -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
|
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.
|
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
|