sexp_processor 4.8.0 → 4.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11e44f6312c253038fcf1ab9039d20f03e7703e0
4
- data.tar.gz: 8fdd674b9c830e9436d27941d6c041fe3e3cb7eb
3
+ metadata.gz: c8a4cb1d34e3c86a00ee122db28cf4d3b7d2ef34
4
+ data.tar.gz: bec449692c425f44e6e40da22b7dae0192956640
5
5
  SHA512:
6
- metadata.gz: 6e012cc2080b582e0c34217331594f3d0442f259828e370164147bbcfd78347490e402b66db482ab3c1205a219b8b74043c34d9c4633de768afc9f1a5fbed402
7
- data.tar.gz: 293726bd82c8cb6bdbd05efbcb4046889afa9284e805c481e8532f573d1aaadc8e9eec4dfecf7cea73a3e86193cf5e0237090caa1631607d1fa63c9ee121cd1a
6
+ metadata.gz: 7ca8f74ecc9e62dc1dd2d2eb272b0cd2502255fa956c75bf8bdad60990070ec05a03d8806c6acf6f61f6d30915b5d3caea73410c551f1a21c7eb528d085f7553
7
+ data.tar.gz: ef4dde66d8a7a6903ddad8520c1bba5ac2885c3fea7a13d54f4d6affd7e42780e78faaebf7c70aa7b26a4aca650673c26d9f39a166bebb1d1cd201e31be25bc0
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,17 @@
1
+ === 4.9.0 / 2017-04-13
2
+
3
+ * 9 minor enhancements:
4
+
5
+ * Added Sexp.depth
6
+ * Added Sexp.sexp_type=
7
+ * Cache Sexp.line_max. Massively speeds up large flay runs.
8
+ * Cleaned up SexpProcessor.process handling of result node type.
9
+ * Extend pt_testcase for ruby 2.4 tests.
10
+ * Extended Sexp.method_missing to only print on every invocation if $VERBOSE=1
11
+ * Extended Sexp.method_missing to warn if the expected sub-sexp is not found.
12
+ * Rewrote Sexp.mass to be MUCH faster. Helps tremendously with flay on large files.
13
+ * Warn that Sexp#method_missing was tripped if $DEBUG.
14
+
1
15
  === 4.8.0 / 2017-02-01
2
16
 
3
17
  * 2 minor enhancements:
data/lib/pt_testcase.rb CHANGED
@@ -76,7 +76,7 @@ class ParseTreeTestCase < Minitest::Test
76
76
  end
77
77
 
78
78
  def self.add_19tests name, hash
79
- add_tests "#{name}__19_20_21_22_23", hash # HACK?
79
+ add_tests "#{name}__19_20_21_22_23_24", hash # HACK?
80
80
  end
81
81
 
82
82
  def self.add_19edgecases ruby, sexp, cases
@@ -101,7 +101,7 @@ class ParseTreeTestCase < Minitest::Test
101
101
  testcases[verbose][klass] = testcases[nonverbose][klass]
102
102
  end
103
103
 
104
- VER_RE = "(1[89]|2[0123])"
104
+ VER_RE = "(1[89]|2[01234])"
105
105
 
106
106
  def self.generate_test klass, node, data, input_name, output_name
107
107
  klass.send :define_method, "test_#{node}" do
data/lib/sexp.rb CHANGED
@@ -95,6 +95,10 @@ class Sexp < Array # ZenTest FULL
95
95
  end
96
96
  end
97
97
 
98
+ def depth
99
+ 1 + (each_sexp.map(&:depth).max || 0)
100
+ end
101
+
98
102
  ##
99
103
  # Enumeratates the sexp yielding to +b+ when the node_type == +t+.
100
104
 
@@ -203,21 +207,36 @@ class Sexp < Array # ZenTest FULL
203
207
  # Returns the maximum line number of the children of self.
204
208
 
205
209
  def line_max
206
- self.deep_each.map(&:line).max
210
+ @line_max ||= self.deep_each.map(&:line).max
207
211
  end
208
212
 
209
213
  ##
210
214
  # Returns the size of the sexp, flattened.
211
215
 
212
216
  def mass
213
- @mass ||= self.structure.flatten.size
217
+ @mass ||=
218
+ inject(1) { |t, s|
219
+ if Sexp === s then
220
+ t + s.mass
221
+ else
222
+ t
223
+ end
224
+ }
214
225
  end
215
226
 
216
227
  ##
217
228
  # Returns the node named +node+, deleting it if +delete+ is true.
218
229
 
219
230
  def method_missing meth, delete = false
220
- find_node meth, delete
231
+ r = find_node meth, delete
232
+ if ENV["DEBUG"] then
233
+ if r.nil? then
234
+ warn "%p.method_missing(%p) => nil from %s" % [self, meth, caller.first]
235
+ elsif ENV["VERBOSE"]
236
+ warn "%p.method_missing(%p) from %s" % [self, meth, caller.first]
237
+ end
238
+ end
239
+ r
221
240
  end
222
241
 
223
242
  def respond_to? msg, private = false # :nodoc:
@@ -241,6 +260,13 @@ class Sexp < Array # ZenTest FULL
241
260
  first
