edn-abnf 0.0.12 → 0.1.1

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: f762b42f537b6298556bf2e2988c8612cd26d9315c980ddb9a5e355a678a40c5
4
- data.tar.gz: 91b77ee973f2d4c23a6a9bb0344a16324e783c47861f7f0929dfd6322dd0f743
3
+ metadata.gz: 7c6889b9d7aa6148fe54cb74e2594c0235b0fe1b6d07192b942d5690aa2b4e55
4
+ data.tar.gz: 40a8707339bb46f5c984b292eff1ece51d0fcdb614feae79c224b83d4d9ffa1e
5
5
  SHA512:
6
- metadata.gz: ecb6361fcf84f6de6d7e547093ec2de27d7cc69161d7717ee336db9b39b0b546ce50015dbcfb8ed64d81129d67acdbaa4eb0fcb64751c55fbe10996e9ca61fd1
7
- data.tar.gz: 8f438a03ee42ea49f1d412b9fe249332acfae759be315a1c6e8f71304fb8159c9161f8267252e9e6f8f463577c2f4c55bfeafff33baae1da7f6c0752d6a131d9
6
+ metadata.gz: 9e1461595213030be64e5e778bceaf998cd105772948b51a9b3340feba463e3e6c2da6a68de1388eb9fab487b7f6d8b5d3b092b00704d67b77d15829f681266b
7
+ data.tar.gz: 8485df1945d7989b762a6d9a94e1395a4228f4fc2126af2c0136af749c3d273d1e72af3d160f3862f8747c33e24411eb084f5fc852138f890f1afa34a2bc4171
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,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "edn-abnf"
3
- s.version = "0.0.12"
4
- s.summary = "CDDL (Concise Data Definition Language) converters and miscellaneous tools"
3
+ s.version = "0.1.1"
4
+ s.summary = "CBOR Extended Diagnostic Notation implemented in ABNF"
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
  s.email = "cabo@tzi.org"
@@ -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.1
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
@@ -125,5 +125,5 @@ requirements: []
125
125
  rubygems_version: 3.4.10
126
126
  signing_key:
127
127
  specification_version: 4
128
- summary: CDDL (Concise Data Definition Language) converters and miscellaneous tools
128
+ summary: CBOR Extended Diagnostic Notation implemented in ABNF
129
129
  test_files: []