summaryrefslogtreecommitdiff
path: root/ext/ripper/tools/list-parse-event-ids.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ripper/tools/list-parse-event-ids.rb')
-rwxr-xr-xext/ripper/tools/list-parse-event-ids.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/ext/ripper/tools/list-parse-event-ids.rb b/ext/ripper/tools/list-parse-event-ids.rb
new file mode 100755
index 0000000000..2936f9b092
--- /dev/null
+++ b/ext/ripper/tools/list-parse-event-ids.rb
@@ -0,0 +1,38 @@
+#
+# list-parse-event-ids.rb
+#
+
+require 'getopts'
+
+def usage( status )
+ (status == 0 ? $stdout : $stderr).print(<<EOS)
+Usage: #{File.basename($0)} [-a] filename
+EOS
+ exit status
+end
+
+def main
+ getopts('a') or usage(1)
+ extract_ids(ARGF).each do |id, arity|
+ if $OPT_a
+ then 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