abnftt 0.2.8 → 0.2.9
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/lib/abnftt/abnf-util.rb +54 -4
- data/lib/abnftt/abnf-writer.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04255d41adaa0533aee35d5a8801909406f679e1e9d3b353c7648dc1dace1836
|
4
|
+
data.tar.gz: 460fa154e1d99877e444177a5f4df9fd91f6b811b91175dc84dc3bc57c55dd4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9850c97066a8320430de8c74fcac0aced968c6abde74f5a4ae260396de2219fa3e1c56d9a770ddac379a94a0b59e1f5d8d47ed1e0f835bf37c42bc18b35c036a
|
7
|
+
data.tar.gz: ab886d8248c6ce0b480d0540e86c67edc6120a475bdca94fa80f0aabe6b3db39d24454776c1bec9939bdb3404e67378800ab0dd5600842ac618140f5a2ffa0a6
|
data/abnftt.gemspec
CHANGED
data/lib/abnftt/abnf-util.rb
CHANGED
@@ -253,6 +253,21 @@ class ABNF
|
|
253
253
|
case here
|
254
254
|
in ["alt", ["cs", c1], ["cs", c2]] if c1.downcase == c2 && c2.upcase == c1
|
255
255
|
[true, ["ci", c1]]
|
256
|
+
in [*rest1, ["cs", c1], ["cs", c2], *rest2] if c1.downcase == c2 && c2.upcase == c1
|
257
|
+
# warn [:PEEP, rest1, c1, c2, rest2].inspect
|
258
|
+
if rest1[0] == "alt"
|
259
|
+
[true, detect_ci([*rest1, ["ci", c1], *rest2])]
|
260
|
+
else
|
261
|
+
false
|
262
|
+
end
|
263
|
+
# This isn't complete...
|
264
|
+
in [*rest1, ["cs", c0], ["cs", c1], ["cs", c2], *rest2] if c1.downcase == c2 && c2.upcase == c1
|
265
|
+
# warn [:PEEP2, rest1, c0, c1, c2, rest2].inspect
|
266
|
+
if rest1[0] == "alt"
|
267
|
+
[true, detect_ci([*rest1, ["cs", c0], ["ci", c1], *rest2])]
|
268
|
+
else
|
269
|
+
false
|
270
|
+
end
|
256
271
|
else
|
257
272
|
false
|
258
273
|
end
|
@@ -347,6 +362,40 @@ class ABNF
|
|
347
362
|
end
|
348
363
|
end)]
|
349
364
|
end])
|
365
|
+
replacements = Hash[
|
366
|
+
rules.map{|k, v|
|
367
|
+
[v, k] if String === v && /^sq-a\d+$/ === v
|
368
|
+
}.compact]
|
369
|
+
# warn [:REPLA, replacements].inspect
|
370
|
+
used = {}
|
371
|
+
used[rules.first.first] = true
|
372
|
+
rules.each do |k, v|
|
373
|
+
visit(v) do |here|
|
374
|
+
if String === here
|
375
|
+
if r = replacements[here]
|
376
|
+
used[r] = true
|
377
|
+
else
|
378
|
+
used[here] = true
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
# TODO: Should not do a h-x09
|
384
|
+
# warn [:USED, used].inspect
|
385
|
+
rules.replace(Hash[rules.map {|k, v|
|
386
|
+
unless replacements[k] || !used[k]
|
387
|
+
if r = replacements[v]
|
388
|
+
v = rules[v]
|
389
|
+
end
|
390
|
+
v = visit(v) do |here|
|
391
|
+
if String === here && (r = replacements[here])
|
392
|
+
# warn [:R, v, r].inspect
|
393
|
+
[true, r]
|
394
|
+
end
|
395
|
+
end
|
396
|
+
[k, v]
|
397
|
+
end
|
398
|
+
}.compact])
|
350
399
|
end
|
351
400
|
|
352
401
|
def share_hex_1(prod, rules)
|
@@ -368,12 +417,13 @@ class ABNF
|
|
368
417
|
name = "x#{c6l}#{c6r}"
|
369
418
|
rules[name] ||= here
|
370
419
|
[true, name]
|
371
|
-
in ["char-range", l, r] if l >= "0" && r <= "9"
|
372
|
-
|
373
|
-
|
374
|
-
|
420
|
+
# in ["char-range", l, r] if l >= "0" && r <= "9"
|
421
|
+
# name = "x#{l}#{r}"
|
422
|
+
# rules[name] ||= here
|
423
|
+
# [true, name]
|
375
424
|
in ["seq", ["cs", "\\u"], *rest]
|
376
425
|
suff = "0"
|
426
|
+
rest = rest.map {|r| share_hex_1(r, rules) }
|
377
427
|
case rest
|
378
428
|
in [["alt", [/^c./, hex], *], *]
|
379
429
|
name = "u-#{hex}"
|
data/lib/abnftt/abnf-writer.rb
CHANGED
@@ -93,6 +93,11 @@ class ABNF
|
|
93
93
|
while l[-1].size > col
|
94
94
|
breakpoint = l[-1][0...col].rindex(' ')
|
95
95
|
break unless breakpoint && breakpoint > 4
|
96
|
+
while (partial = l[-1][0...breakpoint]).count('"').odd?
|
97
|
+
break1 = partial.rindex('"')
|
98
|
+
breakpoint = l[-1][0...break1].rindex(' ')
|
99
|
+
break unless breakpoint && breakpoint > 4
|
100
|
+
end
|
96
101
|
l[-1..-1] = [
|
97
102
|
l[-1][0...breakpoint],
|
98
103
|
" " << l[-1][breakpoint+1..-1]
|