abnftt 0.2.8 → 0.2.10
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 +4 -4
- data/abnftt.gemspec +1 -1
- data/lib/abnfgrammar.rb +44 -13
- data/lib/abnftt/abnf-util.rb +54 -4
- data/lib/abnftt/abnf-writer.rb +5 -0
- metadata +3 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9a087059291d32ed775f03eb1c32af6b495f84ecbaa5769fb6063f8ec649e67d
         | 
| 4 | 
            +
              data.tar.gz: b3fc37446f104478bee6dfc52e762ea173368c00a3b4d11a677259b05cd29bb1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: eaab019ed235a73be1f8089d7764b43295ff94c95ff90bc81689b513a922f5a245c089a985309bb68911c2555c1411a977f943b663340bc8853ded08c01251d3
         | 
| 7 | 
            +
              data.tar.gz: 6476cb791739a7345468ba71d379924712bb94331a987104ee5d24551f8e0ea0b54b624a037c107524b18455bb5d4628dd0546bacf82fe0479f885536b533986
         | 
    
        data/abnftt.gemspec
    CHANGED
    
    
    
        data/lib/abnfgrammar.rb
    CHANGED
    
    | @@ -2530,10 +2530,16 @@ module ABNFGrammar | |
| 2530 2530 | 
             
              end
         | 
| 2531 2531 |  | 
| 2532 2532 | 
             
              module InlineModule0
         | 
| 2533 | 
            -
                def  | 
| 2533 | 
            +
                def inline_module1
         | 
| 2534 | 
            +
                  elements[1]
         | 
| 2535 | 
            +
                end
         | 
| 2534 2536 | 
             
              end
         | 
| 2535 2537 |  | 
| 2536 2538 | 
             
              module InlineModule1
         | 
| 2539 | 
            +
                def ast_wrap(a) ["im", a, text_value] end
         | 
| 2540 | 
            +
              end
         | 
| 2541 | 
            +
             | 
| 2542 | 
            +
              module InlineModule2
         | 
| 2537 2543 | 
             
                def ast_wrap(a) a end
         | 
| 2538 2544 | 
             
              end
         | 
| 2539 2545 |  | 
| @@ -2549,24 +2555,47 @@ module ABNFGrammar | |
| 2549 2555 | 
             
                end
         | 
| 2550 2556 |  | 
| 2551 2557 | 
             
                i0 = index
         | 
| 2552 | 
            -
                 | 
| 2553 | 
            -
                 | 
| 2554 | 
            -
             | 
| 2558 | 
            +
                i1, s1 = index, []
         | 
| 2559 | 
            +
                if (match_len = has_terminal?('&', false, index))
         | 
| 2560 | 
            +
                  r3 = true
         | 
| 2561 | 
            +
                  @index += match_len
         | 
| 2562 | 
            +
                else
         | 
| 2563 | 
            +
                  terminal_parse_failure('\'&\'')
         | 
| 2564 | 
            +
                  r3 = nil
         | 
| 2565 | 
            +
                end
         | 
| 2566 | 
            +
                if r3
         | 
| 2567 | 
            +
                  r2 = r3
         | 
| 2568 | 
            +
                else
         | 
| 2569 | 
            +
                  r2 = instantiate_node(SyntaxNode,input, index...index)
         | 
| 2570 | 
            +
                end
         | 
| 2571 | 
            +
                s1 << r2
         | 
| 2572 | 
            +
                if r2
         | 
| 2573 | 
            +
                  r4 = _nt_inline_module1
         | 
| 2574 | 
            +
                  s1 << r4
         | 
| 2575 | 
            +
                end
         | 
| 2576 | 
            +
                if s1.last
         | 
| 2577 | 
            +
                  r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
         | 
| 2578 | 
            +
                  r1.extend(InlineModule0)
         | 
| 2579 | 
            +
                  r1.extend(InlineModule1)
         | 
| 2580 | 
            +
                else
         | 
| 2581 | 
            +
                  @index = i1
         | 
