ParseTree 1.3.6 → 1.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/Makefile +2 -2
- data/bin/parse_tree_abc +3 -8
- data/bin/parse_tree_deps +2 -7
- data/bin/parse_tree_show +2 -7
- data/lib/composite_sexp_processor.rb +2 -2
- data/lib/parse_tree.rb +3 -7
- data/lib/sexp_processor.rb +21 -11
- data/test/test_sexp_processor.rb +4 -4
- metadata +3 -3
data/History.txt
CHANGED
data/Makefile
CHANGED
@@ -5,7 +5,7 @@ RUBY_LIB?=$(shell $(RUBY) -rrbconfig -e 'include Config; print CONFIG["sitelibdi
|
|
5
5
|
PREFIX?=/usr/local
|
6
6
|
|
7
7
|
all test: FORCE
|
8
|
-
|
8
|
+
$(RUBY) $(RUBY_DEBUG) $(RUBY_FLAGS) test/test_all.rb
|
9
9
|
|
10
10
|
# we only install test_sexp_processor.rb to help make ruby_to_c's
|
11
11
|
# subclass tests work.
|
@@ -33,7 +33,7 @@ clean:
|
|
33
33
|
-rm -fr diff diff.txt *.gem doc $$HOME/.ruby_inline
|
34
34
|
|
35
35
|
demo:
|
36
|
-
echo 1+1 |
|
36
|
+
echo 1+1 | $(RUBY) $(RUBY_FLAGS) ./bin/parse_tree_show -f
|
37
37
|
|
38
38
|
gem:
|
39
39
|
gem ParseTree.gemspec
|
data/bin/parse_tree_abc
CHANGED
@@ -8,14 +8,9 @@
|
|
8
8
|
|
9
9
|
PARSE_TREE_ABC=true
|
10
10
|
|
11
|
-
begin
|
12
|
-
|
13
|
-
|
14
|
-
rescue LoadError
|
15
|
-
require 'parse_tree'
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'sexp_processor'
|
11
|
+
begin require 'rubygems' rescue LoadError end
|
12
|
+
require 'parse_tree'
|
13
|
+
require 'sexp_processor'
|
19
14
|
|
20
15
|
old_classes = []
|
21
16
|
ObjectSpace.each_object(Module) do |klass|
|
data/bin/parse_tree_deps
CHANGED
@@ -6,13 +6,8 @@ ObjectSpace.each_object(Module) { |klass| old_classes << klass } if defined? $a
|
|
6
6
|
|
7
7
|
require 'pp'
|
8
8
|
|
9
|
-
begin
|
10
|
-
|
11
|
-
require_gem 'ParseTree'
|
12
|
-
rescue LoadError
|
13
|
-
require 'parse_tree'
|
14
|
-
end
|
15
|
-
|
9
|
+
begin require 'rubygems' rescue LoadError end
|
10
|
+
require 'parse_tree'
|
16
11
|
require 'sexp_processor'
|
17
12
|
|
18
13
|
ObjectSpace.each_object(Module) { |klass| old_classes << klass } unless defined? $a
|
data/bin/parse_tree_show
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
#!/usr/local/bin/ruby -ws
|
2
2
|
|
3
3
|
require 'pp'
|
4
|
-
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
|
-
require_gem 'ParseTree'
|
8
|
-
rescue LoadError
|
9
|
-
require 'parse_tree'
|
10
|
-
end
|
4
|
+
begin require 'rubygems' rescue LoadError end
|
5
|
+
require 'parse_tree'
|
11
6
|
|
12
7
|
def discover_new_classes_from
|
13
8
|
old_classes = []
|
@@ -41,9 +41,9 @@ class CompositeSexpProcessor < SexpProcessor
|
|
41
41
|
exp
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def on_error_in(node_type, &block)
|
45
45
|
@processors.each do |processor|
|
46
|
-
processor.
|
46
|
+
processor.on_error_in(node_type, &block)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/lib/parse_tree.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
#!/usr/local/bin/ruby -w
|
2
2
|
|
3
|
-
begin
|
4
|
-
|
5
|
-
require_gem 'RubyInline'
|
6
|
-
rescue LoadError
|
7
|
-
require "inline"
|
8
|
-
end
|
3
|
+
begin require 'rubygems' rescue LoadError end
|
4
|
+
require 'inline'
|
9
5
|
|
10
6
|
##
|
11
7
|
# ParseTree is a RubyInline-style extension that accesses and
|
@@ -28,7 +24,7 @@ end
|
|
28
24
|
|
29
25
|
class ParseTree
|
30
26
|
|
31
|
-
VERSION = '1.3.
|
27
|
+
VERSION = '1.3.7'
|
32
28
|
|
33
29
|
##
|
34
30
|
# Initializes a ParseTree instance. Includes newline nodes if
|
data/lib/sexp_processor.rb
CHANGED
@@ -192,23 +192,33 @@ def s(*args)
|
|
192
192
|
Sexp.new(*args)
|
193
193
|
end
|
194
194
|
|
195
|
+
##
|
196
|
+
# SexpProcessor base exception class.
|
197
|
+
|
198
|
+
class SexpProcessorError < StandardError; end
|
199
|
+
|
195
200
|
##
|
196
201
|
# Raised by SexpProcessor if it sees a node type listed in its
|
197
202
|
# unsupported list.
|
198
203
|
|
199
|
-
class UnsupportedNodeError <
|
204
|
+
class UnsupportedNodeError < SexpProcessorError; end
|
200
205
|
|
201
206
|
##
|
202
207
|
# Raised by SexpProcessor if it is in strict mode and sees a node for
|
203
208
|
# which there is no processor available.
|
204
209
|
|
205
|
-
class UnknownNodeError <
|
210
|
+
class UnknownNodeError < SexpProcessorError; end
|
206
211
|
|
207
212
|
##
|
208
213
|
# Raised by SexpProcessor if a processor did not process every node in
|
209
214
|
# a sexp and @require_empty is true.
|
210
215
|
|
211
|
-
class NotEmptyError <
|
216
|
+
class NotEmptyError < SexpProcessorError; end
|
217
|
+
|
218
|
+
##
|
219
|
+
# Raised if assert_type encounters an unexpected sexp type.
|
220
|
+
|
221
|
+
class SexpTypeError < SexpProcessorError; end
|
212
222
|
|
213
223
|
##
|
214
224
|
# SexpProcessor provides a uniform interface to process Sexps.
|
@@ -260,7 +270,7 @@ class SexpProcessor
|
|
260
270
|
|
261
271
|
##
|
262
272
|
# An array that specifies node types that are unsupported by this
|
263
|
-
# processor.
|
273
|
+
# processor. SexpProcessor will raise UnsupportedNodeError if you try
|
264
274
|
# to process one of those node types.
|
265
275
|
|
266
276
|
attr_accessor :unsupported
|
@@ -389,7 +399,7 @@ class SexpProcessor
|
|
389
399
|
self.send(meth, exp)
|
390
400
|
end
|
391
401
|
|
392
|
-
raise
|
402
|
+
raise SexpTypeError, "Result must be a #{@expected}, was #{result.class}:#{result.inspect}" unless @expected === result
|
393
403
|
|
394
404
|
if @require_empty and not exp.empty? then
|
395
405
|
msg = "exp not empty after #{self.class}.#{meth} on #{exp.inspect}"
|
@@ -431,25 +441,25 @@ class SexpProcessor
|
|
431
441
|
end
|
432
442
|
|
433
443
|
def generate # :nodoc:
|
434
|
-
raise "not implemented yet"
|
444
|
+
raise NotImplementedError, "not implemented yet"
|
435
445
|
end
|
436
446
|
|
437
447
|
##
|
438
448
|
# Raises unless the Sexp type for +list+ matches +typ+
|
439
449
|
|
440
450
|
def assert_type(list, typ)
|
441
|
-
raise
|
451
|
+
raise SexpTypeError, "Expected type #{typ.inspect} in #{list.inspect}" if
|
442
452
|
list.first != typ
|
443
453
|
end
|
444
454
|
|
445
455
|
def error_handler(type, exp=nil) # :nodoc:
|
446
456
|
begin
|
447
457
|
return yield
|
448
|
-
rescue
|
458
|
+
rescue StandardError => err
|
449
459
|
if @exceptions.has_key? type then
|
450
460
|
return @exceptions[type].call(self, exp, err)
|
451
461
|
else
|
452
|
-
puts "#{err.class} Exception thrown while processing #{type} for sexp #{exp.inspect} #{caller.inspect}" if $DEBUG
|
462
|
+
$stderr.puts "#{err.class} Exception thrown while processing #{type} for sexp #{exp.inspect} #{caller.inspect}" if $DEBUG
|
453
463
|
raise
|
454
464
|
end
|
455
465
|
end
|
@@ -459,8 +469,8 @@ class SexpProcessor
|
|
459
469
|
##
|
460
470
|
# Registers an error handler for +node+
|
461
471
|
|
462
|
-
def
|
463
|
-
@exceptions[
|
472
|
+
def on_error_in(node_type, &block)
|
473
|
+
@exceptions[node_type] = block
|
464
474
|
end
|
465
475
|
|
466
476
|
##
|
data/test/test_sexp_processor.rb
CHANGED
@@ -282,7 +282,7 @@ class TestSexpProcessor < Test::Unit::TestCase
|
|
282
282
|
@processor = TestProcessor.new
|
283
283
|
@processor.warn_on_default = false
|
284
284
|
|
285
|
-
assert_raises(
|
285
|
+
assert_raises(SexpTypeError) do
|
286
286
|
@processor.process([:broken, 1, 2, 3])
|
287
287
|
end
|
288
288
|
end
|
@@ -342,7 +342,7 @@ class TestSexpProcessor < Test::Unit::TestCase
|
|
342
342
|
end
|
343
343
|
|
344
344
|
def test_assert_type_miss
|
345
|
-
assert_raise(
|
345
|
+
assert_raise(SexpTypeError) do
|
346
346
|
@processor.assert_type([:thingy, 1, 2, 3], :blah)
|
347
347
|
end
|
348
348
|
end
|
@@ -369,7 +369,7 @@ class TestSexpProcessor < Test::Unit::TestCase
|
|
369
369
|
|
370
370
|
def test_expected
|
371
371
|
assert_equal Sexp, @processor.expected
|
372
|
-
assert_raises(
|
372
|
+
assert_raises(SexpTypeError) do
|
373
373
|
@processor.process([:expected]) # should raise
|
374
374
|
end
|
375
375
|
|
@@ -379,7 +379,7 @@ class TestSexpProcessor < Test::Unit::TestCase
|
|
379
379
|
assert_equal Hash, @processor.expected
|
380
380
|
assert !(Hash === s()), "Hash === s() should not be true"
|
381
381
|
|
382
|
-
assert_raises(
|
382
|
+
assert_raises(SexpTypeError) do
|
383
383
|
@processor.process(s(:string, "string")) # should raise
|
384
384
|
end
|
385
385
|
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.10
|
2
|
+
rubygems_version: 0.8.10.1
|
3
3
|
specification_version: 1
|
4
4
|
name: ParseTree
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.3.
|
7
|
-
date: 2005-
|
6
|
+
version: 1.3.7
|
7
|
+
date: 2005-07-13
|
8
8
|
summary: Extract and enumerate ruby parse trees.
|
9
9
|
require_paths:
|
10
10
|
- lib
|