ParseTree 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,11 @@
1
+ *** 1.3.5 / 2005-04-19
2
+
3
+ + 2 minor enhancement
4
+ + Added dynamic exception handling on a per node-type basis (BIG).
5
+ + Added -c=classname to parse_tree_show to help w/ core classes.
6
+ + 1 bug fix
7
+ + Fixed dependency specification error in gemspec.
8
+
1
9
  *** 1.3.4 / 2005-02-09
2
10
 
3
11
  + 2 bug fixes
@@ -14,3 +14,4 @@ test/test_all.rb
14
14
  test/test_composite_sexp_processor.rb
15
15
  test/test_parse_tree.rb
16
16
  test/test_sexp_processor.rb
17
+ validate.sh
@@ -23,6 +23,7 @@ def discover_new_classes_from
23
23
  end
24
24
 
25
25
  new_classes - old_classes
26
+ new_classes = [ eval($c) ] if defined? $c
26
27
  end
27
28
 
28
29
  $f = false unless defined? $f
@@ -40,4 +40,10 @@ class CompositeSexpProcessor < SexpProcessor
40
40
  end
41
41
  exp
42
42
  end
43
+
44
+ def on(exception, &block)
45
+ @processors.each do |processor|
46
+ processor.on(exception, &block)
47
+ end
48
+ end
43
49
  end
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  class ParseTree
30
30
 
31
- VERSION = '1.3.4'
31
+ VERSION = '1.3.5'
32
32
 
33
33
  ##
34
34
  # Initializes a ParseTree instance. Includes newline nodes if
@@ -310,6 +310,7 @@ class SexpProcessor
310
310
  @expected = Sexp
311
311
  @require_empty = true
312
312
  @sexp_accessors = {}
313
+ @exceptions = {}
313
314
 
314
315
  # we do this on an instance basis so we can subclass it for
315
316
  # different processors.
@@ -334,7 +335,7 @@ class SexpProcessor
334
335
  def process(exp)
335
336
  return nil if exp.nil?
336
337
 
337
- exp_orig = exp.deep_clone if $DEBUG
338
+ exp_orig = exp.deep_clone if $DEBUG or @exceptions.has_key?(exp.first)
338
339
  result = self.expected.new
339
340
 
340
341
  type = exp.first
@@ -355,9 +356,12 @@ class SexpProcessor
355
356
  raise UnsupportedNodeError, "'#{type}' is not a supported node type" if @unsupported.include? type
356
357
 
357
358
  # do a pass through the rewriter first, if any, reassign back to exp
359
+ # TODO: maybe the whole rewriting thing needs to be nuked
358
360
  meth = @rewriters[type]
359
361
  if meth then
360
- new_exp = self.send(meth, exp)
362
+ new_exp = error_handler(type, exp_orig) do
363
+ self.send(meth, exp)
364
+ end
361
365
  # REFACTOR: duplicated from below
362
366
  if @require_empty and not exp.empty? then
363
367
  msg = "exp not empty after #{self.class}.#{meth} on #{exp.inspect}"
@@ -379,14 +383,15 @@ class SexpProcessor
379
383
 
380
384
  exp.shift if @auto_shift_type and meth != @default_method
381
385
 
382
- result = self.send(meth, exp)
386
+ result = error_handler(type, exp_orig) do
387
+ self.send(meth, exp)
388
+ end
389
+
383
390
  raise TypeError, "Result must be a #{@expected}, was #{result.class}:#{result.inspect}" unless @expected === result
384
391
 
385
392
  if @require_empty and not exp.empty? then
386
393
  msg = "exp not empty after #{self.class}.#{meth} on #{exp.inspect}"
387
- if $DEBUG then
388
- msg += " from #{exp_orig.inspect}"
389
- end
394
+ msg += " from #{exp_orig.inspect}" if $DEBUG
390
395
  raise NotEmptyError, msg
391
396
  end
392
397
  else
@@ -395,7 +400,9 @@ class SexpProcessor
395
400
  sub_exp = exp.shift
396
401
  sub_result = nil
397
402
  if Array === sub_exp then
398
- sub_result = process(sub_exp)
403
+ sub_result = error_handler(type, exp_orig) do
404
+ process(sub_exp)
405
+ end
399
406
  raise "Result is a bad type" unless Array === sub_exp
400
407
  raise "Result does not have a type in front: #{sub_exp.inspect}" unless Symbol === sub_exp.first unless sub_exp.empty?
401
408
  else
@@ -413,7 +420,9 @@ class SexpProcessor
413
420
  # nothing to do, on purpose
414
421
  end
415
422
  else
416
- raise UnknownNodeError, "Bug! Unknown type #{type.inspect} to #{self.class}"
423
+ msg = "Bug! Unknown node-type #{type.inspect} to #{self.class}"
424
+ msg += " in #{exp_orig.inspect} from #{caller.inspect}" if $DEBUG
425
+ raise UnknownNodeError, msg
417
426
  end
418
427
  end
419
428
  result
@@ -431,6 +440,26 @@ class SexpProcessor
431
440
  list.first != typ
