diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-25 07:20:29 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-25 07:20:29 +0000 |
commit | bcbc1f722c0ab7e26334c6fdafab502f4f021860 (patch) | |
tree | 8d3363d01cb6457a6b909e58e28a75330b2f02c4 | |
parent | 67e79d1d372879dd9bd185b508aad150de76ff6f (diff) |
generic_erb.rb: --vpath option
* tool/generic_erb.rb (vpath.open): move --vpath option from
template/id.h.tmpl.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | common.mk | 4 | ||||
-rw-r--r-- | template/id.h.tmpl | 19 | ||||
-rwxr-xr-x | tool/generic_erb.rb | 16 |
3 files changed, 21 insertions, 18 deletions
@@ -855,8 +855,8 @@ insns: $(INSNS) $(ID_H_INCLUDES) $(ID_H_TARGET): {$(VPATH)}parse.h $(srcdir)/tool/generic_erb.rb $(srcdir)/template/id.h.tmpl $(ECHO) generating id.h $(Q) $(BASERUBY) $(srcdir)/tool/generic_erb.rb --if-change --output=id.h \ - --timestamp=$@ \ - $(srcdir)/template/id.h.tmpl --vpath=$(VPATH) parse.h + --vpath=$(VPATH) --timestamp \ + $(srcdir)/template/id.h.tmpl parse.h node_name.inc: {$(VPATH)}node.h $(ECHO) generating $@ diff --git a/template/id.h.tmpl b/template/id.h.tmpl index 15eb25baed..3279064bd5 100644 --- a/template/id.h.tmpl +++ b/template/id.h.tmpl @@ -12,24 +12,13 @@ **********************************************************************/ <% require 'optparse' -vpath = ["."] -input = nil -opt = OptionParser.new do |o| - o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)} - input, = o.order!(ARGV) -end or abort opt.opt_s +input = ARGV.shift or abort opt.opt_s tokens = nil -vpath.find do |dir| - begin - if line = File.read(File.join(dir, input))[/^\s*enum\s+yytokentype\s*\{([^{}]*)\s*\};/m, 1] - tokens = line.scan(/\b(t(?:LAST_TOKEN|U(?:PLUS|MINUS)|POW|CMP|EQQ?|[NGL]EQ|(?:AND|OR)OP|N?MATCH|DOT\d|AREF|ASET|[LR]SHFT|LAMBDA)|id\w+)\s*=\s*(\d+),?/m) - end - rescue Errno::ENOENT - nil - else - true +vpath.open(input) do |f| + if line = f.read[/^\s*enum\s+yytokentype\s*\{([^{}]*)\s*\};/m, 1] + tokens = line.scan(/\b(t(?:LAST_TOKEN|U(?:PLUS|MINUS)|POW|CMP|EQQ?|[NGL]EQ|(?:AND|OR)OP|N?MATCH|DOT\d|AREF|ASET|[LR]SHFT|LAMBDA)|id\w+)\s*=\s*(\d+),?/m) end end diff --git a/tool/generic_erb.rb b/tool/generic_erb.rb index 8e84a46bfd..b2b988fb3a 100755 --- a/tool/generic_erb.rb +++ b/tool/generic_erb.rb @@ -2,13 +2,27 @@ require 'erb' require 'optparse' require 'fileutils' +vpath = ["."] +def vpath.open(file, *rest) + find do |dir| + begin + path = File.join(dir, file) + return File.open(path, *rest) {|f| yield(f)} + rescue Errno::ENOENT + nil + end + end or raise(Errno::ENOENT, file) +end + timestamp = nil output = nil ifchange = nil + opt = OptionParser.new do |o| o.on('-t', '--timestamp[=PATH]') {|v| timestamp = v || true} o.on('-o', '--output=PATH') {|v| output = v} o.on('-c', '--[no-]if-change') {|v| ifchange = v} + o.on('-v', '--vpath=DIR') {|dirs| vpath.concat dirs.split(File::PATH_SEPARATOR)} o.order!(ARGV) end template = ARGV.shift or abort opt.to_s @@ -16,7 +30,7 @@ erb = ERB.new(File.read(template), nil, '%') erb.filename = template result = erb.result if output - if ifchange and (IO.read(output) rescue nil) == result + if ifchange and (vpath.open(output) {|f| f.read} rescue nil) == result puts "#{output} unchanged" else open(output, "wb") {|f| f.print result} |