1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/ripper/tools/generate-ripper_rb.rb
aamine 0c9d76889a * ext/ripper/Makefile.dev: removed.
* ext/ripper/ripper.rb.in: moved to lib/ripper/core.rb.in.
* ext/ripper/lib/ripper/core.rb: new file.
* ext/ripper/lib/ripper/core.rb.in: new file.
* ext/ripper/tools/generate-ripper_rb.rb: change comment.
* test/ripper/*.rb: on_scan removed.
* test/ripper/*.rb: event name changed: on__ -> on_.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-09-23 10:49:11 +00:00

60 lines
1.3 KiB
Ruby
Executable file

# $Id$
def main
template, ids1, ids2 = *ARGV
print <<header
# This file is automatically generated from #{File.basename(template)} and parse.y.
# DO NOT MODIFY!!!!!!
header
File.foreach(template) do |line|
case line
when /\A\#include ids1/
print_items read_ids(ids1)
when /\A\#include ids2/
print_items read_ids(ids2)
when /\A\#include handlers1/
File.foreach(ids1) do |line|
id, arity = line.split
arity = arity.to_i
puts
puts " def on_#{id}#{paramdecl(arity)}"
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
puts " def on_#{id}(token)"
puts " token"
puts " end"
end
when /\A\#include (.*)/
raise "unknown operation: #include #{$1}"
else
print line
end
end
end
def print_items(ids)
comma = ''
ids.each do |id, arity|
print comma; comma = ",\n"
print " #{id.intern.inspect} => #{arity}"
end
puts
end
def read_ids(path)
File.readlines(path).map {|line| line.split }
end
def paramdecl(n)
return '' if n == 0
'(' + %w(a b c d e f g h i j k l m)[0, n].join(', ') + ')'
end
main