summaryrefslogtreecommitdiff
path: root/ext/ripper/test/validate.rb
blob: 808d321043f24d01a068e936039336103d0ab791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'ripper.so'

class R < Ripper
  def initialize(*args)
    super
    @lineno = 0
  end

  def parse
    result = super
    puts "#{@lineno}:result: #{rawVALUE(result)}"
    validate_object result
    p result
    result
  end

  def on__nl(str)
    @lineno += 1
  end

  def on__ignored_nl(str)
    @lineno += 1
  end

  def on__comment(cmt)
    @lineno += 1
  end

  def on__embdoc_beg(str)
    @lineno += 1
  end

  def on__embdoc(str)
    @lineno += 1
  end

  def on__embdoc_end(str)
    @lineno += 1
  end

  def method_missing(mid, *args)
    puts mid
    args.each_with_index do |a,idx|
      puts "#{@lineno}:#{mid}\##{idx+1}: #{rawVALUE(a)}"
      validate_object a
      p a
    end
    args[0]
  end

  def warn(*args)
  end

  def warning(*args)
  end

  unless respond_to?(:validate_object)
    def validate_object(x)
      x
    end
    def rawVALUE(x)
      x.object_id
    end
  end
end

fname = (ARGV[0] || 'test/src_rb')
R.new(File.read(fname), fname, 1).parse