mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
470c941ce5
* 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
29 lines
696 B
Ruby
Executable file
29 lines
696 B
Ruby
Executable file
#! /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/ =~ $_
|