edn-abnf 0.5.6 → 0.5.8
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 +4 -4
- data/bin/edn-abnf +13 -3
- data/edn-abnf.gemspec +2 -2
- data/lib/cbor-diagnostic-app/b64.rb +1 -1
- data/lib/cbor-diagnostic-app/dt.rb +1 -1
- data/lib/cbor-diagnostic-app/h.rb +1 -1
- data/lib/cbor-diagnostic-app/ip.rb +3 -1
- data/lib/parser/edn-util.rb +36 -1
- data/lib/parser/edngrammar.rb +6 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74a7d7e1c31717d2f7a42f5d44199b54066a5acdb4b624a2cc961ba02356df53
|
4
|
+
data.tar.gz: b229fcd8f8d792363ec1a05af94f6619a22630b52e36c01574e232d204a3e82d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65241c695737a54fd4e4496bd463bbfeec7a257f9a82e900f6f85f45c698dbf6b5dd49fcabd0db4775d057a11675d3a17e164a22949ed3f79176d5cbfc99b544
|
7
|
+
data.tar.gz: bcc298642bb1ab8f8f456b76c6e7c7139bc2e96aeeffdf312869119352fa7580e369e4db28122db008d673a20f7018c6beb1927ec07a581effb615338dc3d14a
|
data/bin/edn-abnf
CHANGED
@@ -6,6 +6,12 @@ require 'treetop'
|
|
6
6
|
require 'json'
|
7
7
|
require 'cbor-pretty'
|
8
8
|
|
9
|
+
# Temporary fix for name conflicts between cbor-diag and edn-abnf
|
10
|
+
diag_path = $LOAD_PATH.grep(/gems\/cbor-diag/).first
|
11
|
+
edn_path = $LOAD_PATH.grep(/gems\/edn-abnf/).first
|
12
|
+
$LOAD_PATH[$LOAD_PATH.index(diag_path)] = edn_path
|
13
|
+
$LOAD_PATH << diag_path
|
14
|
+
|
9
15
|
require_relative '../lib/edn-abnf.rb'
|
10
16
|
|
11
17
|
def snaky(name)
|
@@ -64,21 +70,25 @@ begin
|
|
64
70
|
if nm =~ /\A[a-z][a-z0-9]*\z/
|
65
71
|
require "cbor-diagnostic-app/#{nm}"
|
66
72
|
else
|
67
|
-
raise ArgumentError.new("edn-abnf: app-extension name #{nm} not
|
73
|
+
raise ArgumentError.new("edn-abnf: app-extension name #{nm} not installed")
|
68
74
|
end
|
69
75
|
end
|
70
76
|
end
|
77
|
+
opts.on("-f", "--[no-]fallback", "use tag 999 for unknown app-extensions") do |v|
|
78
|
+
$options.fallback = v
|
79
|
+
end
|
71
80
|
end
|
72
81
|
op.parse!
|
73
82
|
rescue Exception => e
|
74
83
|
warn e
|
84
|
+
warn op
|
75
85
|
exit 1
|
76
86
|
end
|
77
87
|
|
78
88
|
|
79
89
|
if !$options.edn
|
80
90
|
if ARGV == []
|
81
|
-
|
91
|
+
warn op
|
82
92
|
exit 1
|
83
93
|
end
|
84
94
|
$options.edn = ARGF.read
|
@@ -152,7 +162,7 @@ end
|
|
152
162
|
begin
|
153
163
|
edn = EDN.from_edn(edn_file)
|
154
164
|
result = edn.tree # XXX .tree?
|
155
|
-
rescue ArgumentError => e
|
165
|
+
rescue CBOR_DIAG::AppParseError, ArgumentError => e
|
156
166
|
puts "** #{e}"
|
157
167
|
exit 1
|
158
168
|
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.5.
|
3
|
+
s.version = "0.5.8"
|
4
4
|
s.summary = "CBOR Extended Diagnostic Notation (EDN) 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"
|
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency 'treetop', '~>1'
|
19
19
|
s.add_dependency 'json', '~>2'
|
20
20
|
s.add_dependency 'neatjson', '~>0.10'
|
21
|
-
s.add_dependency 'cbor-diag'
|
21
|
+
s.add_dependency 'cbor-diag', '>= 0.9.8'
|
22
22
|
end
|
@@ -5,7 +5,7 @@ class CBOR_DIAG::App_b64
|
|
5
5
|
parser = B64GRAMMARParser.new # B? XXX
|
6
6
|
ast = parser.parse(s)
|
7
7
|
if !ast
|
8
|
-
raise
|
8
|
+
raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in b64'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
|
9
9
|
end
|
10
10
|
# lazy -- not using parse tree...:
|
11
11
|
t = s.gsub(/\s|#[^\n]*(?:\n|\z)/, '').chars.each_slice(4).map(&:join)
|
@@ -11,7 +11,7 @@ class CBOR_DIAG::App_dt
|
|
11
11
|
parser = DTGRAMMARParser.new
|
12
12
|
ast = parser.parse(s)
|
13
13
|
if !ast
|
14
|
-
raise
|
14
|
+
raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in dt'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
|
15
15
|
end
|
16
16
|
frac = ast.has_frac != ""
|
17
17
|
|
@@ -5,7 +5,7 @@ class CBOR_DIAG::App_h
|
|
5
5
|
parser = HGRAMMARParser.new
|
6
6
|
ast = parser.parse(s)
|
7
7
|
if !ast
|
8
|
-
raise
|
8
|
+
raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in h'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
|
9
9
|
end
|
10
10
|
ast.ast
|
11
11
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require_relative "ipgrammar.rb"
|
2
2
|
require 'ipaddr'
|
3
3
|
|
4
|
+
require "cbor-diagnostic-app/0"
|
5
|
+
|
4
6
|
class CBOR_DIAG::App_ip
|
5
7
|
def self.decode(app_prefix, s)
|
6
8
|
parser = IPGRAMMARParser.new
|
7
9
|
ast = parser.parse(s)
|
8
10
|
if !ast
|
9
|
-
raise
|
11
|
+
raise CBOR_DIAG::AppParseError.new("cbor-diagnostic: Parse Error in ip'#{s}':\n" << EDN.reason(parser, s), parser.failure_index)
|
10
12
|
end
|
11
13
|
fam, ipv = ast.ast
|
12
14
|
case app_prefix
|
data/lib/parser/edn-util.rb
CHANGED
@@ -5,11 +5,26 @@ end
|
|
5
5
|
require 'treetop'
|
6
6
|
require_relative './edngrammar'
|
7
7
|
|
8
|
+
class CBOR_DIAG::App_ # fallback!
|
9
|
+
def self.decode(app_prefix, s)
|
10
|
+
if CBOR::Sequence === s
|
11
|
+
args = s.elements
|
12
|
+
else
|
13
|
+
args = [s]
|
14
|
+
end
|
15
|
+
CBOR::Tagged.new(999, [app_prefix, args])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
8
19
|
module EDNGRAMMAR
|
9
20
|
const_set(:APPS, Hash.new { |h, k|
|
10
21
|
h[k] = begin ::CBOR_DIAG.const_get("App_#{k.downcase}")
|
11
22
|
rescue NameError
|
12
|
-
|
23
|
+
if $options.fallback
|
24
|
+
::CBOR_DIAG::App_
|
25
|
+
else
|
26
|
+
raise ArgumentError, "cbor-diagnostic: Unknown application-oriented extension '#{k}'", caller
|
27
|
+
end
|
13
28
|
end
|
14
29
|
}) unless const_defined?(:APPS)
|
15
30
|
end
|
@@ -24,6 +39,26 @@ class Treetop::Runtime::SyntaxNode
|
|
24
39
|
def hex_value
|
25
40
|
text_value.to_i(16)
|
26
41
|
end
|
42
|
+
def app_parser_level1_diagnostics(e, node)
|
43
|
+
outbytes = 0
|
44
|
+
intv = node.interval.end...(node.interval.end+1) # default: closing '
|
45
|
+
node.elements.each_with_index do |el, i|
|
46
|
+
outbytes += el.ast.size
|
47
|
+
if outbytes > e.position
|
48
|
+
intv = el.interval
|
49
|
+
break
|
50
|
+
end
|
51
|
+
end
|
52
|
+
failure_index = intv.begin
|
53
|
+
failure_line = node.input.line_of(failure_index)
|
54
|
+
failure_column = node.input.column_of(failure_index)
|
55
|
+
if line = node.input.lines.to_a[failure_line - 1]
|
56
|
+
reason = "** Line #{failure_line}, column #{failure_column}:\n"
|
57
|
+
reason << line
|
58
|
+
reason << "\n#{'~' * (failure_column - 1)}#{'^' * intv.size}"
|
59
|
+
end
|
60
|
+
warn reason
|
61
|
+
end
|
27
62
|
end
|
28
63
|
|
29
64
|
|
data/lib/parser/edngrammar.rb
CHANGED
@@ -1696,7 +1696,12 @@ module EDNGRAMMAR
|
|
1696
1696
|
def ast # XXX ignoring h and b64
|
1697
1697
|
data = sqstr.ast.force_encoding(Encoding::UTF_8) # XXX undo .b
|
1698
1698
|
app = app_prefix.text_value
|
1699
|
-
|
1699
|
+
begin
|
1700
|
+
::EDNGRAMMAR::APPS[app].decode(app, data)
|
1701
|
+
rescue CBOR_DIAG::AppParseError => e
|
1702
|
+
app_parser_level1_diagnostics(e, elements[1].elements[1])
|
1703
|
+
raise e
|
1704
|
+
end
|
1700
1705
|
end
|
1701
1706
|
end
|
1702
1707
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edn-abnf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-05
|
10
|
+
date: 2025-07-05 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bundler
|
@@ -85,14 +85,14 @@ dependencies:
|
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: 0.9.8
|
89
89
|
type: :runtime
|
90
90
|
prerelease: false
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
95
|
+
version: 0.9.8
|
96
96
|
description: edn-abnf implements converters and miscellaneous tools for CBOR EDN's
|
97
97
|
ABNF
|
98
98
|
email: cabo@tzi.org
|