summaryrefslogtreecommitdiff
path: root/tool/id2token.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 08:12:29 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 08:12:29 +0000
commitd22ac50ad493256c707b7b39eadf3ac46d989224 (patch)
treece0cb41e12b6389e4d36e1c182b8f5bbb2b63226 /tool/id2token.rb
parent2f80fddadc25d13c2c9862b03d16c0445265c027 (diff)
tool/vpath.rb
* tool/generic_erb.rb, tool/id2token.rb: add --path-separator option for mingw where make and built ruby live in different world. * tool/vpath.rb: extract from tool/instruction.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/id2token.rb')
-rwxr-xr-xtool/id2token.rb23
1 files changed, 9 insertions, 14 deletions
diff --git a/tool/id2token.rb b/tool/id2token.rb
index 4c7189c..191b872 100755
--- a/tool/id2token.rb
+++ b/tool/id2token.rb
@@ -1,27 +1,22 @@
#! /usr/bin/ruby -p
+# -*- coding: us-ascii -*-
BEGIN {
require 'optparse'
- vpath = ["."]
+ $:.unshift(File.dirname(__FILE__))
+ require 'vpath'
+ vpath = VPath.new
header = nil
opt = OptionParser.new do |o|
- o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)}
+ vpath.def_options(o)
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}"
+ h = vpath.read(header) rescue abort("#{header} not found in #{vpath.inspect}")
+ h.scan(/^#define\s+RUBY_TOKEN_(\w+)\s+(\d+)/) do |token, id|
+ TOKENS[token] = id
+ end
TOKENS_RE = /\bRUBY_TOKEN\((#{TOKENS.keys.join('|')})\)\s*(?=\s)/
}