C0 code coverage information
Generated on Wed May 31 01:38:08 AUS Eastern Standard Time 2006 with rcov 0.4.1
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name |
Total lines |
Lines of code |
Total coverage |
Code coverage |
misp.rb
|
112
|
100
|
|
|
1 # http://www.jadetower.org/muses/archives/000431.html
2
3 require 'misp.tab' # racc-generated parser
4 require 'pp'
5
6 module Misp
7
8 module SExpr
9 def self.new(str)
10 Misp.parse(str)
11 end
12 def atom?
13 kind_of? Symbol
14 end
15 def pair?
16 kind_of? Pair
17 end
18 def quote_expr?
19 pair? && hd == :quote && tl.pair? && tl.tl == :nil
20 end
21 def function_expr?
22 pair? && hd == :fn && tl.pair? && tl.tl.pair?
23 end
24 def evaluate
25 case self
26 when :nil, :atom, :eq, :hd, :if, :fn, :pair, :quote, :tl
27 self
28 when Pair
29 case hd
30 when Pair
31 Pair.new(hd.evaluate, tl).evaluate
32 when :atom
33 if tl.hd.evaluate.atom? then :true else :nil end
34 when :eq
35 if tl.hd.evaluate.equal? tl.tl.hd.evaluate then :true else :nil end
36 when :hd
37 tl.hd.evaluate.hd
38 when :if
39 if tl.hd.evaluate != :nil
40 tl.tl.hd.evaluate
41 else
42 tl.tl.tl.hd.evaluate
43 end
44 when :fn
45 :nil
46 when :pair
47 Pair.new(tl.hd.evaluate, tl.tl.hd.evaluate)
48 when :quote
49 tl.hd
50 when :tl
51 tl.hd.evaluate.tl
52 else
53 raise RuntimeError, "can't evaluate undefined atom '#{ hd.inspect }'"
54 end
55 else
56 raise RuntimeError, "can't evaluate undefined atom '#{ self.inspect }'"
57 end
58 end
59 def to_sexp
60 self
61 end
62 end
63
64 class ::Symbol
65 include SExpr
66 end
67
68 class Pair
69 include SExpr
70 attr_accessor :hd, :tl
71 def initialize(hd, tl = :nil)
72 @hd, @tl = hd, tl
73 end
74 def inspect
75 "(#{ hd.inspect } . #{ tl.inspect })"
76 end
77 def ==(other)
78 if other.respond_to?(:hd) && other.respond_to?(:tl)
79 hd == other.hd && tl == other.tl
80 end
81 end
82 def to_s(use_special_syntax = true)
83 if tl == :nil
84 # Nil Hiding
85 "(#{ hd })"
86 elsif use_special_syntax && quote_expr?
87 # Quote
88 "'#{ tl.hd }"
89 elsif use_special_syntax && function_expr?
90 # Function notation
91 params = if tl.hd.atom? then ".#{tl.hd}" else tl.hd.to_s[1...-1] end
92 "{|#{ params }| #{ tl.tl.hd }}"
93 elsif tl.pair?
94 # Tail Folding
95 "(#{ hd } #{ tl.to_s(false)[1...-1] })"
96 else
97 "(#{ hd } . #{ tl })"
98 end
99 end
100 end
101
102 class ::Array
103 def to_sexp() Pair.new(self[0].to_sexp, self[1].to_sexp) end
104 end
105 class ::NilClass
106 def to_sexp() :nil end
107 end
108
109 def self.parse(str)
110 Parser.new(str).do_parse
111 end
112 end
Generated using the rcov code coverage analysis tool for Ruby version 0.4.1.