summaryrefslogtreecommitdiff
path: root/ext/ripper/tools/list-parse-event-ids.rb
blob: 84c7e4c445cb05e8cbed0faa9fb20c2999211a72 (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
# $Id$

def main
  if ARGV[0] == '-a'
    with_arity = true
    ARGV.delete_at 0
  else
    with_arity = false
  end
  extract_ids(ARGF).each do |id, arity|
    if with_arity
      puts "#{id} #{arity}"
    else
      puts id
    end
  end
end

def extract_ids(f)
  results = []
  f.each do |line|
    next if /\A\#\s*define\s+s?dispatch/ === line
    next if /ripper_dispatch/ === line
    if a = line.scan(/dispatch(\d)\((\w+)/)
      a.each do |arity, event|
        results.push [event, arity.to_i]
      end
    end
  end
  results.uniq.sort
end

main