| 2582 | 
            +
                  r1 = nil
         | 
| 2583 | 
            +
                end
         | 
| 2555 2584 | 
             
                if r1
         | 
| 2556 2585 | 
             
                  r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
         | 
| 2557 2586 | 
             
                  r0 = r1
         | 
| 2558 2587 | 
             
                else
         | 
| 2559 2588 | 
             
                  if (match_len = has_terminal?('', false, index))
         | 
| 2560 | 
            -
                     | 
| 2561 | 
            -
                     | 
| 2589 | 
            +
                    r5 = instantiate_node(SyntaxNode,input, index...(index + match_len))
         | 
| 2590 | 
            +
                    r5.extend(InlineModule2)
         | 
| 2562 2591 | 
             
                    @index += match_len
         | 
| 2563 2592 | 
             
                  else
         | 
| 2564 2593 | 
             
                    terminal_parse_failure('\'\'')
         | 
| 2565 | 
            -
                     | 
| 2594 | 
            +
                    r5 = nil
         | 
| 2566 2595 | 
             
                  end
         | 
| 2567 | 
            -
                  if  | 
| 2568 | 
            -
                     | 
| 2569 | 
            -
                    r0 =  | 
| 2596 | 
            +
                  if r5
         | 
| 2597 | 
            +
                    r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
         | 
| 2598 | 
            +
                    r0 = r5
         | 
| 2570 2599 | 
             
                  else
         | 
| 2571 2600 | 
             
                    @index = i0
         | 
| 2572 2601 | 
             
                    r0 = nil
         | 
| @@ -2578,10 +2607,12 @@ module ABNFGrammar | |
| 2578 2607 | 
             
                r0
         | 
| 2579 2608 | 
             
              end
         | 
| 2580 2609 |  | 
| 2581 | 
            -
            end
         | 
| 2582 2610 |  | 
| 2583 | 
            -
            class  | 
| 2584 | 
            -
             | 
| 2611 | 
            +
              class Parser < Treetop::Runtime::CompiledParser
         | 
| 2612 | 
            +
                include ABNFGrammar
         | 
| 2613 | 
            +
              end
         | 
| 2585 2614 | 
             
            end
         | 
| 2586 2615 |  | 
| 2616 | 
            +
            ABNFGrammarParser = ABNFGrammar::Parser
         | 
| 2617 | 
            +
             | 
| 2587 2618 |  | 
    
        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]
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,13 @@ | |
| 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.10
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Carsten Bormann
         | 
| 8 | 
            -
            autorequire:
         | 
| 9 8 | 
             
            bindir: bin
         | 
| 10 9 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2025- | 
| 10 | 
            +
            date: 2025-04-29 00:00:00.000000000 Z
         | 
| 12 11 | 
             
            dependencies: []
         | 
| 13 12 | 
             
            description: Less shifty support for tools based on IETF's ABNF
         | 
| 14 13 | 
             
            email: cabo@tzi.org
         | 
| @@ -34,7 +33,6 @@ homepage: http://github.com/cabo/abnftt | |
| 34 33 | 
             
            licenses:
         | 
| 35 34 | 
             
            - MIT
         | 
| 36 35 | 
             
            metadata: {}
         | 
| 37 | 
            -
            post_install_message:
         | 
| 38 36 | 
             
            rdoc_options: []
         | 
| 39 37 | 
             
            require_paths:
         | 
| 40 38 | 
             
            - lib
         | 
| @@ -49,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 49 47 | 
             
                - !ruby/object:Gem::Version
         | 
| 50 48 | 
             
                  version: '0'
         | 
| 51 49 | 
             
            requirements: []
         | 
| 52 | 
            -
            rubygems_version: 3. | 
| 53 | 
            -
            signing_key:
         | 
| 50 | 
            +
            rubygems_version: 3.6.2
         | 
| 54 51 | 
             
            specification_version: 4
         | 
| 55 52 | 
             
            summary: RFC 5234+7405 ABNF to Treetop
         | 
| 56 53 | 
             
            test_files: []
         |