2004-09-14 07:27:36 -04:00
|
|
|
# $Id$
|
2004-09-12 13:34:30 -04:00
|
|
|
|
|
|
|
def main
|
|
|
|
template, ids1, ids2 = *ARGV
|
2004-09-19 15:49:56 -04:00
|
|
|
print <<header
|
|
|
|
#
|
2004-09-20 01:40:23 -04:00
|
|
|
# This file is automatically generated from #{File.basename(template)} and parse.y.
|
2004-09-19 15:49:56 -04:00
|
|
|
# DO NOT MODIFY!!!!!!
|
|
|
|
#
|
|
|
|
header
|
2004-09-12 13:34:30 -04:00
|
|
|
File.foreach(template) do |line|
|
|
|
|
case line
|
2004-09-14 07:27:36 -04:00
|
|
|
when /\A\#include ids1/
|
|
|
|
print_items read_ids(ids1)
|
|
|
|
when /\A\#include ids2/
|
|
|
|
print_items read_ids(ids2)
|
2004-09-12 13:34:30 -04:00
|
|
|
when /\A\#include handlers1/
|
|
|
|
File.foreach(ids1) do |line|
|
|
|
|
id, arity = line.split
|
|
|
|
arity = arity.to_i
|
|
|
|
puts
|
2004-09-22 01:22:50 -04:00
|
|
|
puts " def on_#{id}#{paramdecl(arity)}"
|
2004-09-12 13:34:30 -04:00
|
|
|
puts " #{arity == 0 ? 'nil' : 'a'}"
|
|
|
|
puts " end"
|
|
|
|
end
|
|
|
|
when /\A\#include handlers2/
|
|
|
|
File.foreach(ids2) do |line|
|
|
|
|
id, arity = line.split
|
|
|
|
arity = arity.to_i
|
|
|
|
puts
|
2004-09-22 01:22:50 -04:00
|
|
|
puts " def on_#{id}(token)"
|
2004-09-12 13:34:30 -04:00
|
|
|
puts " token"
|
|
|
|
puts " end"
|
|
|
|
end
|
|
|
|
when /\A\#include (.*)/
|
|
|
|
raise "unknown operation: #include #{$1}"
|
|
|
|
else
|
|
|
|
print line
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-09-14 07:27:36 -04:00
|
|
|
def print_items(ids)
|
2004-09-19 15:49:56 -04:00
|
|
|
comma = ''
|
|
|
|
ids.each do |id, arity|
|
2004-09-14 07:27:36 -04:00
|
|
|
print comma; comma = ",\n"
|
2004-09-19 15:49:56 -04:00
|
|
|
print " #{id.intern.inspect} => #{arity}"
|
2004-09-14 07:27:36 -04:00
|
|
|
end
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_ids(path)
|
2004-09-19 15:49:56 -04:00
|
|
|
File.readlines(path).map {|line| line.split }
|
2004-09-14 07:27:36 -04:00
|
|
|
end
|
|
|
|
|
2004-09-19 15:49:56 -04:00
|
|
|
def paramdecl(n)
|
|
|
|
return '' if n == 0
|
|
|
|
'(' + %w(a b c d e f g h i j k l m)[0, n].join(', ') + ')'
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
main
|