abnftt 0.2.6 → 0.2.7

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: 267bcebab4bd13c22da536e87b6ccd3444b214db589a5e9d4b054a56ffe3a686
4
- data.tar.gz: cf4c222a9825e210e635989837ba43432e87661ba6e5e98a9a52aedcfbdad055
3
+ metadata.gz: 436afd21fea00a7369bf5dfdfdcc0a61b33ee0b14f482a6d1c00488a520c93c1
4
+ data.tar.gz: 93cb2255e048e4482c4245e9beb6bf635a79b253124359a8c0debbd2abb204b2
5
5
  SHA512:
6
- metadata.gz: 28fe16c851f050e8072bdf939b45569fde9233fbeb26a2e43169fa04b1c66e85e43e893056faab3b87a4e5c49f2f7cea08274dd852c26f8d42688a85198eab57
7
- data.tar.gz: 0f4977a6b13b8b4a621b594a31ad87d6759b5780bb59b98f7afc3ab4ac3e70fd2f9ee5cb9f710b8db1ce79e8f411734ec1517ad829456f3cd0f4a383f683d721
6
+ metadata.gz: '09621b3970222f8de758894c6fa6c58821fca89980612234ca31cdedae11fcc1c2c9b2e1fd9edb873865169b640926e049388888a82da7baa4b1dfa972f37dde'
7
+ data.tar.gz: 4f77b32132f12ae7a2f6c91b250df5213fdb386c21ecd6fe02c6470115be7996448eefbd94f0e9cd833cc446a7a451c7ff65567069cd15695e6093c11505bd43
data/abnftt.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "abnftt"
3
- s.version = "0.2.6"
3
+ s.version = "0.2.7"
4
4
  s.summary = "RFC 5234+7405 ABNF to Treetop"
5
5
  s.description = %q{Less shifty support for tools based on IETF's ABNF}
6
6
  s.author = "Carsten Bormann"
data/bin/abnfrob CHANGED
@@ -26,6 +26,9 @@ begin
26
26
  opts.on("-a", "--asr33", "Line-break to fit on teletype") do |v|
27
27
  $options.asr33 = v
28
28
  end
29
+ opts.on("--ascii", "No escaping of ASCII printables %x20-7e") do |v|
30
+ $options.ascii = v
31
+ end
29
32
  opts.on("--squash=PREFIX", String, "Squash to app-prefix") do |v|
30
33
  $options.squash = v
31
34
  end
@@ -78,7 +81,7 @@ if $options.squash
78
81
  abnf.flatten_ops
79
82
  abnf.flatten_strings
80
83
 
81
- abnf.squash_edn_levels
84
+ abnf.squash_edn_levels(ascii: $options.ascii)
82
85
  abnf.char_range_to_string
83
86
 
84
87
  abnf.share_hex("sq")
@@ -24,7 +24,7 @@ class ABNF
24
24
  ["\x2F", "/"],
25
25
  ["\x5C", "\\"]]
26
26
 
27
- def squash_edn_levels_1(prod)
27
+ def squash_edn_levels_1(prod, **options)
28
28
  f1 = visit(prod) do |here|
29
29
  case here
30
30
  in ["char-range", c1, c2]
@@ -35,12 +35,20 @@ class ABNF
35
35
  ["seq", ["char-range", "\\", "\\"], ["char-range", ev, ev]]
36
36
  end
37
37
  }.compact
38
- old = alt_ranges_legacy(c1.ord, c2.ord)
39
- new = alt_ranges_modern(c1.ord, c2.ord)
38
+ u_escapes = []
39
+ if options[:ascii]
40
+ do_ranges_outside(here, " ", "~") do |l, r|
41
+ u_escapes << alt_ranges_legacy(l, r) # old
42
+ u_escapes << alt_ranges_modern(l, r) # new
43
+ end
44
+ else
45
+ u_escapes << alt_ranges_legacy(c1.ord, c2.ord) # old
46
+ u_escapes << alt_ranges_modern(c1.ord, c2.ord) # new
47
+ end
40
48
  oldnew = ["seq",
41
49
  ["cs", "\\u"],
42
- wrap_flat("alt", [old, new]) ]
43
- [true, wrap_flat("alt", [*lit, *esc, oldnew].sort)]
50
+ wrap_flat("alt", u_escapes) ] if u_escapes != []
51
+ [true, wrap_flat("alt", [*lit, *esc, oldnew].compact.sort)]
44
52
  else
45
53
  false
46
54
  end
@@ -48,9 +56,9 @@ class ABNF
48
56
  flatten_ops_1(f1)
49
57
  end
50
58
 
51
- def squash_edn_levels
59
+ def squash_edn_levels(**options)
52
60
  rules.each do |name, prod|
53
- rules[name] = squash_edn_levels_1(prod)
61
+ rules[name] = squash_edn_levels_1(prod, **options)
54
62
  end
55
63
  end
56
64
 
@@ -32,6 +32,19 @@ class ABNF
32
32
  end
33
33
  end
34
34
 
35
+ def do_ranges_outside(cr, l, r)
36
+ if cr[2] < l || cr[1] > r # outside
37
+ yield cr[1].ord, cr[2].ord
38
+ else
39
+ if cr[1] < l
40
+ yield cr[1].ord, l.ord - 1
41
+ end
42
+ if cr[2] > r
43
+ yield r.ord + 1, cr[2].ord
44
+ end
45
+ end
46
+ end
47
+
35
48
  # Utilities for creating hexadecimal rules from unsigned integers
36
49
 
37
50
  def hexdig_range(l, r)
@@ -355,6 +368,10 @@ class ABNF
355
368
  name = "x#{c6l}#{c6r}"
356
369
  rules[name] ||= here
357
370
  [true, name]
371
+ in ["char-range", l, r] if l >= "0" && r <= "9"
372
+ name = "x#{l}#{r}"
373
+ rules[name] ||= here
374
+ [true, name]
358
375
  else
359
376
  false
360
377
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abnftt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-09 00:00:00.000000000 Z
11
+ date: 2025-01-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Less shifty support for tools based on IETF's ABNF
14
14
  email: cabo@tzi.org