ast 2.3.0 → 2.4.0

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
  SHA1:
3
- metadata.gz: 5188ebb01ae2cb91d0e2dae2e40804376d106e66
4
- data.tar.gz: bb200f5e71042ac5557007ad49c51e4645a00961
3
+ metadata.gz: fa80b25cb36d090155a83e7e24dfb047701f681a
4
+ data.tar.gz: d93cac6b17f6b9b3f61df96a21fd5383cd53a6c7
5
5
  SHA512:
6
- metadata.gz: 397957b342a439a794431ad75d842d8d10d086dc8599dad0077451bd0fcbec5f1b9eb2f0a192958b38d1ce0a2620b53ae23977531ea2e3596c6c43868cdf290a
7
- data.tar.gz: e019bbec67f6c1d0b34410e8f2ddd1587d2a9054e0f7dc60e240387aff5b92a7b0a3bfdea7cfeb771a8ca3544be54327f05d45bf34816f311cbc1634159e619e
6
+ metadata.gz: edd48c34d4d4bb2deb23ce4eda259a7e1454c84a39d2d8b2d90bd489c0cc31f993deea37068aea225ea83470ae9ebb2e0ef603a0efc284b69edc2690456d94d2
7
+ data.tar.gz: 684ac2d08942b7161f0cc30ffac40605138034907c77047752842dd659cfb817826f21fd8ffd8724a27442f3a5bb1a44fbbd825fb4baef914f7905b853f545e1
@@ -1,14 +1,14 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.2
5
4
  - 1.9.3
6
5
  - 2.0
7
6
  - 2.1
8
7
  - 2.2
8
+ - 2.3
9
+ - 2.4.1
9
10
  - jruby-18mode
10
11
  - jruby-19mode
11
- - rbx-2
12
12
 
13
13
  before_install:
14
14
  - gem install bundler
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ast'
3
- s.version = '2.3.0'
3
+ s.version = '2.4.0'
4
4
  s.license = 'MIT'
5
5
  s.authors = ["whitequark"]
6
6
  s.email = ["whitequark@whitequark.org"]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AST
2
4
  # Node is an immutable class, instances of which represent abstract
3
5
  # syntax tree nodes. It combines semantic information (i.e. anything
@@ -42,8 +44,17 @@ module AST
42
44
 
43
45
  # Returns the children of this node.
44
46
  # The returned value is frozen.
47
+ # The to_a alias is useful for decomposing nodes concisely.
48
+ # For example:
49
+ #
50
+ # node = s(:gasgn, :$foo, s(:integer, 1))
51
+ # var_name, value = *node
52
+ # p var_name # => :$foo
53
+ # p value # => (integer 1)
54
+ #
45
55
  # @return [Array]
46
56
  attr_reader :children
57
+ alias to_a children
47
58
 
48
59
  # Returns the precomputed hash value for this node
49
60
  # @return [Fixnum]
@@ -167,20 +178,6 @@ module AST
167
178
 
168
179
  alias << append
169
180
 
170
- # Returns {#children}. This is very useful in order to decompose nodes
171
- # concisely. For example:
172
- #
173
- # node = s(:gasgn, :$foo, s(:integer, 1))
174
- # s
175
- # var_name, value = *node
176
- # p var_name # => :$foo
177
- # p value # => (integer 1)
178
- #
179
- # @return [Array]
180
- def to_a
181
- children
182
- end
183
-
184
181
  # Converts `self` to a pretty-printed s-expression.
185
182
  #
186
183
  # @param [Integer] indent Base indentation level.
@@ -189,12 +186,8 @@ module AST
189
186
  indented = " " * indent
190
187
  sexp = "#{indented}(#{fancy_type}"
191
188
 
192
- first_node_child = children.index do |child|
193
- child.is_a?(Node) || child.is_a?(Array)
194
- end || children.count
195
-
196
- children.each_with_index do |child, idx|
197
- if child.is_a?(Node) && idx >= first_node_child
189
+ children.each do |child|
190
+ if child.is_a?(Node)
198
191
  sexp += "\n#{child.to_sexp(indent + 1)}"
199
192
  else
200
193
  sexp += " #{child.inspect}"
@@ -217,12 +210,8 @@ module AST
217
210
  indented = " " * indent
218
211
  sexp = "#{indented}s(:#{@type}"
219
212
 
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
213
+ children.each do |child|
214
+ if child.is_a?(Node)
226
215
  sexp += ",\n#{child.inspect(indent + 1)}"
227
216
  else
228
217
  sexp += ", #{child.inspect}"
@@ -238,6 +227,22 @@ module AST
238
227
  def to_ast
239
228
  self
240
229
  end
230
+
231
+ # Converts `self` to an Array where the first element is the type as a Symbol,
232
+ # and subsequent elements are the same representation of its children.
233
+ #
234
+ # @return [Array<Symbol, [...Array]>]
235
+ def to_sexp_array
236
+ children_sexp_arrs = children.map do |child|
237
+ if child.is_a?(Node)
238
+ child.to_sexp_array
239
+ else
240
+ child
241
+ end
242
+ end
243
+
244
+ [type, *children_sexp_arrs]
245
+ end
241
246
 
242
247
  protected
243
248
 
@@ -5,10 +5,10 @@ require 'simplecov'
5
5
  require 'coveralls'
6
6
 
7
7
  SimpleCov.start do
8
- self.formatter = SimpleCov::Formatter::MultiFormatter[
8
+ self.formatter = SimpleCov::Formatter::MultiFormatter.new([
9
9
  SimpleCov::Formatter::HTMLFormatter,
10
10
  Coveralls::SimpleCov::Formatter
11
- ]
11
+ ])
12
12
 
13
13
  # Exclude the testsuite itself.
14
14
  add_filter "/test/"
@@ -88,6 +88,13 @@ describe AST::Node do
88
88
  it 'should return self in to_ast' do
89
89
  @node.to_ast.should.be.identical_to @node
90
90
  end
91
+
92
+ it 'should produce to_sexp_array correctly' do
93
+ AST::Node.new(:a, [ :sym, [ 1, 2 ] ]).to_sexp_array.should.equal [:a, :sym, [1, 2]]
94
+ AST::Node.new(:a, [ :sym,
95
+ AST::Node.new(:b, [ @node, @node ])
96
+ ]).to_sexp_array.should.equal [:a, :sym, [:b, [:node, 0, 1], [:node, 0, 1]]]
97
+ end
91
98
 
92
99
  it 'should only use type and children to compute #hash' do
93
100
  @node.hash.should.equal([@node.type, @node.children, @node.class].hash)
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.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - whitequark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-07 00:00:00.000000000 Z
11
+ date: 2018-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -194,9 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  requirements: []
196
196
  rubyforge_project:
197
- rubygems_version: 2.5.1
197
+ rubygems_version: 2.5.2.2
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: A library for working with Abstract Syntax Trees.
201
201
  test_files: []
202
- has_rdoc: