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
Nobuyoshi Nakada bcf82b7c26
Process token IDs from id.def without id.h
Fixes id.h error during updating ripper.c by `make after-update`.

While it used to update id.h in the build directory, but was trying to
update ripper.c in the source directory.  In principle, files in the
source directory can or should not depend on files in the build
directory.
2022-09-08 18:22:47 +09:00

23 lines
546 B
Ruby
Executable file

#! /usr/bin/ruby -p
# -*- coding: us-ascii -*-
# Used to build the Ruby parsing code in common.mk and Ripper.
BEGIN {
require 'optparse'
opt = OptionParser.new do |o|
o.order!(ARGV)
end or abort opt.opt_s
TOKENS = {}
defs = File.join(File.dirname(File.dirname(__FILE__)), "defs/id.def")
ids = eval(File.read(defs), nil, defs)
ids[:token_op].each do |_id, _op, token, id|
TOKENS[token] = id
end
TOKENS_RE = /\bRUBY_TOKEN\((#{TOKENS.keys.join('|')})\)\s*(?=\s)/
}
$_.gsub!(TOKENS_RE) {TOKENS[$1]} if /^%token/ =~ $_