summaryrefslogtreecommitdiff
path: root/tool/id2token.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-31 05:31:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-31 05:31:20 +0000
commit470c941ce5bd1800fc24f271c6234cee096fd592 (patch)
tree124a826f07c07015f08bc835b057200570f91671 /tool/id2token.rb
parent2e42f37a020ce9c94f7d41e69b3e3ffec43a54ce (diff)
id.h: independent from parse.h
* template/id.h.tmpl, tool/id2token.rb: make id.h independent from parse.h, and make parse.c dependent on it instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/id2token.rb')
-rwxr-xr-xtool/id2token.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/tool/id2token.rb b/tool/id2token.rb
new file mode 100755
index 0000000..4c7189c
--- /dev/null
+++ b/tool/id2token.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/ruby -p
+BEGIN {
+ require 'optparse'
+ vpath = ["."]
+ header = nil
+
+ opt = OptionParser.new do |o|
+ o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)}
+ header = o.order!(ARGV).shift
+ end or abort opt.opt_s
+
+ TOKENS = {}
+ vpath.find do |dir|
+ begin
+ h = File.read(File.join(dir, header))
+ rescue Errno::ENOENT
+ nil
+ else
+ h.scan(/^#define\s+RUBY_TOKEN_(\w+)\s+(\d+)/) do |token, id|
+ TOKENS[token] = id
+ end
+ true
+ end
+ end or abort "#{header} not found in #{vpath.inspect}"
+
+ TOKENS_RE = /\bRUBY_TOKEN\((#{TOKENS.keys.join('|')})\)\s*(?=\s)/
+}
+
+$_.gsub!(TOKENS_RE) {TOKENS[$1]} if /^%token/ =~ $_