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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
636 B
Ruby
Raw Normal View History

#! /usr/bin/ruby -p
# -*- coding: us-ascii -*-
# Used to build the Ruby parsing code in common.mk and Ripper.
BEGIN {
require 'optparse'
require_relative 'lib/vpath'
vpath = VPath.new
header = nil
opt = OptionParser.new do |o|
vpath.def_options(o)
header = o.order!(ARGV).shift
end or abort opt.opt_s
TOKENS = {}
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)/
}
$_.gsub!(TOKENS_RE) {TOKENS[$1]} if /^%token/ =~ $_