lib/review/preprocessor.rb in review-3.0.0 vs lib/review/preprocessor.rb in review-3.1.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (c) 2010-2017 Minero Aoki, Kenshi Muto
+# Copyright (c) 2010-2019 Minero Aoki, Kenshi Muto
# 2002-2009 Minero Aoki
#
# This program is free software.
# You can distribute or modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
@@ -67,10 +67,11 @@
def initialize(repo, param)
@repository = repo
@config = param
@logger = ReVIEW.logger
+ @leave_content = nil
end
def process(inf, outf)
init_errorutils inf
@f = outf
@@ -104,20 +105,22 @@
skip_list f
when /\A\#@mapfile/
direc = parse_directive(line, 1, 'eval')
path = expand(direc.arg)
+ @leave_content = File.extname(path) == '.re'
if direc['eval']
ent = evaluate(path, ent)
else
ent = @repository.fetch_file(path)
end
replace_block(f, line, ent, false) # FIXME: turn off lineno: tmp
when /\A\#@map(?:range)?/
direc = parse_directive(line, 2, 'unindent')
path = expand(direc.args[0])
+ @leave_content = File.extname(path) == '.re'
ent = @repository.fetch_range(path, direc.args[1]) or
error "unknown range: #{path}: #{direc.args[1]}"
ent = (direc['unindent'] ? unindent(ent, direc['unindent']) : ent)
replace_block(f, line, ent, false) # FIXME: turn off lineno: tmp
@@ -125,10 +128,13 @@
error 'unbaranced #@end'
when /\A\#@/
op = line.slice(/@(\w+)/, 1)
warn "unknown directive: #{line.strip}" unless known_directive?(op)
+ if op == 'warn'
+ warn line.strip.sub(/\#@warn\((.+)\)/, '\1')
+ end
@f.print line
when /\A\s*\z/ # empty line
@f.puts
else
@@ -164,13 +170,15 @@
case line
when /\A\#@end/
@f.print line
return nil
when %r{\A//\}}
- warn '//} seen in list'
- @f.print line
- return nil
+ unless @leave_content
+ warn '//} seen in list'
+ @f.print line
+ return nil
+ end
when /\A\#@\w/
warn "#{line.slice(/\A\#@\w+/)} seen in list"
@f.print line
when /\A\#@/
@f.print line
@@ -355,10 +363,11 @@
end
private
def file_descripter(fname)
+ @leave_content = File.extname(fname) == '.re'
return @repository[fname] if @repository[fname]
@repository[fname] = git?(fname) ? parse_git_blob(fname) : parse_file(fname)
end
@@ -453,9 +462,13 @@
repo
end
def canonical(line)
+ if @leave_content
+ return line
+ end
+
tabwidth = @config['tabwidth'] || 8
if tabwidth > 0
detab(line, tabwidth).rstrip + "\n"
else
line