edn-abnf-ec 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/edn-abnf-ec +109 -0
- data/edn-abnf.gemspec +21 -0
- data/lib/cbor-diagnostic-app/b64.rb +22 -0
- data/lib/cbor-diagnostic-app/b64grammar.rb +677 -0
- data/lib/cbor-diagnostic-app/dt.rb +33 -0
- data/lib/cbor-diagnostic-app/dtgrammar.rb +700 -0
- data/lib/cbor-diagnostic-app/h.rb +13 -0
- data/lib/cbor-diagnostic-app/hgrammar.rb +771 -0
- data/lib/cbor-diagnostic-app/ip.rb +21 -0
- data/lib/cbor-diagnostic-app/ipgrammar.rb +1698 -0
- data/lib/edn-abnf.rb +42 -0
- data/lib/parser/edn-util.rb +24 -0
- data/lib/parser/edngrammar.rb +4708 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7b8331d46fcc5488aa566d52bff36e7805ff2572124c5a968d64d6ec7f748f5c
|
4
|
+
data.tar.gz: d8e7bf78468578f924d877d1864b9648e873afadaad603152d081fd42a675451
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f047258eb31ee14fad5ef55f4608ce77aabd0f718049b47ddc67225f1ab488b97e600e6dba3ceecba2a22a67e7c8fc1be0c4b831878b2ba85335a9103ee4b61a
|
7
|
+
data.tar.gz: c22826fe2b73b320a98e6ea0fec1d9afd7b0a031c465697d5f2af5f64dfda4a93bbcf3a5241f88c1ecc56c7042709c6032a915cd67af4250e9d5d05cd2499257
|
data/bin/edn-abnf-ec
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8-hfs
|
3
|
+
require 'pp'
|
4
|
+
require 'yaml'
|
5
|
+
require 'treetop'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
require_relative '../lib/edn-abnf.rb'
|
9
|
+
|
10
|
+
def snaky(name)
|
11
|
+
name.gsub(/-/, "_")
|
12
|
+
end
|
13
|
+
|
14
|
+
Encoding.default_external = Encoding::UTF_8
|
15
|
+
require 'optparse'
|
16
|
+
require 'ostruct'
|
17
|
+
|
18
|
+
$options = OpenStruct.new
|
19
|
+
begin
|
20
|
+
op = OptionParser.new do |opts|
|
21
|
+
opts.banner = "Usage: edn-abnf.rb [options] [file.edn... | -]"
|
22
|
+
|
23
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
24
|
+
$options.verbose = v
|
25
|
+
end
|
26
|
+
opts.on("-l", "--[no-]lines", "multi-line mode") do |v|
|
27
|
+
require 'csv'
|
28
|
+
$options.lines = v
|
29
|
+
end
|
30
|
+
opts.on("-eEDN", "--e=EDN", "supply EDN on command line") do |v|
|
31
|
+
$options.edn = v
|
32
|
+
end
|
33
|
+
opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :edn, :diag], "Target format") do |v|
|
34
|
+
$options.target = v
|
35
|
+
end
|
36
|
+
end
|
37
|
+
op.parse!
|
38
|
+
rescue Exception => e
|
39
|
+
warn e
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
if !$options.edn
|
45
|
+
if ARGV == []
|
46
|
+
puts op
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
$options.edn = ARGF.read
|
50
|
+
else
|
51
|
+
if ARGV != []
|
52
|
+
warn "*** file names #{ARGV.join(", ")} ignored due to -e given"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
edn_file = $options.edn
|
57
|
+
|
58
|
+
if $options.lines
|
59
|
+
CSV.parse(edn_file) do |ok, edn, out|
|
60
|
+
if ok[0] == "#"
|
61
|
+
puts "# #{ok}, #{edn.inspect}, #{out}" if $options.verbose
|
62
|
+
next
|
63
|
+
end
|
64
|
+
begin
|
65
|
+
ok = ok == "="
|
66
|
+
puts "➔ #{ok}, #{edn}, #{out}" if $options.verbose
|
67
|
+
edn = EDN.from_edn(edn)
|
68
|
+
result = edn.tree
|
69
|
+
diag = result.cbor_diagnostic
|
70
|
+
if out == diag && !ok
|
71
|
+
puts "** ≠ / #{diag.inspect} / #{out.inspect}"
|
72
|
+
end
|
73
|
+
if out != diag && ok
|
74
|
+
puts "** ≡ / #{diag.inspect} / #{out.inspect}"
|
75
|
+
end
|
76
|
+
rescue ArgumentError => e
|
77
|
+
if ok
|
78
|
+
puts "** #{e} / #{result.inspect} / #{out.inspect}"
|
79
|
+
else
|
80
|
+
if $options.verbose
|
81
|
+
puts "expected failure #{e}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
exit
|
87
|
+
end
|
88
|
+
|
89
|
+
begin
|
90
|
+
edn = EDN.from_edn(edn_file)
|
91
|
+
result = edn.tree # XXX .tree?
|
92
|
+
rescue ArgumentError => e
|
93
|
+
puts "** #{e}"
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
|
97
|
+
case $options.target
|
98
|
+
when :basic, nil
|
99
|
+
pp result
|
100
|
+
when :neat, :json
|
101
|
+
require 'neatjson'
|
102
|
+
puts JSON.neat_generate(result, after_comma: 1, after_colon: 1)
|
103
|
+
when :yaml
|
104
|
+
puts result.to_yaml
|
105
|
+
when :edn, :diag
|
106
|
+
puts result.cbor_diagnostic
|
107
|
+
else
|
108
|
+
warn ["Unknown target format: ", $options.target].inspect
|
109
|
+
end
|
data/edn-abnf.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "edn-abnf-ec"
|
3
|
+
s.version = "0.1.8"
|
4
|
+
s.summary = "CBOR Extended Diagnostic Notation (EDN) implemented in ABNF"
|
5
|
+
s.description = %q{edn-abnf implements converters and miscellaneous tools for CBOR EDN's ABNF}
|
6
|
+
s.author = "Carsten Bormann"
|
7
|
+
s.email = "cabo@tzi.org"
|
8
|
+
s.license = "MIT"
|
9
|
+
s.homepage = "http://github.com/cabo/edn-abnf"
|
10
|
+
s.files = Dir['lib/**/*.rb'] + %w(edn-abnf.gemspec) + Dir['bin/**/*.rb']
|
11
|
+
s.executables = Dir['bin/*'].map {|x| File.basename(x)}
|
12
|
+
s.required_ruby_version = '>= 1.9.2'
|
13
|
+
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
|
16
|
+
s.add_development_dependency 'bundler', '~>1'
|
17
|
+
s.add_development_dependency 'abnftt', '~>0.2'
|
18
|
+
s.add_dependency 'treetop', '~>1'
|
19
|
+
s.add_dependency 'json', '~>2'
|
20
|
+
s.add_dependency 'neatjson', '~>0.10'
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "b64grammar.rb"
|
2
|
+
|
3
|
+
class CBOR_DIAG::App_b64
|
4
|
+
def self.decode(_, s)
|
5
|
+
parser = B64GRAMMARParser.new # B? XXX
|
6
|
+
ast = parser.parse(s)
|
7
|
+
if !ast
|
8
|
+
raise ArgumentError, "cbor-diagnostic: Parse Error in b64'#{s}':\n" << EDN.reason(parser, s)
|
9
|
+
end
|
10
|
+
# lazy -- not using parse tree...:
|
11
|
+
t = s.gsub(/\s|#[^\n]*(?:\n|\z)/, '').chars.each_slice(4).map(&:join)
|
12
|
+
if last = t[-1]
|
13
|
+
last << "=" * (4 - last.size)
|
14
|
+
end
|
15
|
+
b = t.join.tr("-_", "+/")
|
16
|
+
begin
|
17
|
+
b.unpack("m0")[0]
|
18
|
+
rescue ArgumentError
|
19
|
+
raise ArgumentError, "cbor-diagnostic: invalid base64 #{b.inspect}", caller[1..-1]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|