242
261
  end
243
262
 
263
+ ##
264
+ # Sets the node type of the Sexp.
265
+
266
+ def sexp_type= v
267
+ self[0] = v
268
+ end
269
+
244
270
  ##
245
271
  # Returns the Sexp body, ie the values without the node type.
246
272
 
@@ -33,7 +33,7 @@ require 'sexp'
33
33
 
34
34
  class SexpProcessor
35
35
 
36
- VERSION = "4.8.0"
36
+ VERSION = "4.9.0"
37
37
 
38
38
  ##
39
39
  # Automatically shifts off the Sexp type before handing the
@@ -278,12 +278,7 @@ class SexpProcessor
278
278
 
279
279
  # NOTE: this is costly, but we are in the generic processor
280
280
  # so we shouldn't hit it too much with RubyToC stuff at least.
281
- #if Sexp === exp and not exp.sexp_type.nil? then
282
- begin
283
- result.sexp_type = exp.sexp_type
284
- rescue Exception
285
- # nothing to do, on purpose
286
- end
281
+ result.sexp_type = exp.sexp_type if Sexp === exp and exp.sexp_type
287
282
  else
288
283
  msg = "Bug! Unknown node-type #{type.inspect} to #{self.class}"
289
284
  msg += " in #{exp_orig.inspect} from #{caller.inspect}" if $DEBUG
data/test/test_sexp.rb CHANGED
@@ -1,10 +1,24 @@
1
1
  $TESTING = true
2
2
 
3
3
  require 'minitest/autorun'
4
+ require "minitest/benchmark" if ENV["BENCH"]
4
5
  require 'sexp_processor'
5
6
  require 'stringio'
6
7
  require 'pp'
7
8
 
9
+ def pyramid_sexp max
10
+ # s(:array,
11
+ # s(:array, s(:s, 1)),
12
+ # s(:array, s(:s, 1), s(:s, 2)),
13
+ # ...
14
+ # s(:array, s(:s, 1), s(:s, 2), ... s(:s, max-1)))
15
+
16
+ s(:array,
17
+ *(1...max).map { |n|
18
+ s(:array, *(1..n).map { |m|
19
+ s(:s, m) })})
20
+ end
21
+
8
22
  class SexpTestCase < Minitest::Test
9
23
  # KEY for regex tests
10
24
  # :a == no change
@@ -235,6 +249,15 @@ class TestSexp < SexpTestCase # ZenTest FULL
235
249
  assert_equal 7, s.mass
236
250
  end
237
251
 
252
+ def test_mass_huge
253
+ max = 100
254
+ sexp = pyramid_sexp max
255
+
256
+ exp = (max*max + max)/2 # pyramid number 1+2+3+...+m
257
+
258
+ assert_equal exp, sexp.mass
259
+ end
260
+
238
261
  def test_method_missing
239
262
  assert_nil @sexp.not_there
240
263
  assert_equal s(:lit, 42), @basic_sexp.lit
@@ -342,6 +365,13 @@ class TestSexp < SexpTestCase # ZenTest FULL
342
365
  assert_equal [42], @basic_sexp.each_sexp.map { |_, n| n }
343
366
  end
344
367
 
368
+ def test_depth
369
+ assert_equal 1, s(:a).depth
370
+ assert_equal 2, s(:a, s(:b)).depth
371
+ assert_equal 3, s(:a, s(:b1, s(:c)), s(:b2)).depth
372
+ assert_equal 5, s(:a, s(:b, s(:c, s(:d, s(:e))))).depth
373
+ end
374
+
345
375
  def test_deep_each
346
376
  result = []
347
377
  @complex_sexp.deep_each { |s| result << s if s.first == :if }
@@ -373,3 +403,30 @@ class TestSexpAny < SexpTestCase
373
403
  end
374
404
 
375
405
  end
406
+
407
+ class BenchSexp < Minitest::Benchmark
408
+ def run
409
+ GC.disable
410
+ super
411
+ ensure
412
+ GC.enable
413
+ end
414
+
415
+ def self.bench_range
416
+ bench_linear 100, 500, 50
417
+ end
418
+
419
+ @@data = Hash[bench_range.map { |n| [n, pyramid_sexp(n)] }]
420
+
421
+ def bench_pyramid
422
+ assert_performance_power do |max|
423
+ pyramid_sexp max
424
+ end
425
+ end
426
+
427
+ def bench_mass
428
+ assert_performance_power do |max|
429
+ @@data[max].mass
430
+ end
431
+ end
432
+ end if ENV["BENCH"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sexp_processor
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.0
4
+ version: 4.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -30,7 +30,7 @@ cert_chain:
30
30
  E4oJcnPkJAr0rw504JGtlZtONZQblwmRJOIdXzolaE3NRGUzGVOUSptZppAKiavY
31
31
  fO6tdKQc/5RfA8oQEkg8hrxA5PQSz4TOFJGLpFvIapEk6tMruQ0bHgkhr9auXg==
32
32
  -----END CERTIFICATE-----
33
- date: 2017-02-01 00:00:00.000000000 Z
33
+ date: 2017-04-13 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: rdoc
metadata.gz.sig CHANGED
Binary file