parser_node_ext 1.0.0 → 1.1.1
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/CHANGELOG.md +9 -0
- data/Gemfile.lock +2 -2
- data/README.md +13 -3
- data/lib/parser_node_ext/version.rb +1 -1
- data/lib/parser_node_ext.rb +38 -14
- metadata +3 -4
- data/sig/parser_node_ext.rbs +0 -38
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: fac844753c169838574a48c56d9ea740d7de80bbe80e2d5edf8dc199c59ea512
         | 
| 4 | 
            +
              data.tar.gz: 0caa0e5dba4f6769ad2d01ed011a01c2c7266d29adf102508482f185421fdef4
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: af230faaea69ad75bd6c4afddc4b0cce04498fb173c260f175164e954377ee7198721cb19ddf3eba764ba9da12b42b6b5764dd2b687342f277d7bff37b8f1444
         | 
| 7 | 
            +
              data.tar.gz: 989b25efea51c0b4d732e9db822e1450c6b67e7f079af6de96fe71849f48141c894980e7d402eeca56a6014bb227d418e9cccde92adc2385a7f8949b398d2059
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                parser_node_ext (1. | 
| 4 | 
            +
                parser_node_ext (1.1.1)
         | 
| 5 5 | 
             
                  parser
         | 
| 6 6 |  | 
| 7 7 | 
             
            GEM
         | 
| @@ -9,7 +9,7 @@ GEM | |
| 9 9 | 
             
              specs:
         | 
| 10 10 | 
             
                ast (2.4.2)
         | 
| 11 11 | 
             
                diff-lcs (1.5.0)
         | 
| 12 | 
            -
                parser (3.2.1 | 
| 12 | 
            +
                parser (3.2.2.1)
         | 
| 13 13 | 
             
                  ast (~> 2.4.1)
         | 
| 14 14 | 
             
                rake (13.0.6)
         | 
| 15 15 | 
             
                rspec (3.11.0)
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,8 +1,15 @@ | |
| 1 1 | 
             
            # ParserNodeExt
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 3 | 
            +
            It assigns names to the child nodes of the [parser](https://rubygems.org/gems/parser).
         | 
| 4 4 |  | 
| 5 | 
            -
             | 
| 5 | 
            +
            It also adds some helpers
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ```ruby
         | 
| 8 | 
            +
            # node is a hash node
         | 
| 9 | 
            +
            node.foo_pair # get the pair node of hash foo key
         | 
| 10 | 
            +
            node.foo_value # get the value node of the hash foo key
         | 
| 11 | 
            +
            node.foo_source # get the source of the value node of the hash foo key
         | 
| 12 | 
            +
            ```
         | 
| 6 13 |  | 
| 7 14 | 
             
            ## Installation
         | 
| 8 15 |  | 
| @@ -22,7 +29,10 @@ Or install it yourself as: | |
| 22 29 |  | 
| 23 30 | 
             
            ## Usage
         | 
| 24 31 |  | 
| 25 | 
            -
             | 
| 32 | 
            +
            ```ruby
         | 
| 33 | 
            +
            require 'parser/current'
         | 
| 34 | 
            +
            require 'parser_node_ext'
         | 
| 35 | 
            +
            ```
         | 
| 26 36 |  | 
| 27 37 | 
             
            ## Development
         | 
| 28 38 |  | 
    
        data/lib/parser_node_ext.rb
    CHANGED
    
    | @@ -367,12 +367,27 @@ module ParserNodeExt | |
| 367 367 | 
             
                    end
         | 
| 368 368 | 
             
                  end
         | 
| 369 369 |  | 
| 370 | 
            +
                  # Get :hash pair node according to specified key.
         | 
| 371 | 
            +
                  # @example
         | 
| 372 | 
            +
                  #   node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
         | 
| 373 | 
            +
                  #   node.hash_pair(:foo) # s(:pair, s(:sym, :foo), s(:sym, :bar))
         | 
| 374 | 
            +
                  # @param [Symbol, String] key value.
         | 
| 375 | 
            +
                  # @return [Parser::AST::Node] hash pair node.
         | 
| 376 | 
            +
                  # @raise [MethodNotSupported] if calls on other node.
         | 
| 377 | 
            +
                  def hash_pair(key)
         | 
| 378 | 
            +
                    if :hash == type
         | 
| 379 | 
            +
                      children.find { |pair_node| pair_node.key.to_value == key }
         | 
| 380 | 
            +
                    else
         | 
| 381 | 
            +
                      raise MethodNotSupported, "hash_pair is not supported for #{self}"
         | 
| 382 | 
            +
                    end
         | 
| 383 | 
            +
                  end
         | 
| 384 | 
            +
             | 
| 370 385 | 
             
                  # Get :hash value node according to specified key.
         | 
| 371 386 | 
             
                  # @example
         | 
| 372 387 | 
             
                  #   node # s(:hash, s(:pair, s(:sym, :foo), s(:sym, :bar)))
         | 
| 373 388 | 
             
                  #   node.hash_value(:foo) # s(:sym, :bar)
         | 
| 374 389 | 
             
                  # @param [Symbol, String] key value.
         | 
| 375 | 
            -
                  # @return [Parser::AST::Node] hash value  | 
| 390 | 
            +
                  # @return [Parser::AST::Node] hash value node.
         | 
| 376 391 | 
             
                  # @raise [MethodNotSupported] if calls on other node.
         | 
| 377 392 | 
             
                  def hash_value(key)
         | 
| 378 393 | 
             
                    if :hash == type
         | 
| @@ -450,18 +465,24 @@ module ParserNodeExt | |
| 450 465 | 
             
                  def method_missing(method_name, *args, &block)
         | 
| 451 466 | 
             
                    if :args == type && children.respond_to?(method_name)
         | 
| 452 467 | 
             
                      return children.send(method_name, *args, &block)
         | 
| 453 | 
            -
                    elsif :hash == type && method_name.to_s. | 
| 454 | 
            -
                      key = method_name.to_s | 
| 455 | 
            -
                      return  | 
| 456 | 
            -
                      return  | 
| 468 | 
            +
                    elsif :hash == type && method_name.to_s.end_with?('_pair')
         | 
| 469 | 
            +
                      key = method_name.to_s[0..-6]
         | 
| 470 | 
            +
                      return hash_pair(key.to_sym) if key?(key.to_sym)
         | 
| 471 | 
            +
                      return hash_pair(key.to_s) if key?(key.to_s)
         | 
| 457 472 |  | 
| 458 473 | 
             
                      return nil
         | 
| 459 | 
            -
                    elsif :hash == type && method_name.to_s. | 
| 460 | 
            -
                      key = method_name.to_s | 
| 474 | 
            +
                    elsif :hash == type && method_name.to_s.end_with?('_value')
         | 
| 475 | 
            +
                      key = method_name.to_s[0..-7]
         | 
| 476 | 
            +
                      return hash_value(key.to_sym) if key?(key.to_sym)
         | 
| 477 | 
            +
                      return hash_value(key.to_s) if key?(key.to_s)
         | 
| 478 | 
            +
             | 
| 479 | 
            +
                      return nil
         | 
| 480 | 
            +
                    elsif :hash == type && method_name.to_s.end_with?('_source')
         | 
| 481 | 
            +
                      key = method_name.to_s[0..-8]
         | 
| 461 482 | 
             
                      return hash_value(key.to_sym)&.to_source if key?(key.to_sym)
         | 
| 462 483 | 
             
                      return hash_value(key.to_s)&.to_source if key?(key.to_s)
         | 
| 463 484 |  | 
| 464 | 
            -
                      return  | 
| 485 | 
            +
                      return ''
         | 
| 465 486 | 
             
                    end
         | 
| 466 487 |  | 
| 467 488 | 
             
                    super
         | 
| @@ -470,12 +491,15 @@ module ParserNodeExt | |
| 470 491 | 
             
                  def respond_to_missing?(method_name, *args)
         | 
| 471 492 | 
             
                    if :args == type && children.respond_to?(method_name)
         | 
| 472 493 | 
             
                      return true
         | 
| 473 | 
            -
                    elsif :hash == type && method_name.to_s. | 
| 474 | 
            -
                      key = method_name.to_s | 
| 475 | 
            -
                      return  | 
| 476 | 
            -
                    elsif :hash == type && method_name.to_s. | 
| 477 | 
            -
                      key = method_name.to_s | 
| 478 | 
            -
                      return  | 
| 494 | 
            +
                    elsif :hash == type && method_name.to_s.end_with?('_pair')
         | 
| 495 | 
            +
                      key = method_name.to_s[0..-6]
         | 
| 496 | 
            +
                      return key?(key.to_sym) || key?(key.to_s)
         | 
| 497 | 
            +
                    elsif :hash == type && method_name.to_s.end_with?('_value')
         | 
| 498 | 
            +
                      key = method_name.to_s[0..-7]
         | 
| 499 | 
            +
                      return key?(key.to_sym) || key?(key.to_s)
         | 
| 500 | 
            +
                    elsif :hash == type && method_name.to_s.end_with?('_source')
         | 
| 501 | 
            +
                      key = method_name.to_s[0..-8]
         | 
| 502 | 
            +
                      return key?(key.to_sym) || key?(key.to_s)
         | 
| 479 503 | 
             
                    end
         | 
| 480 504 |  | 
| 481 505 | 
             
                    super
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: parser_node_ext
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Richard Huang
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023- | 
| 11 | 
            +
            date: 2023-05-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: parser
         | 
| @@ -41,7 +41,6 @@ files: | |
| 41 41 | 
             
            - lib/parser_node_ext.rb
         | 
| 42 42 | 
             
            - lib/parser_node_ext/version.rb
         | 
| 43 43 | 
             
            - parser_node_ext.gemspec
         | 
| 44 | 
            -
            - sig/parser_node_ext.rbs
         | 
| 45 44 | 
             
            homepage: https://github.com/xinminlabs/parser_node_ext
         | 
| 46 45 | 
             
            licenses: []
         | 
| 47 46 | 
             
            metadata:
         | 
| @@ -63,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 63 62 | 
             
                - !ruby/object:Gem::Version
         | 
| 64 63 | 
             
                  version: '0'
         | 
| 65 64 | 
             
            requirements: []
         | 
| 66 | 
            -
            rubygems_version: 3.4. | 
| 65 | 
            +
            rubygems_version: 3.4.10
         | 
| 67 66 | 
             
            signing_key:
         | 
| 68 67 | 
             
            specification_version: 4
         | 
| 69 68 | 
             
            summary: extend parser node
         | 
    
        data/sig/parser_node_ext.rbs
    DELETED
    
    | @@ -1,38 +0,0 @@ | |
| 1 | 
            -
            module ParserNodeExt
         | 
| 2 | 
            -
              VERSION: String
         | 
| 3 | 
            -
              # See the writing guide of rbs: https://github.com/ruby/rbs#guides
         | 
| 4 | 
            -
             | 
| 5 | 
            -
              def arguments: () -> Array[Parser::AST::Node]
         | 
| 6 | 
            -
              def arguments_count: () -> Integer
         | 
| 7 | 
            -
              def begin: () -> Parser::AST::Node
         | 
| 8 | 
            -
              def body: () -> Array[Parser::AST::Node]
         | 
| 9 | 
            -
              def caller: () -> Parser::AST::Node
         | 
| 10 | 
            -
              def elements: () -> Array[Parser::AST::Node]
         | 
| 11 | 
            -
              def else_statement: () -> Parser::AST::Node
         | 
| 12 | 
            -
              def exceptions: () -> Array[Parser::AST::Node]
         | 
| 13 | 
            -
              def end: () -> Parser::AST::Node
         | 
| 14 | 
            -
              def ensure_body: () -> Array[Parser::AST::Node]
         | 
| 15 | 
            -
              def expression: () -> Parser::AST::Node
         | 
| 16 | 
            -
              def old_name: () -> Symbol
         | 
| 17 | 
            -
              def options: () -> Parser::AST::Node
         | 
| 18 | 
            -
              def operator: () -> Symbol
         | 
| 19 | 
            -
              def if_statement: () -> Parser::AST::Node
         | 
| 20 | 
            -
              def in_statements: () -> Array[Parser::AST::Node]
         | 
| 21 | 
            -
              def key: () -> Parser::AST::Node
         | 
| 22 | 
            -
              def guard: () -> Parser::AST::Node
         | 
| 23 | 
            -
              def left_value: () -> Parser::AST::Node | Symbol
         | 
| 24 | 
            -
              def message: () -> Symbol
         | 
| 25 | 
            -
              def name: () -> Parser::AST::Node | Symbol
         | 
| 26 | 
            -
              def new_name: () -> Symbol
         | 
| 27 | 
            -
              def pairs: () -> Array[Parser::AST::Node]
         | 
| 28 | 
            -
              def parent_class: () -> Parser::AST::Node
         | 
| 29 | 
            -
              def receiver: () -> Parser::AST::Node
         | 
| 30 | 
            -
              def rescue_bodies: () -> Array[Parser::AST::Node]
         | 
| 31 | 
            -
              def right_value: () -> Parser::AST::Node
         | 
| 32 | 
            -
              def self: () -> Parser::AST::Node
         | 
| 33 | 
            -
              def value: () -> Parser::AST::Node
         | 
| 34 | 
            -
              def variable: () -> Parser::AST::Node
         | 
| 35 | 
            -
              def when_statements: () -> Array[Parser::AST::Node]
         | 
| 36 | 
            -
             | 
| 37 | 
            -
              def to_hash: () -> Hash
         | 
| 38 | 
            -
            end
         |