abnftt 0.2.6 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/abnftt.gemspec +1 -1
- data/bin/abnfrob +4 -1
- data/lib/abnftt/abnf-squasher.rb +15 -7
- data/lib/abnftt/abnf-util.rb +40 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e6933b3f5ea91221735a98fe3546dd85b0f6518f7c9d679b05a2cb110da886d
|
4
|
+
data.tar.gz: f4a5e5a932367c09c0d50fd07e06880917b5cac56a3ff0414e7a1660a97f21dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c2ee28b5a7d49da94691310541782e4e227432f1c1cd5690b0cccd48dad6c4c2d0cfb4a113784fb043bab1ca95c8569b10c315483abe05b59fd58d8a26a4197
|
7
|
+
data.tar.gz: f9ba70bcc72a526da42c94917ca21a768479e5de8127982c5d61c832901a7ff9868285d63bbd23fb4c8fee6c9e0f2cfbf09a708da47b5f982461ea613e76c2a4
|
data/abnftt.gemspec
CHANGED
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")
|
data/lib/abnftt/abnf-squasher.rb
CHANGED
@@ -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
|
-
|
39
|
-
|
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",
|
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
|
|
data/lib/abnftt/abnf-util.rb
CHANGED
@@ -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,33 @@ 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]
|
375
|
+
in ["seq", ["cs", "\\u"], *rest]
|
376
|
+
suff = "0"
|
377
|
+
case rest
|
378
|
+
in [["alt", [/^c./, hex], *], *]
|
379
|
+
name = "u-#{hex}"
|
380
|
+
while rules[name] && rules[name] != here
|
381
|
+
name = "u-#{hex}-#{suff.succ!}"
|
382
|
+
end
|
383
|
+
in [["alt", ["seq", [/^c./, hex], *], *], *]
|
384
|
+
name = "u-#{hex}x"
|
385
|
+
while rules[name] && rules[name] != here
|
386
|
+
name = "u-#{hex}x-#{suff.succ!}"
|
387
|
+
end
|
388
|
+
else
|
389
|
+
# require 'neatjson'
|
390
|
+
# warn ::JSON.neat_generate(here)
|
391
|
+
name = "u-#{suff.succ!}"
|
392
|
+
while rules[name] && rules[name] != here
|
393
|
+
name = "u-#{suff.succ!}"
|
394
|
+
end
|
395
|
+
end
|
396
|
+
rules[name] ||= here
|
397
|
+
[true, name]
|
358
398
|
else
|
359
399
|
false
|
360
400
|
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.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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
|