2012-08-31 01:31:20 -04:00
|
|
|
#! /usr/bin/ruby -p
|
2012-11-29 03:12:29 -05:00
|
|
|
# -*- coding: us-ascii -*-
|
2016-07-02 17:01:04 -04:00
|
|
|
|
|
|
|
# Used to build the Ruby parsing code in common.mk and Ripper.
|
|
|
|
|
2012-08-31 01:31:20 -04:00
|
|
|
BEGIN {
|
|
|
|
require 'optparse'
|
2012-11-29 03:12:29 -05:00
|
|
|
$:.unshift(File.dirname(__FILE__))
|
|
|
|
require 'vpath'
|
|
|
|
vpath = VPath.new
|
2012-08-31 01:31:20 -04:00
|
|
|
header = nil
|
|
|
|
|
|
|
|
opt = OptionParser.new do |o|
|
2012-11-29 03:12:29 -05:00
|
|
|
vpath.def_options(o)
|
2012-08-31 01:31:20 -04:00
|
|
|
header = o.order!(ARGV).shift
|
|
|
|
end or abort opt.opt_s
|
|
|
|
|
|
|
|
TOKENS = {}
|
2012-11-29 03:12:29 -05:00
|
|
|
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
|
2012-08-31 01:31:20 -04:00
|
|
|
|
|
|
|
TOKENS_RE = /\bRUBY_TOKEN\((#{TOKENS.keys.join('|')})\)\s*(?=\s)/
|
|
|
|
}
|
|
|
|
|
|
|
|
$_.gsub!(TOKENS_RE) {TOKENS[$1]} if /^%token/ =~ $_
|