edn-abnf 0.5.7 → 0.5.9

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: 3bcd4eb027bdd536dd68495888d729d0bd74647daa157fe2ba8f674432f6a8d8
4
- data.tar.gz: 3fcc1ece75ccda7eca35284880b26232f6014528d17e0abd46ef73c86c2dc7da
3
+ metadata.gz: 806ffbc9b5f1324cd2ae94381fc1260144ed5a8dc62c29a45d42335fb5424a19
4
+ data.tar.gz: bcfcf9de27c7fe957601ee45ba33dec200314ddab4015543cf2f76aec39a3c6a
5
5
  SHA512:
6
- metadata.gz: c2820714dc0bca0ac2196af9f156062423db534c166de6b18dd0e243638b808d2906b3bcd2cf0e2d7fcbb6555fa42f21213c1026983ac586e1793735b21bfcd1
7
- data.tar.gz: dc913cf9e16dfc2655c086042c477ac664f43ac179bfd06939cc063426360e1e62a1173f84b7413cc97a4f4b7f663a399b3eaaf7e7099f48d1c1c6feeef12614
6
+ metadata.gz: d3897fe3c7e47eadb5d3d29b90ed663d397254b802ce5fe54b493dbf75a1d3a808b04426e80c5b5e15410ab75d60056b4ca0f7a8b165140a4ba72ff49950cace
7
+ data.tar.gz: 6aab126c0f00fc8b2b6b43bffb9bd8902c79f6ae3df2fa1f6b7a866d277ed27825aa8f48d20294b24e44f62f4d5b7b9a6452a6e33bcb234476449a9901c0b827
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)
@@ -51,6 +57,10 @@ begin
51
57
  opts.on("-i", "--[no-]integrated", "use integrated parsers where available") do |v|
52
58
  $options.integrated = v
53
59
  end
60
+ opts.on("--[no-]level", "use separate level shifter") do |v|
61
+ $options.level = v
62
+ $stdout.sync = true
63
+ end
54
64
  opts.on("-eEDN", "--e=EDN", "supply EDN on command line") do |v|
55
65
  $options.edn = v
56
66
  end
@@ -64,7 +74,7 @@ begin
64
74
  if nm =~ /\A[a-z][a-z0-9]*\z/
65
75
  require "cbor-diagnostic-app/#{nm}"
66
76
  else
67
- raise ArgumentError.new("edn-abnf: app-extension name #{nm} not valid")
77
+ raise ArgumentError.new("edn-abnf: app-extension name #{nm} not installed")
68
78
  end
69
79
  end
70
80
  end
@@ -156,7 +166,7 @@ end
156
166
  begin
157
167
  edn = EDN.from_edn(edn_file)
158
168
  result = edn.tree # XXX .tree?
159
- rescue ArgumentError => e
169
+ rescue CBOR_DIAG::AppParseError, ArgumentError => e
160
170
  puts "** #{e}"
161
171
  exit 1
162
172
  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.7"
3
+ s.version = "0.5.9"
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 ArgumentError, "cbor-diagnostic: Parse Error in b64'#{s}':\n" << EDN.reason(parser, s)
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 ArgumentError, "cbor-diagnostic: Parse Error in dt'#{s}':\n" << EDN.reason(parser, s)
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 ArgumentError, "cbor-diagnostic: Parse Error in h'#{s}':\n" << EDN.reason(parser, s)
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 ArgumentError, "cbor-diagnostic: Parse Error in ip'#{s}':\n" << EDN.reason(parser, s)
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
@@ -39,6 +39,52 @@ class Treetop::Runtime::SyntaxNode
39
39
  def hex_value
40
40
  text_value.to_i(16)
41
41
  end
42
+ def app_parser_level1_diagnostics(e, node)
43
+ outbytes = 0
44
+ if $options.level # do manual level-shifting
45
+ input = node.input
46
+ ol1pos = l1pos = node.interval.begin
47
+ while outbytes <= e.position
48
+ outbytes += 1
49
+ ol1pos = l1pos
50
+ c1 = input[l1pos]
51
+ if c1 == "\\" # escapable-s
52
+ c2 = input[l1pos += 1]
53
+ if c2 == "u" # hexchar-s
54
+ c3 = input[l1pos += 1]
55
+ if c3 == "{"
56
+ l1pos = input.index("}", l1pos)
57
+ else
58
+ if (input[l1pos, 4].to_i(16) & 0xFC00) == 0xD800 # high-surrogate
59
+ l1pos += 6 # low-surrogate
60
+ end
61
+ l1pos += 3 # non-surrogate
62
+ end
63
+ end
64
+ end
65
+ l1pos += 1
66
+ end
67
+ intv = ol1pos...l1pos
68
+ else
69
+ intv = node.interval.end...(node.interval.end+1) # default: closing '
70
+ node.elements.each_with_index do |el, i|
71
+ outbytes += el.ast.size
72
+ if outbytes > e.position
73
+ intv = el.interval
74
+ break
75
+ end
76
+ end
77
+ end
78
+ failure_index = intv.begin
79
+ failure_line = node.input.line_of(failure_index)
80
+ failure_column = node.input.column_of(failure_index)
81
+ reason = "** Line #{failure_line}, column #{failure_column}:\n"
82
+ if line = node.input.lines.to_a[failure_line - 1]
83
+ reason << line
84
+ reason << "\n#{'~' * (failure_column - 1)}#{'^' * intv.size}"
85
+ end
86
+ warn reason
87
+ end
42
88
  end
43
89
 
44
90
 
@@ -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
- ::EDNGRAMMAR::APPS[app].decode(app, data)
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.7
4
+ version: 0.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-15 00:00:00.000000000 Z
10
+ date: 2025-07-08 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: '0'
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: '0'
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