Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#@mapfile等でre拡張子時にはタブなどを含めて「ありのまま」取り込む #1248

Merged
merged 2 commits into from
Jan 7, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' ? true : nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@leave_content = File.extname(path) == '.re' ? true : nil
@leave_content = File.extname(path) == '.re'

でも良さそうです(他の行も)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、おおせのとおりに!

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' ? true : nil
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' ? true : nil
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