Skip to content

Commit

Permalink
Merge pull request #1248 from kmuto/fix-preproc
Browse files Browse the repository at this point in the history
#@mapfile等でre拡張子時にはタブなどを含めて「ありのまま」取り込む
  • Loading branch information
kmuto authored Jan 7, 2019
2 parents 354ad72 + a882585 commit 15e8d72
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/review/preprocessor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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.
Expand Down Expand Up @@ -69,6 +69,7 @@ def initialize(repo, param)
@repository = repo
@config = param
@logger = ReVIEW.logger
@leave_content = nil
end

def process(inf, outf)
Expand Down Expand Up @@ -106,6 +107,7 @@ def preproc(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
Expand All @@ -116,6 +118,7 @@ def preproc(f)
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)
Expand Down Expand Up @@ -166,9 +169,11 @@ def skip_list(f)
@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
Expand Down Expand Up @@ -357,6 +362,7 @@ def fetch(file, type, name)
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)
Expand Down Expand Up @@ -455,6 +461,10 @@ def _parse_file(f)
end

def canonical(line)
if @leave_content
return line
end

tabwidth = @config['tabwidth'] || 8
if tabwidth > 0
detab(line, tabwidth).rstrip + "\n"
Expand Down

0 comments on commit 15e8d72

Please sign in to comment.