mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/ripper: ripper extention added.
* ext/ripper/MANIFEST: new file. * ext/ripper/README: new file. * ext/ripper/depend: new file. * ext/ripper/extconf.rb: new file. * ext/ripper/eventids2.c: new file. * ext/ripper/ripper.rb.in: new file. * ext/ripper/lib/ripper.rb: new file. * ext/ripper/test/check-event-arity.rb: new file. * ext/ripper/test/check-event-coverage.sh: new file. * ext/ripper/test/check-scanner-event-coverage.rb: new file. * ext/ripper/test/list-called-events.rb: new file. * ext/ripper/test/src_rb: new file. * ext/ripper/test/validate.rb: new file. * ext/ripper/tools/generate-eventids1.rb: new file. * ext/ripper/tools/generate-param-macros.rb: new file. * ext/ripper/tools/generate-ripper_rb.rb: new file. * ext/ripper/tools/list-parse-event-ids.rb: new file. * ext/ripper/tools/list-scan-event-ids.rb: new file. * ext/ripper/tools/preproc.rb: new file. * ext/ripper/tools/strip.rb: new file. * test/ripper: ripper tests added. * test/ripper/dummyparser.rb: new file. * test/ripper/test_parser_events.rb: new file. * test/ripper/test_scanner_events.rb: new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5bea219a9d
commit
c971589817
25 changed files with 3911 additions and 0 deletions
18
ext/ripper/tools/generate-eventids1.rb
Executable file
18
ext/ripper/tools/generate-eventids1.rb
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# generate-eventids1.rb
|
||||
#
|
||||
|
||||
ids = ARGF.map {|s| s.strip }
|
||||
|
||||
ids.each do |id|
|
||||
puts "static ID ripper_id_#{id};"
|
||||
end
|
||||
|
||||
puts
|
||||
puts 'static void'
|
||||
puts 'ripper_init_eventids1()'
|
||||
puts '{'
|
||||
ids.each do |id|
|
||||
puts %Q[ ripper_id_#{id} = rb_intern("on__#{id}");]
|
||||
end
|
||||
puts '}'
|
||||
14
ext/ripper/tools/generate-param-macros.rb
Executable file
14
ext/ripper/tools/generate-param-macros.rb
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
off = true
|
||||
ARGF.each do |line|
|
||||
case line
|
||||
when /RIPPER_PARAMS_DECL_BEGIN/
|
||||
off = false
|
||||
when /RIPPER_PARAMS_DECL_END/
|
||||
exit
|
||||
when /ripper/
|
||||
next if off
|
||||
var = line.scan(/\w+/).last or next
|
||||
base = var.sub(/ripper_/, '')
|
||||
puts %"\#define #{base}\t\t(parser->ripper_#{base})"
|
||||
end
|
||||
end
|
||||
44
ext/ripper/tools/generate-ripper_rb.rb
Executable file
44
ext/ripper/tools/generate-ripper_rb.rb
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# generate-ripper_rb.rb
|
||||
# Creates ripper.rb, filling in default event handlers, given a basic
|
||||
# template, the list of parser events (ids1), and a list of lexer
|
||||
# events (ids2).
|
||||
#
|
||||
|
||||
def main
|
||||
template, ids1, ids2 = *ARGV
|
||||
File.foreach(template) do |line|
|
||||
case line
|
||||
when /\A\#include handlers1/
|
||||
File.foreach(ids1) do |line|
|
||||
id, arity = line.split
|
||||
arity = arity.to_i
|
||||
puts
|
||||
puts " def on__#{id}(#{argdecl(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
|
||||
|
||||
# Generate generic arg list depending on arity (n)
|
||||
# n:: [Integer] arity of method
|
||||
def argdecl( n )
|
||||
%w(a b c d e f g h i j k l m)[0, n].join(', ')
|
||||
end
|
||||
|
||||
main
|
||||
38
ext/ripper/tools/list-parse-event-ids.rb
Executable file
38
ext/ripper/tools/list-parse-event-ids.rb
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# list-parse-event-ids.rb
|
||||
#
|
||||
|
||||
require 'getopts'
|
||||
|
||||
def usage( status )
|
||||
(status == 0 ? $stdout : $stderr).print(<<EOS)
|
||||
Usage: #{File.basename($0)} [-a] filename
|
||||
EOS
|
||||
exit status
|
||||
end
|
||||
|
||||
def main
|
||||
getopts('a') or usage(1)
|
||||
extract_ids(ARGF).each do |id, arity|
|
||||
if $OPT_a
|
||||
then puts "#{id} #{arity}"
|
||||
else puts id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def extract_ids( f )
|
||||
results = []
|
||||
f.each do |line|
|
||||
next if /\A\#\s*define\s+s?dispatch/ === line
|
||||
next if /ripper_dispatch/ === line
|
||||
if a = line.scan(/dispatch(\d)\((\w+)/)
|
||||
a.each do |arity, event|
|
||||
results.push [event, arity.to_i]
|
||||
end
|
||||
end
|
||||
end
|
||||
results.uniq.sort
|
||||
end
|
||||
|
||||
main
|
||||
32
ext/ripper/tools/list-scan-event-ids.rb
Executable file
32
ext/ripper/tools/list-scan-event-ids.rb
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
#
|
||||
# list-scan-event-ids.rb
|
||||
#
|
||||
|
||||
require 'getopts'
|
||||
|
||||
def usage(status)
|
||||
(status == 0 ? $stdout : $stderr).puts(<<EOS)
|
||||
Usage: #{File.basename($0)} eventids2.c
|
||||
-a print IDs with arity.
|
||||
EOS
|
||||
exit status
|
||||
end
|
||||
|
||||
def main
|
||||
ok = getopts('a', 'help')
|
||||
usage 0 if $OPT_help
|
||||
usage 1 unless ok
|
||||
extract_ids(ARGF).sort.each do |id|
|
||||
if $OPT_a
|
||||
puts "#{id} 1"
|
||||
else
|
||||
puts id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def extract_ids(f)
|
||||
(f.read.scan(/ripper_id_(\w+)/).flatten - ['scan']).uniq
|
||||
end
|
||||
|
||||
main
|
||||
57
ext/ripper/tools/preproc.rb
Executable file
57
ext/ripper/tools/preproc.rb
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
def main
|
||||
prelude
|
||||
grammar
|
||||
usercode
|
||||
end
|
||||
|
||||
def prelude
|
||||
while line = ARGF.gets
|
||||
case line
|
||||
when %r</\*%%%\*/>
|
||||
puts '/*'
|
||||
when %r</\*%>
|
||||
puts '*/'
|
||||
when %r<%\*/>
|
||||
puts
|
||||
when /\A%%/
|
||||
puts '%%'
|
||||
return
|
||||
when /\A%token/
|
||||
puts line.sub(/<\w+>/, '<val>')
|
||||
when /\A%type/
|
||||
puts line.sub(/<\w+>/, '<val>')
|
||||
else
|
||||
print line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def grammar
|
||||
while line = ARGF.gets
|
||||
case line
|
||||
when %r</\*%%%\*/>
|
||||
puts '#if 0'
|
||||
when %r</\*%c%\*/>
|
||||
puts '/*'
|
||||
when %r</\*%c>
|
||||
puts '*/'
|
||||
when %r</\*%>
|
||||
puts '#endif'
|
||||
when %r<%\*/>
|
||||
puts
|
||||
when /\A%%/
|
||||
puts '%%'
|
||||
return
|
||||
else
|
||||
print line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def usercode
|
||||
while line = ARGF.gets
|
||||
print line
|
||||
end
|
||||
end
|
||||
|
||||
main
|
||||
12
ext/ripper/tools/strip.rb
Executable file
12
ext/ripper/tools/strip.rb
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
last_is_void = false
|
||||
ARGF.each do |line|
|
||||
if line.strip.empty?
|
||||
#puts() unless last_is_void
|
||||
last_is_void = true
|
||||
elsif /\A\#/ === line
|
||||
;
|
||||
else
|
||||
print line
|
||||
last_is_void = false
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue