ast 2.1.0 → 2.2.0
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/README.md +3 -3
- data/ast.gemspec +1 -1
- data/lib/ast/node.rb +30 -9
- data/test/test_ast.rb +26 -5
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6fd328f8be0444eea7ebadfba831f783f87defe1
         | 
| 4 | 
            +
              data.tar.gz: ee6204555aec2a37f32aa1db514a7a43dd959d77
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 32abdd8a6d4ba69e9433c307d9048358d39423c621a8af819649f9cc712ada40cdfd21289549a5478d1db68c695eab51b4edb7bae5966381284735ebc9cd65bc
         | 
| 7 | 
            +
              data.tar.gz: a680513585f7b67ef99b25e621cf5bbea81183d2412e3c237d756cc82faa21a32775ea050251bf893aeeba813699a27104705f6032fb94c7e1fbb38f212c983d
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,8 +1,8 @@ | |
| 1 1 | 
             
            # AST
         | 
| 2 2 |  | 
| 3 | 
            -
            [](https://travis-ci.org/whitequark/ast)
         | 
| 4 | 
            +
            [](https://codeclimate.com/github/whitequark/ast)
         | 
| 5 | 
            +
            [](https://coveralls.io/r/whitequark/ast)
         | 
| 6 6 |  | 
| 7 7 | 
             
            AST is a small library for working with immutable abstract syntax trees.
         | 
| 8 8 |  | 
    
        data/ast.gemspec
    CHANGED
    
    
    
        data/lib/ast/node.rb
    CHANGED
    
    | @@ -80,7 +80,7 @@ module AST | |
| 80 80 | 
             
                # By default, each entry in the `properties` hash is assigned to
         | 
| 81 81 | 
             
                # an instance variable in this instance of Node. A subclass should define
         | 
| 82 82 | 
             
                # attribute readers for such variables. The values passed in the hash
         | 
| 83 | 
            -
                # are not frozen or whitelisted; such behavior can also be implemented | 
| 83 | 
            +
                # are not frozen or whitelisted; such behavior can also be implemented
         | 
| 84 84 | 
             
                # by subclassing Node and overriding this method.
         | 
| 85 85 | 
             
                #
         | 
| 86 86 | 
             
                # @return [nil]
         | 
| @@ -104,6 +104,7 @@ module AST | |
| 104 104 | 
             
                def dup
         | 
| 105 105 | 
             
                  self
         | 
| 106 106 | 
             
                end
         | 
| 107 | 
            +
                alias :clone :dup
         | 
| 107 108 |  | 
| 108 109 | 
             
                # Returns a new instance of Node where non-nil arguments replace the
         | 
| 109 110 | 
             
                # corresponding fields of `self`.
         | 
| @@ -166,13 +167,6 @@ module AST | |
| 166 167 |  | 
| 167 168 | 
             
                alias << append
         | 
| 168 169 |  | 
| 169 | 
            -
                # Converts `self` to a concise s-expression, omitting any children.
         | 
| 170 | 
            -
                #
         | 
| 171 | 
            -
                # @return [String]
         | 
| 172 | 
            -
                def to_s
         | 
| 173 | 
            -
                  "(#{fancy_type} ...)"
         | 
| 174 | 
            -
                end
         | 
| 175 | 
            -
             | 
| 176 170 | 
             
                # Returns {#children}. This is very useful in order to decompose nodes
         | 
| 177 171 | 
             
                # concisely. For example:
         | 
| 178 172 | 
             
                #
         | 
| @@ -211,7 +205,34 @@ module AST | |
| 211 205 |  | 
| 212 206 | 
             
                  sexp
         | 
| 213 207 | 
             
                end
         | 
| 214 | 
            -
             | 
| 208 | 
            +
             | 
| 209 | 
            +
                alias to_s to_sexp
         | 
| 210 | 
            +
             | 
| 211 | 
            +
                # Converts `self` to a s-expression ruby string.
         | 
| 212 | 
            +
                # The code return will recreate the node, using the sexp module s()
         | 
| 213 | 
            +
                #
         | 
| 214 | 
            +
                # @param  [Integer] indent Base indentation level.
         | 
| 215 | 
            +
                # @return [String]
         | 
| 216 | 
            +
                def inspect(indent=0)
         | 
| 217 | 
            +
                  indented = "  " * indent
         | 
| 218 | 
            +
                  sexp = "#{indented}s(:#{@type}"
         | 
| 219 | 
            +
             | 
| 220 | 
            +
                  first_node_child = children.index do |child|
         | 
| 221 | 
            +
                    child.is_a?(Node) || child.is_a?(Array)
         | 
| 222 | 
            +
                  end || children.count
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                  children.each_with_index do |child, idx|
         | 
| 225 | 
            +
                    if child.is_a?(Node) && idx >= first_node_child
         | 
| 226 | 
            +
                      sexp << ",\n#{child.inspect(indent + 1)}"
         | 
| 227 | 
            +
                    else
         | 
| 228 | 
            +
                      sexp << ", #{child.inspect}"
         | 
| 229 | 
            +
                    end
         | 
| 230 | 
            +
                  end
         | 
| 231 | 
            +
             | 
| 232 | 
            +
                  sexp << ")"
         | 
| 233 | 
            +
             | 
| 234 | 
            +
                  sexp
         | 
| 235 | 
            +
                end
         | 
| 215 236 |  | 
| 216 237 | 
             
                # @return [AST::Node] self
         | 
| 217 238 | 
             
                def to_ast
         | 
    
        data/test/test_ast.rb
    CHANGED
    
    | @@ -30,6 +30,10 @@ describe AST::Node do | |
| 30 30 | 
             
                @node.dup.should.equal? @node
         | 
| 31 31 | 
             
              end
         | 
| 32 32 |  | 
| 33 | 
            +
              it 'should return self when cloning' do
         | 
| 34 | 
            +
                @node.clone.should.equal? @node
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 33 37 | 
             
              it 'should return an updated node, but only if needed' do
         | 
| 34 38 | 
             
                @node.updated().should.be.identical_to @node
         | 
| 35 39 | 
             
                @node.updated(:node).should.be.identical_to @node
         | 
| @@ -51,11 +55,6 @@ describe AST::Node do | |
| 51 55 | 
             
                updated.meta.should.equal 'other_value'
         | 
| 52 56 | 
             
              end
         | 
| 53 57 |  | 
| 54 | 
            -
              it 'should use fancy type in to_s' do
         | 
| 55 | 
            -
                node = AST::Node.new(:ast_node)
         | 
| 56 | 
            -
                node.to_s.should.equal '(ast-node ...)'
         | 
| 57 | 
            -
              end
         | 
| 58 | 
            -
             | 
| 59 58 | 
             
              it 'should format to_sexp correctly' do
         | 
| 60 59 | 
             
                AST::Node.new(:a, [ :sym, [ 1, 2 ] ]).to_sexp.should.equal '(a :sym [1, 2])'
         | 
| 61 60 | 
             
                AST::Node.new(:a, [ :sym, @node ]).to_sexp.should.equal "(a :sym\n  (node 0 1))"
         | 
| @@ -64,6 +63,28 @@ describe AST::Node do | |
| 64 63 | 
             
                ]).to_sexp.should.equal "(a :sym\n  (b\n    (node 0 1)\n    (node 0 1)))"
         | 
| 65 64 | 
             
              end
         | 
| 66 65 |  | 
| 66 | 
            +
              it 'should format to_s correctly' do
         | 
| 67 | 
            +
                AST::Node.new(:a, [ :sym, [ 1, 2 ] ]).to_s.should.equal '(a :sym [1, 2])'
         | 
| 68 | 
            +
                AST::Node.new(:a, [ :sym, @node ]).to_s.should.equal "(a :sym\n  (node 0 1))"
         | 
| 69 | 
            +
                AST::Node.new(:a, [ :sym,
         | 
| 70 | 
            +
                  AST::Node.new(:b, [ @node, @node ])
         | 
| 71 | 
            +
                ]).to_s.should.equal "(a :sym\n  (b\n    (node 0 1)\n    (node 0 1)))"
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              it 'should format inspect correctly' do
         | 
| 75 | 
            +
                AST::Node.new(:a, [ :sym, [ 1, 2 ] ]).inspect.should.equal "s(:a, :sym, [1, 2])"
         | 
| 76 | 
            +
                AST::Node.new(:a, [ :sym,
         | 
| 77 | 
            +
                  AST::Node.new(:b, [ @node, @node ])
         | 
| 78 | 
            +
                ]).inspect.should.equal "s(:a, :sym,\n  s(:b,\n    s(:node, 0, 1),\n    s(:node, 0, 1)))"
         | 
| 79 | 
            +
              end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
              it 'should recreate inspect output' do
         | 
| 82 | 
            +
                simple_node = AST::Node.new(:a, [ :sym, [ 1, 2 ] ])
         | 
| 83 | 
            +
                eval(simple_node.inspect).should.equal simple_node
         | 
| 84 | 
            +
                complex_node =  s(:a ,  :sym,  s(:b, s(:node,  0,  1),  s(:node,  0,  1)))
         | 
| 85 | 
            +
                eval(complex_node.inspect).should.equal complex_node
         | 
| 86 | 
            +
              end
         | 
| 87 | 
            +
             | 
| 67 88 | 
             
              it 'should return self in to_ast' do
         | 
| 68 89 | 
             
                @node.to_ast.should.be.identical_to @node
         | 
| 69 90 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ast
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2. | 
| 4 | 
            +
              version: 2.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - whitequark
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-12-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rake
         |