edn-abnf 0.0.12 → 0.1.0

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: f762b42f537b6298556bf2e2988c8612cd26d9315c980ddb9a5e355a678a40c5
4
- data.tar.gz: 91b77ee973f2d4c23a6a9bb0344a16324e783c47861f7f0929dfd6322dd0f743
3
+ metadata.gz: 2894bfba4af4dbd61e9c9c10431713446360aba2962a99f3729b22d13ebdf52a
4
+ data.tar.gz: 7222fd2e9723cb4221283eaf6c06083718a8884d840c9709ca9673f4dfd0678f
5
5
  SHA512:
6
- metadata.gz: ecb6361fcf84f6de6d7e547093ec2de27d7cc69161d7717ee336db9b39b0b546ce50015dbcfb8ed64d81129d67acdbaa4eb0fcb64751c55fbe10996e9ca61fd1
7
- data.tar.gz: 8f438a03ee42ea49f1d412b9fe249332acfae759be315a1c6e8f71304fb8159c9161f8267252e9e6f8f463577c2f4c55bfeafff33baae1da7f6c0752d6a131d9
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.12"
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"
@@ -7,7 +7,7 @@ require 'time'
7
7
  # Probably should copy over Time#xmlschema and fix that for us.
8
8
 
9
9
  class CBOR_DIAG::App_dt
10
- def self.decode(_, s)
10
+ def self.decode(app_prefix, s)
11
11
  parser = DTGRAMMARParser.new
12
12
  ast = parser.parse(s)
13
13
  if !ast
@@ -16,10 +16,18 @@ class CBOR_DIAG::App_dt
16
16
  # ast.ast
17
17
 
18
18
  t = Time.iso8601(s)
19
- if t.subsec != 0
19
+ tv = if t.subsec != 0
20
20
  t.to_f
21
21
  else
22
22
  t.to_i
23
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
24
32
  end
25
33
  end
@@ -6,7 +6,7 @@ class CBOR_DIAG::App_ip
6
6
  parser = IPGRAMMARParser.new
7
7
  ast = parser.parse(s)
8
8
  if !ast
9
- raise ArgumentError, "cbor-diagnostic: Parse Error in h'#{s}':\n" << EDN.reason(parser, s)
9
+ raise ArgumentError, "cbor-diagnostic: Parse Error in ip'#{s}':\n" << EDN.reason(parser, s)
10
10
  end
11
11
  fam, ipv = ast.ast
12
12
  case app_prefix
@@ -18,5 +18,4 @@ class CBOR_DIAG::App_ip
18
18
  fail app_prefix
19
19
  end
20
20
  end
21
- # s.gsub(/#.*|\s|\/[^\/]*\//, "").chars.each_slice(2).map{ |x| Integer(x.join, 16).chr("BINARY") }.join
22
21
  end
@@ -1499,7 +1499,7 @@ module EDNGRAMMAR
1499
1499
  app = app_prefix.text_value
1500
1500
  # Find a better place to put a default initialization
1501
1501
  EDNGRAMMAR.const_set(:APPS, Hash.new { |h, k|
1502
- h[k] = begin ::CBOR_DIAG.const_get("App_#{app.downcase}")
1502
+ h[k] = begin ::CBOR_DIAG.const_get("App_#{k.downcase}")
1503
1503
 
1504
1504
  rescue NameError
1505
1505
  raise ArgumentError, "cbor-diagnostic: Unknown application-oriented extension '#{k}'", caller
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.12
4
+ version: 0.1.0
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-10-15 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler