lib/review/preprocessor.rb in review-1.6.0 vs lib/review/preprocessor.rb in review-1.7.0

- old
+ new

@@ -22,28 +22,14 @@ @errutils_file = f @errutils_err = false end def warn(msg) - if @config["outencoding"] =~ /^EUC$/ - msg = NKF.nkf("-W -e", msg) - elsif @config["outencoding"] =~ /^SJIS$/ - msg = NKF.nkf("-W -s", msg) - elsif @config["outencoding"] =~ /^JIS$/ - msg = NKF.nkf("-W -j", msg) - end $stderr.puts "#{location()}: warning: #{msg}" end def error(msg) - if @config["outencoding"] =~ /^EUC$/ - msg = NKF.nkf("-W -e", msg) - elsif @config["outencoding"] =~ /^SJIS$/ - msg = NKF.nkf("-W -s", msg) - elsif @config["outencoding"] =~ /^JIS$/ - msg = NKF.nkf("-W -j", msg) - end @errutils_err = true raise ApplicationError, "#{location()}: #{msg}" end def location @@ -146,30 +132,30 @@ when /\A\#@mapfile/ direc = parse_directive(line, 1, 'eval') path = expand(direc.arg) ent = @repository.fetch_file(path) ent = evaluate(path, ent) if direc['eval'] - replace_block f, line, ent, false # FIXME: turn off lineno: tmp + 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]) 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 + replace_block(f, line, ent, false) # FIXME: turn off lineno: tmp when /\A\#@end/ error 'unbaranced #@end' when /\A\#@/ op = line.slice(/@(\w+)/, 1) #error "unkown directive: #{line.strip}" unless known_directive?(op) warn "unkown directive: #{line.strip}" unless known_directive?(op) @f.print line - when /\A\s*\z/ # empty line + when /\A\s*\z/ # empty line @f.puts else @f.print line end end @@ -181,38 +167,15 @@ def known_directive?(op) KNOWN_DIRECTIVES.index(op) end - def convert_outencoding(*s) - ine = "" - if @config["inencoding"] =~ /^EUC$/i - ine = "-E," - elsif @config["inencoding"] =~ /^SJIS$/i - ine = "-S," - elsif @config["inencoding"] =~ /^JIS$/i - ine = "-J," - elsif @config["inencoding"] =~ /^UTF\-8$/i - ine = "-W," - end - - if @config["outencoding"] =~ /^EUC$/i - NKF.nkf("#{ine} -m0x -e", *s) - elsif @config["outencoding"] =~ /^SJIS$/i - NKF.nkf("#{ine} -m0x -s", *s) - elsif @config["outencoding"] =~ /^JIS$/i - NKF.nkf("#{ine} -m0x -j", *s) - else - NKF.nkf("#{ine} -m0x -w", *s) - end - end - def replace_block(f, directive_line, newlines, with_lineno) @f.print directive_line newlines.each do |line| print_number line.number if with_lineno - @f.print convert_outencoding(line.string) + @f.print line.string end skip_list f end def print_number(num) @@ -241,12 +204,12 @@ end class Directive def initialize(op, args, opts) @op = op - @args = args - @opts = opts + @args = args + @opts = opts end attr_reader :op attr_reader :args attr_reader :opts @@ -295,16 +258,16 @@ table end def optarg_value(spec) case spec - when 'true' then true # [name=true] - when 'false' then false # [name=false] - when 'nil' then nil # [name=nil] - when nil then true # [name] - when /^\d+$/ then $&.to_i # [name=8] - else # [name=val] + when 'true' then true # [name=true] + when 'false' then false # [name=false] + when 'nil' then nil # [name=nil] + when nil then true # [name] + when /^\d+$/ then $&.to_i # [name=8] + else # [name=val] spec end end def init_vars @@ -463,11 +426,11 @@ def _parse_file(f) whole = [] repo = {'file' => whole} curr = {'WHOLE' => whole} lineno = 1 - yacchack = false # remove ';'-only lines. + yacchack = false # remove ';'-only lines. opened = [['(not opened)', '(not opened)']] * 3 f.each do |line| case line when /(?:\A\#@|\#@@)([a-z]+)_(begin|end)\((.*)\)/ @@ -508,10 +471,10 @@ opened.pop when /(?:\A\#@|\#@@)yacchack/ yacchack = true - when /\A\#@-/ # does not increment line number. + when /\A\#@-/ # does not increment line number. line = canonical($') curr.each_value do |list| list.push Line.new(nil, line) end