432
441
  end
433
442
 
443
+ def error_handler(type, exp=nil) # :nodoc:
444
+ if @exceptions.has_key? type then
445
+ begin
446
+ return yield
447
+ rescue Exception => err
448
+ return @exceptions[type].call(self, exp, err)
449
+ end
450
+ else
451
+ return yield
452
+ end
453
+ end
454
+ private :error_handler
455
+
456
+ ##
457
+ # Registers an error handler for +node+
458
+
459
+ def on(node, &block)
460
+ @exceptions[node] = block
461
+ end
462
+
434
463
  ##
435
464
  # A fairly generic processor for a dummy node. Dummy nodes are used
436
465
  # when your processor is doing a complicated rewrite that replaces
@@ -0,0 +1,31 @@
1
+ #!/bin/bash
2
+
3
+ # set -xv
4
+
5
+ trap "exit 1" 1 2 3 15
6
+
7
+ DIRS="-I../../metaruby/dev/tests/builtin -I../../metaruby/dev/tests -Ilib"
8
+ for d in $(ls -d ../../*/dev); do
9
+ DIRS="-I$d $DIRS"
10
+ done
11
+
12
+ if [ -f rb.bad.txt ]; then
13
+ mv rb.bad.txt rb.files.txt
14
+ else
15
+ find ../../*/dev /usr/local/lib/ruby/1.8/ -name \*.rb > rb.files.txt
16
+ fi
17
+
18
+ total_count=$(wc -l rb.files.txt | awk '{print $1}')
19
+ curr_count=0
20
+ for f in $(cat rb.files.txt); do
21
+ curr_count=$(($curr_count + 1))
22
+ if GEM_SKIP=ParseTree ruby $DIRS ./bin/parse_tree_show -q $f > /dev/null 2> rb.err.txt < /dev/null; then
23
+ echo $f >> rb.good.txt
24
+ status=pass
25
+ else
26
+ echo $f >> rb.bad.txt
27
+ status=fail
28
+ fi
29
+ fname=`basename $f`
30
+ printf "%4d/%4d: %s %s\n" $curr_count $total_count $status $fname
31
+ done
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.4
2
+ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: ParseTree
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.3.4
7
- date: 2005-02-09
6
+ version: 1.3.5
7
+ date: 2005-04-19
8
8
  summary: Extract and enumerate ruby parse trees.
9
9
  require_paths:
10
10
  - lib
@@ -34,7 +34,6 @@ files:
34
34
  - Makefile
35
35
  - Manifest.txt
36
36
  - README.txt
37
- - ParseTree.gemspec
38
37
  - bin/parse_tree_abc
39
38
  - bin/parse_tree_deps
40
39
  - bin/parse_tree_show
@@ -46,6 +45,7 @@ files:
46
45
  - test/test_composite_sexp_processor.rb
47
46
  - test/test_parse_tree.rb
48
47
  - test/test_sexp_processor.rb
48
+ - validate.sh
49
49
  test_files:
50
50
  - test/test_all.rb
51
51
  rdoc_options: []
@@ -55,6 +55,15 @@ executables:
55
55
  - parse_tree_deps
56
56
  - parse_tree_show
57
57
  extensions: []
58
- requirements:
59
- - RubyInline.
60
- dependencies: []
58
+ requirements: []
59
+ dependencies:
60
+ - !ruby/object:Gem::Dependency
61
+ name: RubyInline
62
+ version_requirement:
63
+ version_requirements: !ruby/object:Gem::Version::Requirement
64
+ requirements:
65
+ -
66
+ - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ version:
@@ -1,39 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'rubygems'
4
- $: << "./lib"
5
- require 'parse_tree'
6
-
7
- spec = Gem::Specification.new do |s|
8
-
9
- s.name = 'ParseTree'
10
- s.version = ParseTree::VERSION
11
- s.summary = "Extract and enumerate ruby parse trees."
12
-
13
- paragraphs = File.read("README.txt").split(/\n\n+/)
14
- s.description = paragraphs[2]
15
- puts "Description = #{s.description}"
16
-
17
- s.requirements << "RubyInline."
18
- s.files = IO.readlines("Manifest.txt").map {|f| f.chomp }
19
-
20
- s.require_paths = ['lib', 'test']
21
- s.autorequire = 'parse_tree'
22
-
23
- s.bindir = "bin"
24
- s.executables = s.files.grep(Regexp.new(s.bindir)) { |f| File.basename(f) }
25
- puts "Executables = #{s.executables.join(", ")}"
26
-
27
- s.has_rdoc = true
28
- s.test_suite_file = "test/test_all.rb"
29
-
30
- s.author = "Ryan Davis"
31
- s.email = "ryand-ruby@zenspider.com"
32
- s.homepage = "http://www.zenspider.com/ZSS/Products/ParseTree/"
33
- s.rubyforge_project = "parsetree"
34
- end
35
-
36
- if $0 == __FILE__
37
- Gem.manage_gems
38
- Gem::Builder.new(spec).build
39
- end