summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--ext/ripper/depend8
-rwxr-xr-xext/ripper/tools/preproc.rb84
3 files changed, 72 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index ac36e485312..a140d11f721 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Sep 23 07:07:47 2005 Minero Aoki <aamine@loveruby.net>
+
+ * test/ripper/depend: use --output option instead of redirect;
+ nmake does not remove a target when the target file is created by
+ redirect. [ruby-dev:26466]
+
+ * test/ripper/tools/preproc.rb: new option --output.
+
Fri Sep 23 06:57:52 2005 Minero Aoki <aamine@loveruby.net>
* test/ripper/tools/generate.rb: check parser event arity.
diff --git a/ext/ripper/depend b/ext/ripper/depend
index 67a9d0998bf..b18df1efd79 100644
--- a/ext/ripper/depend
+++ b/ext/ripper/depend
@@ -3,13 +3,13 @@ ripper.o: ripper.c eventids1.c $(srcdir)/eventids2.c $(hdrdir)/lex.c
.y.c:
bison -t -v -o$@ $<
-ripper.y: $(hdrdir)/parse.y $(srcdir)/tools/preproc.rb
- $(RUBY) $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y > $@
+ripper.y: $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y
+ $(RUBY) $(srcdir)/tools/preproc.rb $(hdrdir)/parse.y --output=$@
-$(srcdir)/lib/ripper/core.rb: $(srcdir)/lib/ripper/core.rb.in $(srcdir)/tools/generate.rb
+$(srcdir)/lib/ripper/core.rb: $(srcdir)/tools/generate.rb $(srcdir)/lib/ripper/core.rb.in $(hdrdir)/parse.y $(hdrdir)/eventids2.c
$(RUBY) $(srcdir)/tools/generate.rb --mode=ripper/core --template=$@.in --output=$@ --ids1src=$(hdrdir)/parse.y --ids2src=$(srcdir)/eventids2.c
-eventids1.c: $(hdrdir)/parse.y $(srcdir)/tools/generate.rb
+eventids1.c: $(srcdir)/tools/generate.rb $(hdrdir)/parse.y
$(RUBY) $(srcdir)/tools/generate.rb --mode=eventids1 --ids1src=$(hdrdir)/parse.y --output=$@
# Entries for Ripper maintainer
diff --git a/ext/ripper/tools/preproc.rb b/ext/ripper/tools/preproc.rb
index a2dba36e02d..4b26c5bcb07 100755
--- a/ext/ripper/tools/preproc.rb
+++ b/ext/ripper/tools/preproc.rb
@@ -1,56 +1,92 @@
+# $Id$
+
+require 'stringio'
+require 'optparse'
+
def main
- prelude
- grammar
- usercode
+ output = nil
+ parser = OptionParser.new
+ parser.banner = "Usage: #{File.basename($0)} [--output=PATH] <parse.y>"
+ parser.on('--output=PATH', 'An output file.') {|path|
+ output = path
+ }
+ parser.on('--help', 'Prints this message and quit.') {
+ puts parser.help
+ exit 0
+ }
+ begin
+ parser.parse!
+ rescue OptionParser::ParseError => err
+ $stderr.puts err.message
+ $stderr.puts parser.help
+ exit 1
+ end
+ unless ARGV.size == 1
+ $stderr.puts "wrong number of arguments (#{ARGV.size} for 1)"
+ exit 1
+ end
+ out = StringIO.new
+ File.open(ARGV[0]) {|f|
+ prelude f, out
+ grammar f, out
+ usercode f, out
+ }
+ if output
+ File.open(output, 'w') {|f|
+ f.write out.string
+ }
+ else
+ print out.string
+ end
end
-def prelude
- while line = ARGF.gets
+def prelude(f, out)
+ while line = f.gets
case line
when %r</\*%%%\*/>
- puts '/*'
+ out.puts '/*'
when %r</\*%>
- puts '*/'
+ out.puts '*/'
when %r<%\*/>
- puts
+ out.puts
when /\A%%/
- puts '%%'
+ out.puts '%%'
return
when /\A%token/
- puts line.sub(/<\w+>/, '<val>')
+ out.puts line.sub(/<\w+>/, '<val>')
when /\A%type/
- puts line.sub(/<\w+>/, '<val>')
+ out.puts line.sub(/<\w+>/, '<val>')
else
- print line
+ out.print line
end
end
end
-def grammar
- while line = ARGF.gets
+def grammar(f, out)
+ while line = f.gets
case line
when %r</\*%%%\*/>
- puts '#if 0'
+ out.puts '#if 0'
when %r</\*%c%\*/>
- puts '/*'
+ out.puts '/*'
when %r</\*%c>
- puts '*/'
+ out.puts '*/'
when %r</\*%>
- puts '#endif'
+ out.puts '#endif'
when %r<%\*/>
- puts
+ out.puts
when /\A%%/
- puts '%%'
+ out.puts '%%'
return
else
- print line
+ out.print line
end
end
end
-def usercode
- while line = ARGF.gets
- print line
+def usercode(f, out)
+ while line = f.gets
+ out.print line
end
end