rubyjs 0.7.1 → 0.8.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.
- data/examples/client_server/README +18 -0
- data/examples/client_server/Rakefile +5 -0
- data/examples/client_server/client.js +749 -0
- data/examples/client_server/client.rb +12 -0
- data/examples/client_server/index.html +7 -0
- data/examples/client_server/server.rb +17 -0
- data/examples/hw/hw.js +234 -216
- data/rubyjs.gemspec +2 -2
- data/src/rubyjs.rb +0 -1
- data/src/rubyjs/compiler.rb +21 -8
- data/src/rubyjs/debug_name_generator.rb +23 -6
- data/src/rubyjs/model.rb +14 -8
- data/test/browser.test.html +1 -1
- data/test/browser.test.js +2337 -1992
- data/test/test_yield.rb +2 -0
- metadata +108 -158
- data/patches/parse_tree.rb.diff +0 -34
- data/vendor/ParseTree-1.7.1-patched/History.txt +0 -217
- data/vendor/ParseTree-1.7.1-patched/Manifest.txt +0 -22
- data/vendor/ParseTree-1.7.1-patched/README.txt +0 -110
- data/vendor/ParseTree-1.7.1-patched/Rakefile +0 -41
- data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_abc +0 -89
- data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_audit +0 -28
- data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_deps +0 -62
- data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_show +0 -49
- data/vendor/ParseTree-1.7.1-patched/demo/printer.rb +0 -20
- data/vendor/ParseTree-1.7.1-patched/lib/composite_sexp_processor.rb +0 -49
- data/vendor/ParseTree-1.7.1-patched/lib/parse_tree.rb +0 -1013
- data/vendor/ParseTree-1.7.1-patched/lib/sexp.rb +0 -235
- data/vendor/ParseTree-1.7.1-patched/lib/sexp_processor.rb +0 -330
- data/vendor/ParseTree-1.7.1-patched/lib/unique.rb +0 -15
- data/vendor/ParseTree-1.7.1-patched/test/pt_testcase.rb +0 -1221
- data/vendor/ParseTree-1.7.1-patched/test/something.rb +0 -53
- data/vendor/ParseTree-1.7.1-patched/test/test_all.rb +0 -13
- data/vendor/ParseTree-1.7.1-patched/test/test_composite_sexp_processor.rb +0 -69
- data/vendor/ParseTree-1.7.1-patched/test/test_parse_tree.rb +0 -216
- data/vendor/ParseTree-1.7.1-patched/test/test_sexp.rb +0 -291
- data/vendor/ParseTree-1.7.1-patched/test/test_sexp_processor.rb +0 -244
- data/vendor/ParseTree-1.7.1-patched/validate.sh +0 -31
- data/vendor/ParseTree-1.7.1/History.txt +0 -217
- data/vendor/ParseTree-1.7.1/Manifest.txt +0 -22
- data/vendor/ParseTree-1.7.1/README.txt +0 -110
- data/vendor/ParseTree-1.7.1/Rakefile +0 -41
- data/vendor/ParseTree-1.7.1/bin/parse_tree_abc +0 -89
- data/vendor/ParseTree-1.7.1/bin/parse_tree_audit +0 -28
- data/vendor/ParseTree-1.7.1/bin/parse_tree_deps +0 -62
- data/vendor/ParseTree-1.7.1/bin/parse_tree_show +0 -49
- data/vendor/ParseTree-1.7.1/demo/printer.rb +0 -20
- data/vendor/ParseTree-1.7.1/lib/composite_sexp_processor.rb +0 -49
- data/vendor/ParseTree-1.7.1/lib/parse_tree.rb +0 -1004
- data/vendor/ParseTree-1.7.1/lib/sexp.rb +0 -235
- data/vendor/ParseTree-1.7.1/lib/sexp_processor.rb +0 -330
- data/vendor/ParseTree-1.7.1/lib/unique.rb +0 -15
- data/vendor/ParseTree-1.7.1/test/pt_testcase.rb +0 -1221
- data/vendor/ParseTree-1.7.1/test/something.rb +0 -53
- data/vendor/ParseTree-1.7.1/test/test_all.rb +0 -13
- data/vendor/ParseTree-1.7.1/test/test_composite_sexp_processor.rb +0 -69
- data/vendor/ParseTree-1.7.1/test/test_parse_tree.rb +0 -216
- data/vendor/ParseTree-1.7.1/test/test_sexp.rb +0 -291
- data/vendor/ParseTree-1.7.1/test/test_sexp_processor.rb +0 -244
- data/vendor/ParseTree-1.7.1/validate.sh +0 -31
@@ -1,22 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
README.txt
|
4
|
-
Rakefile
|
5
|
-
bin/parse_tree_abc
|
6
|
-
bin/parse_tree_audit
|
7
|
-
bin/parse_tree_deps
|
8
|
-
bin/parse_tree_show
|
9
|
-
demo/printer.rb
|
10
|
-
lib/composite_sexp_processor.rb
|
11
|
-
lib/parse_tree.rb
|
12
|
-
lib/sexp.rb
|
13
|
-
lib/sexp_processor.rb
|
14
|
-
lib/unique.rb
|
15
|
-
test/pt_testcase.rb
|
16
|
-
test/something.rb
|
17
|
-
test/test_all.rb
|
18
|
-
test/test_composite_sexp_processor.rb
|
19
|
-
test/test_parse_tree.rb
|
20
|
-
test/test_sexp.rb
|
21
|
-
test/test_sexp_processor.rb
|
22
|
-
validate.sh
|
@@ -1,110 +0,0 @@
|
|
1
|
-
ParseTree
|
2
|
-
http://rubyforge.org/projects/parsetree/
|
3
|
-
http://www.zenspider.com/ZSS/Products/ParseTree/
|
4
|
-
support@zenspider.com
|
5
|
-
|
6
|
-
** DESCRIPTION:
|
7
|
-
|
8
|
-
ParseTree is a C extension (using RubyInline) that extracts the parse
|
9
|
-
tree for an entire class or a specific method and returns it as a
|
10
|
-
s-expression (aka sexp) using ruby's arrays, strings, symbols, and
|
11
|
-
integers.
|
12
|
-
|
13
|
-
As an example:
|
14
|
-
|
15
|
-
def conditional1(arg1)
|
16
|
-
if arg1 == 0 then
|
17
|
-
return 1
|
18
|
-
end
|
19
|
-
return 0
|
20
|
-
end
|
21
|
-
|
22
|
-
becomes:
|
23
|
-
|
24
|
-
[:defn,
|
25
|
-
:conditional1,
|
26
|
-
[:scope,
|
27
|
-
[:block,
|
28
|
-
[:args, :arg1],
|
29
|
-
[:if,
|
30
|
-
[:call, [:lvar, :arg1], :==, [:array, [:lit, 0]]],
|
31
|
-
[:return, [:lit, 1]],
|
32
|
-
nil],
|
33
|
-
[:return, [:lit, 0]]]]]
|
34
|
-
|
35
|
-
** FEATURES/PROBLEMS:
|
36
|
-
|
37
|
-
+ Uses RubyInline, so it just drops in.
|
38
|
-
+ Includes SexpProcessor and CompositeSexpProcessor.
|
39
|
-
+ Allows you to write very clean filters.
|
40
|
-
+ Includes parse_tree_show, which lets you quickly snoop code.
|
41
|
-
+ echo "1+1" | parse_tree_show -f for quick snippet output.
|
42
|
-
+ Includes parse_tree_abc, which lets you get abc metrics on code.
|
43
|
-
+ abc metrics = numbers of assignments, branches, and calls.
|
44
|
-
+ whitespace independent metric for method complexity.
|
45
|
-
+ Includes parse_tree_deps, which shows you basic class level dependencies.
|
46
|
-
+ Only works on methods in classes/modules, not arbitrary code.
|
47
|
-
+ Does not work on the core classes, as they are not ruby (yet).
|
48
|
-
|
49
|
-
** SYNOPSYS:
|
50
|
-
|
51
|
-
sexp_array = ParseTree.new.parse_tree(klass)
|
52
|
-
|
53
|
-
or:
|
54
|
-
|
55
|
-
class MyProcessor < SexpProcessor
|
56
|
-
def initialize
|
57
|
-
super
|
58
|
-
self.strict = false
|
59
|
-
end
|
60
|
-
def process_lit(exp)
|
61
|
-
val = exp.shift
|
62
|
-
return val
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
or:
|
67
|
-
|
68
|
-
% ./parse_tree_show myfile.rb
|
69
|
-
|
70
|
-
or:
|
71
|
-
|
72
|
-
% echo "1+1" | ./parse_tree_show -f
|
73
|
-
|
74
|
-
or:
|
75
|
-
|
76
|
-
% ./parse_tree_abc myfile.rb
|
77
|
-
|
78
|
-
** REQUIREMENTS:
|
79
|
-
|
80
|
-
+ RubyInline 3 or better.
|
81
|
-
|
82
|
-
** INSTALL:
|
83
|
-
|
84
|
-
+ sudo rake install
|
85
|
-
+ or: sudo gem install ParseTree
|
86
|
-
|
87
|
-
** LICENSE:
|
88
|
-
|
89
|
-
(The MIT License)
|
90
|
-
|
91
|
-
Copyright (c) 2001-2004 Ryan Davis, Zen Spider Software
|
92
|
-
|
93
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
94
|
-
a copy of this software and associated documentation files (the
|
95
|
-
"Software"), to deal in the Software without restriction, including
|
96
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
97
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
98
|
-
permit persons to whom the Software is furnished to do so, subject to
|
99
|
-
the following conditions:
|
100
|
-
|
101
|
-
The above copyright notice and this permission notice shall be
|
102
|
-
included in all copies or substantial portions of the Software.
|
103
|
-
|
104
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
105
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
106
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
107
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
108
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
109
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
110
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'hoe'
|
5
|
-
|
6
|
-
$: << "../../RubyInline/dev"
|
7
|
-
require './lib/parse_tree.rb'
|
8
|
-
|
9
|
-
Hoe.new("ParseTree", ParseTree::VERSION) do |p|
|
10
|
-
p.rubyforge_name = "parsetree"
|
11
|
-
p.summary = "Extract and enumerate ruby parse trees."
|
12
|
-
p.description = p.paragraphs_of("README.txt", 2).join("\n\n")
|
13
|
-
p.changes = p.paragraphs_of("History.txt", 1).join("\n\n")
|
14
|
-
p.clean_globs << File.expand_path("~/.ruby_inline")
|
15
|
-
p.extra_deps << ['RubyInline', '>= 3.2.0']
|
16
|
-
p.spec_extras[:require_paths] = proc { |paths| paths << 'test' }
|
17
|
-
end
|
18
|
-
|
19
|
-
desc 'Run against ruby 1.9 (from a multiruby install) with -d.'
|
20
|
-
task :test19 do
|
21
|
-
sh "~/.multiruby/install/1_9/bin/ruby -d #{Hoe::RUBY_FLAGS} test/test_all.rb #{Hoe::FILTER}"
|
22
|
-
end
|
23
|
-
|
24
|
-
desc 'Run in gdb'
|
25
|
-
task :debug do
|
26
|
-
puts "RUN: r -d #{Hoe::RUBY_FLAGS} test/test_all.rb #{Hoe::FILTER}"
|
27
|
-
sh "gdb ~/.multiruby/install/19/bin/ruby"
|
28
|
-
end
|
29
|
-
|
30
|
-
desc 'Run a very basic demo'
|
31
|
-
task :demo do
|
32
|
-
sh "echo 1+1 | ruby #{Hoe::RUBY_FLAGS} ./bin/parse_tree_show -f"
|
33
|
-
end
|
34
|
-
|
35
|
-
desc 'Show what tests are not sorted'
|
36
|
-
task :sort do
|
37
|
-
sh "pgrep '^ \\\"(\\w+)' test/pt_testcase.rb | cut -f 2 -d\\\" > x"
|
38
|
-
sh "sort x > y"
|
39
|
-
sh "diff x y"
|
40
|
-
sh "rm -f x y"
|
41
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby -ws
|
2
|
-
|
3
|
-
# ABC metric
|
4
|
-
#
|
5
|
-
# Assignments, Branches, and Calls
|
6
|
-
#
|
7
|
-
# A simple way to measure the complexity of a function or method.
|
8
|
-
|
9
|
-
if defined? $I and String === $I then
|
10
|
-
$I.split(/:/).each do |dir|
|
11
|
-
$: << dir
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
PARSE_TREE_ABC=true
|
16
|
-
|
17
|
-
begin require 'rubygems' rescue LoadError end
|
18
|
-
require 'sexp'
|
19
|
-
require 'parse_tree'
|
20
|
-
require 'sexp_processor'
|
21
|
-
|
22
|
-
old_classes = []
|
23
|
-
ObjectSpace.each_object(Module) do |klass|
|
24
|
-
old_classes << klass
|
25
|
-
end
|
26
|
-
|
27
|
-
ARGV.each do |name|
|
28
|
-
begin
|
29
|
-
require name
|
30
|
-
rescue NameError => err
|
31
|
-
$stderr.puts "ERROR requiring #{name}. Perhaps you need to add some -I's?\n\n#{err}"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
new_classes = []
|
36
|
-
ObjectSpace.each_object(Module) do |klass|
|
37
|
-
new_classes << klass
|
38
|
-
end
|
39
|
-
|
40
|
-
score = {}
|
41
|
-
|
42
|
-
new_classes -= old_classes
|
43
|
-
|
44
|
-
klasses = Sexp.from_array(ParseTree.new.parse_tree(*new_classes))
|
45
|
-
klasses.each do |klass|
|
46
|
-
klass.shift # :class
|
47
|
-
klassname = klass.shift
|
48
|
-
klass.shift # superclass
|
49
|
-
methods = klass
|
50
|
-
|
51
|
-
methods.each do |defn|
|
52
|
-
a=b=c=0
|
53
|
-
defn.shift
|
54
|
-
methodname = defn.shift
|
55
|
-
tokens = defn.structure.flatten
|
56
|
-
tokens.each do |token|
|
57
|
-
case token
|
58
|
-
when :attrasgn, :attrset, :dasgn_curr, :iasgn, :lasgn, :masgn then
|
59
|
-
a += 1
|
60
|
-
when :and, :case, :else, :if, :iter, :or, :rescue, :until, :when, :while then
|
61
|
-
b += 1
|
62
|
-
when :call, :fcall, :super, :vcall, :yield then
|
63
|
-
c += 1
|
64
|
-
when :args, :argscat, :array, :begin, :block, :block_arg, :block_pass, :bool, :cfunc, :colon2, :const, :cvar, :defined, :defn, :dregx, :dstr, :dvar, :dxstr, :ensure, :false, :fbody, :gvar, :hash, :ivar, :lit, :long, :lvar, :match2, :match3, :nil, :not, :nth_ref, :return, :scope, :self, :splat, :str, :to_ary, :true, :unknown, :value, :void, :zarray, :zarray, :zclass, :zsuper then
|
65
|
-
# ignore
|
66
|
-
else
|
67
|
-
puts "unhandled token #{token.inspect}" if $VERBOSE
|
68
|
-
end
|
69
|
-
end
|
70
|
-
key = ["#{klassname}.#{methodname}", a, b, c]
|
71
|
-
val = Math.sqrt(a*a+b*b+c*c)
|
72
|
-
score[key] = val
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
puts "|ABC| = Math.sqrt(assignments^2 + branches^2 + calls^2)"
|
77
|
-
puts
|
78
|
-
count = 1
|
79
|
-
ta = tb = tc = tval = 0
|
80
|
-
score.sort_by { |k,v| v }.reverse.each do |key,val|
|
81
|
-
name, a, b, c = *key
|
82
|
-
ta += a
|
83
|
-
tb += b
|
84
|
-
tc += c
|
85
|
-
tval += val
|
86
|
-
printf "%3d) %-50s = %2d + %2d + %2d = %6.2f\n", count, name, a, b, c, val
|
87
|
-
count += 1
|
88
|
-
end rescue nil
|
89
|
-
printf "%3d) %-50s = %2d + %2d + %2d = %6.2f\n", count, "Total", ta, tb, tc, tval
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
2
|
-
|
3
|
-
require 'parse_tree'
|
4
|
-
|
5
|
-
all_nodes = ParseTree::NODE_NAMES
|
6
|
-
|
7
|
-
ARGV.each do |processor|
|
8
|
-
require processor
|
9
|
-
end
|
10
|
-
|
11
|
-
ObjectSpace.each_object(Class) do |klass|
|
12
|
-
if klass < SexpProcessor then
|
13
|
-
|
14
|
-
processor = klass.new
|
15
|
-
processors = klass.public_instance_methods(true).grep(/process_/)
|
16
|
-
|
17
|
-
if processor.strict then
|
18
|
-
puts "#{klass.name}:"
|
19
|
-
puts
|
20
|
-
|
21
|
-
# TODO: check unsupported against supported
|
22
|
-
processors = processors.map { |m| m[8..-1].intern } + processor.unsupported
|
23
|
-
unsupported = all_nodes - processors
|
24
|
-
p unsupported.sort_by { |sym| sym.to_s }
|
25
|
-
puts
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby -ws
|
2
|
-
|
3
|
-
old_classes = []; new_classes = []
|
4
|
-
|
5
|
-
ObjectSpace.each_object(Module) { |klass| old_classes << klass } if defined? $a
|
6
|
-
|
7
|
-
require 'pp'
|
8
|
-
|
9
|
-
begin require 'rubygems' rescue LoadError end
|
10
|
-
require 'parse_tree'
|
11
|
-
require 'sexp_processor'
|
12
|
-
|
13
|
-
ObjectSpace.each_object(Module) { |klass| old_classes << klass } unless defined? $a
|
14
|
-
|
15
|
-
class DependencyAnalyzer < SexpProcessor
|
16
|
-
|
17
|
-
attr_reader :dependencies
|
18
|
-
attr_accessor :current_class
|
19
|
-
|
20
|
-
def initialize
|
21
|
-
super
|
22
|
-
self.auto_shift_type = true
|
23
|
-
@dependencies = Hash.new { |h,k| h[k] = [] }
|
24
|
-
@current_method = nil
|
25
|
-
@current_class = nil
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.process(*klasses)
|
29
|
-
analyzer = self.new
|
30
|
-
klasses.each do |start_klass|
|
31
|
-
analyzer.current_class = start_klass
|
32
|
-
analyzer.process(ParseTree.new.parse_tree(start_klass))
|
33
|
-
end
|
34
|
-
|
35
|
-
deps = analyzer.dependencies
|
36
|
-
deps.keys.sort_by {|k| k.to_s}.each do |dep_to|
|
37
|
-
dep_from = deps[dep_to]
|
38
|
-
puts "#{dep_to}: #{dep_from.uniq.sort.join(", ")}"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def process_defn(exp)
|
43
|
-
name = exp.shift
|
44
|
-
@current_method = name
|
45
|
-
return s(:defn, name, process(exp.shift), process(exp.shift))
|
46
|
-
end
|
47
|
-
|
48
|
-
def process_const(exp)
|
49
|
-
name = exp.shift
|
50
|
-
const = (defined?($c) ? @current_class.name : "#{@current_class}.#{@current_method}")
|
51
|
-
is_class = ! (Object.const_get(name) rescue nil).nil?
|
52
|
-
@dependencies[name] << const if is_class
|
53
|
-
return s(:const, name)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
if __FILE__ == $0 then
|
58
|
-
ARGV.each { |name| require name }
|
59
|
-
ObjectSpace.each_object(Module) { |klass| new_classes << klass }
|
60
|
-
new_classes.delete DependencyAnalyzer unless defined? $a
|
61
|
-
DependencyAnalyzer.process(*(new_classes - old_classes))
|
62
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby -ws
|
2
|
-
|
3
|
-
require 'pp'
|
4
|
-
begin require 'rubygems' rescue LoadError end
|
5
|
-
require 'parse_tree'
|
6
|
-
|
7
|
-
def discover_new_classes_from
|
8
|
-
old_classes = []
|
9
|
-
ObjectSpace.each_object(Module) do |klass|
|
10
|
-
old_classes << klass
|
11
|
-
end
|
12
|
-
|
13
|
-
yield
|
14
|
-
|
15
|
-
new_classes = []
|
16
|
-
ObjectSpace.each_object(Module) do |klass|
|
17
|
-
new_classes << klass
|
18
|
-
end
|
19
|
-
|
20
|
-
new_classes -= old_classes
|
21
|
-
new_classes = [ eval($c) ] if defined? $c
|
22
|
-
new_classes
|
23
|
-
end
|
24
|
-
|
25
|
-
$f = false unless defined? $f
|
26
|
-
|
27
|
-
new_classes = discover_new_classes_from do
|
28
|
-
ARGV.unshift "-" if ARGV.empty?
|
29
|
-
ARGV.each do |name|
|
30
|
-
if name == "-" then
|
31
|
-
code = $stdin.read
|
32
|
-
code = "class Example; def example; #{code}; end; end" if $f
|
33
|
-
eval code unless code.nil?
|
34
|
-
else
|
35
|
-
require name
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
result = ParseTree.new.parse_tree(*new_classes)
|
41
|
-
|
42
|
-
result = result[0][3][2][1][2..-1] if $f
|
43
|
-
|
44
|
-
unless defined? $q then
|
45
|
-
pp result
|
46
|
-
else
|
47
|
-
p result
|
48
|
-
end
|
49
|
-
|
@@ -1,20 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby -w
|
2
|
-
require 'rubygems'
|
3
|
-
require 'sexp_processor'
|
4
|
-
|
5
|
-
class QuickPrinter < SexpProcessor
|
6
|
-
def initialize
|
7
|
-
super
|
8
|
-
self.strict = false
|
9
|
-
self.auto_shift_type = true
|
10
|
-
end
|
11
|
-
def process_defn(exp)
|
12
|
-
name = exp.shift
|
13
|
-
args = process exp.shift
|
14
|
-
body = process exp.shift
|
15
|
-
puts " def #{name}"
|
16
|
-
return s(:defn, name, args, body)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
QuickPrinter.new.process(*ParseTree.new.parse_tree(QuickPrinter))
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'sexp_processor'
|
2
|
-
|
3
|
-
##
|
4
|
-
# Implements the Composite pattern on SexpProcessor. Need we say more?
|
5
|
-
#
|
6
|
-
# Yeah... probably. Implements a SexpProcessor of SexpProcessors so
|
7
|
-
# you can easily chain multiple to each other. At some stage we plan
|
8
|
-
# on having all of them run +process+ and but only ever output
|
9
|
-
# something when +generate+ is called, allowing for deferred final
|
10
|
-
# processing.
|
11
|
-
|
12
|
-
class CompositeSexpProcessor < SexpProcessor
|
13
|
-
|
14
|
-
##
|
15
|
-
# The list o' processors to run.
|
16
|
-
|
17
|
-
attr_reader :processors
|
18
|
-
|
19
|
-
def initialize # :nodoc:
|
20
|
-
super
|
21
|
-
@processors = []
|
22
|
-
end
|
23
|
-
|
24
|
-
##
|
25
|
-
# Add a +processor+ to the list of processors to run.
|
26
|
-
|
27
|
-
def <<(processor)
|
28
|
-
raise ArgumentError, "Can only add sexp processors" unless
|
29
|
-
SexpProcessor === processor
|
30
|
-
@processors << processor
|
31
|
-
end
|
32
|
-
|
33
|
-
##
|
34
|
-
# Run +exp+ through all of the processors, returning the final
|
35
|
-
# result.
|
36
|
-
|
37
|
-
def process(exp)
|
38
|
-
@processors.each do |processor|
|
39
|
-
exp = processor.process(exp)
|
40
|
-
end
|
41
|
-
exp
|
42
|
-
end
|
43
|
-
|
44
|
-
def on_error_in(node_type, &block)
|
45
|
-
@processors.each do |processor|
|
46
|
-
processor.on_error_in(node_type, &block)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|