2012-08-31 09:31:20 +04:00
|
|
|
#! /usr/bin/ruby -p
|
2012-11-29 12:12:29 +04:00
|
|
|
# -*- coding: us-ascii -*-
|
2012-08-31 09:31:20 +04:00
|
|
|
BEGIN {
|
|
|
|
require 'optparse'
|
2012-11-29 12:12:29 +04:00
|
|
|
$:.unshift(File.dirname(__FILE__))
|
|
|
|
require 'vpath'
|
|
|
|
vpath = VPath.new
|
2012-08-31 09:31:20 +04:00
|
|
|
header = nil
|
|
|
|
|
|
|
|
opt = OptionParser.new do |o|
|
2012-11-29 12:12:29 +04:00
|
|
|
vpath.def_options(o)
|
2012-08-31 09:31:20 +04:00
|
|
|
header = o.order!(ARGV).shift
|
|
|
|
end or abort opt.opt_s
|
|
|
|
|
|
|
|
TOKENS = {}
|
2012-11-29 12:12:29 +04: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 09:31:20 +04:00
|
|
|
|
|
|
|
TOKENS_RE = /\bRUBY_TOKEN\((#{TOKENS.keys.join('|')})\)\s*(?=\s)/
|
|
|
|
}
|
|
|
|
|
|
|
|
$_.gsub!(TOKENS_RE) {TOKENS[$1]} if /^%token/ =~ $_
|