1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/tool/id2token.rb
nobu 470c941ce5 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
2012-08-31 05:31:20 +00:00

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/ =~ $_