edn-abnf 0.0.11 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dd67fd4813a8adf98e4bbffd069e9d9e40a9c8d4c51c9f1ef1226497d3e7e9b
4
- data.tar.gz: 524e68b7bb39b5acb883ddcbbbf3afd6531dfbc3892abfdf7346e8a97452e51d
3
+ metadata.gz: 2894bfba4af4dbd61e9c9c10431713446360aba2962a99f3729b22d13ebdf52a
4
+ data.tar.gz: 7222fd2e9723cb4221283eaf6c06083718a8884d840c9709ca9673f4dfd0678f
5
5
  SHA512:
6
- metadata.gz: 132445c4a4c05bd1ce60d552c0c6809df5c92cb850c79243cd26fd5552f5db73e3a1b93dbce1585cddec77ff764d33b1bfb7a868d1907dfa37145a1762530729
7
- data.tar.gz: e399041d7bf61d00d80fe824daeb72e8d008927cd8cd5958aedce23f100e53ecef2887393d0aca753bafc9fed1c4330bd8696ffdcd6a6e69829331efd28e8e22
6
+ metadata.gz: 8c1f9277ebcf2028c2abe48723e0ed3a9c326caf6629d4ce610f81ea1c96880ef2e83b0b2c2150b0b5c364befab7d94d3d7665636a5d3cc15594675db96fb7f3
7
+ data.tar.gz: 204d4de2c92eda0009a1214f9db0982561584f28bcfa2d30a7917c44477f0263dec3c490ebe7ac31743c4eae8ad4e4b2abe906bc75401378b6a86655613bc72b
data/bin/edn-abnf CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # coding: utf-8-hfs
2
3
  require 'pp'
3
4
  require 'yaml'
4
5
  require 'treetop'
@@ -22,6 +23,13 @@ begin
22
23
  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
23
24
  $options.verbose = v
24
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
25
33
  opts.on("-tFMT", "--to=FMT", [:basic, :neat, :json, :yaml, :edn, :diag], "Target format") do |v|
26
34
  $options.target = v
27
35
  end
@@ -32,12 +40,51 @@ rescue Exception => e
32
40
  exit 1
33
41
  end
34
42
 
35
- if ARGV == []
36
- puts op
37
- exit 1
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
38
54
  end
39
55
 
40
- edn_file = ARGF.read
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}, #{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
41
88
 
42
89
  begin
43
90
  edn = EDN.from_edn(edn_file)
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.11"
3
+ s.version = "0.1.0"
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,33 @@
1
+ require_relative "dtgrammar.rb"
2
+ require 'time'
3
+
4
+ # Using Time#iso8601 creates the following bugs:
5
+ # * dt'1970-01-01T10:00:00' is accepted and gives local time
6
+ # * dt'1970-01-01T10:00:00.0Z' gives an integer instead of a float
7
+ # Probably should copy over Time#xmlschema and fix that for us.
8
+
9
+ class CBOR_DIAG::App_dt
10
+ def self.decode(app_prefix, s)
11
+ parser = DTGRAMMARParser.new
12
+ ast = parser.parse(s)
13
+ if !ast
14
+ raise ArgumentError, "cbor-diagnostic: Parse Error in dt'#{s}':\n" << EDN.reason(parser, s)
15
+ end
16
+ # ast.ast
17
+
18
+ t = Time.iso8601(s)
19
+ tv = if t.subsec != 0
20
+ t.to_f
21
+ else
22
+ t.to_i
23
+ end
24
+ case app_prefix
25
+ when 'dt'
26
+ tv
27
+ when 'DT'
28
+ CBOR::Tagged.new(1, tv)
29
+ else
30
+ fail app_prefix
31
+ end
32
+ end
33
+ end