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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e6933b3f5ea91221735a98fe3546dd85b0f6518f7c9d679b05a2cb110da886d
4
- data.tar.gz: f4a5e5a932367c09c0d50fd07e06880917b5cac56a3ff0414e7a1660a97f21dd
3
+ metadata.gz: 04255d41adaa0533aee35d5a8801909406f679e1e9d3b353c7648dc1dace1836
4
+ data.tar.gz: 460fa154e1d99877e444177a5f4df9fd91f6b811b91175dc84dc3bc57c55dd4e
5
5
  SHA512:
6
- metadata.gz: 9c2ee28b5a7d49da94691310541782e4e227432f1c1cd5690b0cccd48dad6c4c2d0cfb4a113784fb043bab1ca95c8569b10c315483abe05b59fd58d8a26a4197
7
- data.tar.gz: f9ba70bcc72a526da42c94917ca21a768479e5de8127982c5d61c832901a7ff9868285d63bbd23fb4c8fee6c9e0f2cfbf09a708da47b5f982461ea613e76c2a4
6
+ metadata.gz: 9850c97066a8320430de8c74fcac0aced968c6abde74f5a4ae260396de2219fa3e1c56d9a770ddac379a94a0b59e1f5d8d47ed1e0f835bf37c42bc18b35c036a
7
+ data.tar.gz: ab886d8248c6ce0b480d0540e86c67edc6120a475bdca94fa80f0aabe6b3db39d24454776c1bec9939bdb3404e67378800ab0dd5600842ac618140f5a2ffa0a6
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.8"
3
+ s.version = "0.2.9"
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"
@@ -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
- name = "x#{l}#{r}"
373
- rules[name] ||= here
374
- [true, name]
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}"
@@ -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]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abnftt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann