edn-abnf 0.0.1 → 0.0.3
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 +2 -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 +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17ca8476ccb59a567d0c72fa1eb3be96a637901add2544a545a5e87f8781bd8f
|
4
|
+
data.tar.gz: c88bba22e17635f44acbe1705cd8cb6a9c37ca4c91806e729341cfd347aa8eed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baac80d34ad740d44e18907bda40ee83f50ab858441d61a70b44ec9f9786fa90c2d24cb988327c44f9ad19762d89af2dffb5b77b2817b1f1c23688a9390bda01
|
7
|
+
data.tar.gz: a6a086be5922adf1ce51f51f5dc009719ed985729efb2c94c4d27bed097054f5490c2d04ca33e32e6a9239bd5c987a31860dc24aa05e46dcdedf7c2293c37f04
|
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.3"
|
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"
|
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.require_paths = ["lib"]
|
15
15
|
|
16
16
|
s.add_development_dependency 'bundler', '~>1'
|
17
|
+
s.add_development_dependency 'abnftt', '~>0.2'
|
17
18
|
s.add_dependency 'treetop', '~>1'
|
18
19
|
s.add_dependency 'json', '~>2'
|
19
20
|
s.add_dependency 'neatjson', '~>0.10'
|
@@ -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,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: abnftt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: treetop
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,11 +85,15 @@ description: edn-abnf implements converters and miscellaneous tools for CBOR EDN
|
|
71
85
|
email: cabo@tzi.org
|
72
86
|
executables:
|
73
87
|
- edn-abnf
|
88
|
+
- edn-abnf~
|
74
89
|
extensions: []
|
75
90
|
extra_rdoc_files: []
|
76
91
|
files:
|
77
92
|
- bin/edn-abnf
|
93
|
+
- bin/edn-abnf~
|
78
94
|
- edn-abnf.gemspec
|
95
|
+
- lib/cbor-diagnostic-app/b64.rb
|
96
|
+
- lib/cbor-diagnostic-app/h.rb
|
79
97
|
- lib/edn-abnf.rb
|
80
98
|
- lib/parser/edn-util.rb
|
81
99
|
- lib/parser/edngrammar.rb
|